2012-07-09 19:12:57 +02:00
|
|
|
#!/bin/bash
|
|
|
|
RECORDVM_DATA=/var/makedist/recordvm
|
|
|
|
#VBOX=1
|
|
|
|
VBOX_VMNAME="openmamba-recordvm"
|
|
|
|
VBOX_DISPLAY=:1
|
|
|
|
EXECUTION_TIME=200
|
|
|
|
VIDEO_EXT=.flv
|
|
|
|
VIDEO_EXT2=.ogv
|
|
|
|
|
2012-07-22 17:21:25 +02:00
|
|
|
function usage() {
|
2012-07-09 19:12:57 +02:00
|
|
|
echo "Usage:"
|
2012-07-22 17:21:25 +02:00
|
|
|
echo "recordvm.sh iso_path [--recreate-images] [-h]"
|
2012-07-09 19:12:57 +02:00
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2012-07-22 17:21:25 +02:00
|
|
|
opts=($@)
|
|
|
|
|
|
|
|
while test -n "$1" ; do
|
|
|
|
case $1 in
|
|
|
|
"--recreate-images") RECREATE_IMAGES=1;;
|
|
|
|
"-h") usage; exit 0 ;;
|
|
|
|
*) if [ -z "$ISO_PATH" ]; then
|
|
|
|
ISO_PATH=$1
|
|
|
|
else
|
|
|
|
echo "Error: extra argument $1 specified; aborting."
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
[ "$ISO_PATH" ] || {
|
|
|
|
echo "Error: ISO path was not specified; aborting."
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2012-07-09 19:12:57 +02:00
|
|
|
ISO_DIR=`dirname $ISO_PATH`
|
|
|
|
ISO_NAME=`basename $ISO_PATH`
|
2013-01-27 16:11:56 +01:00
|
|
|
ISO_ARCH=`echo $ISO_NAME | sed "s|.*\.\([A-Za-z0-9_]*\)\.iso|\1|"`
|
2012-07-09 19:12:57 +02:00
|
|
|
|
|
|
|
[ -e $ISO_PATH ] || {
|
|
|
|
echo "Error: file $ISO_PATH does not exist; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2012-11-29 12:24:13 +01:00
|
|
|
if [ -e $ISO_DIR/latest-is-milestone*.txt ]; then
|
|
|
|
ISO_VERSION=`ls $ISO_DIR/latest-is-milestone[0-9]*-*.txt 2>/dev/null| sed "s/.*latest-is-milestone[0-9]*-\(.*\)\.txt/\1/"`
|
|
|
|
elif [ -e $ISO_DIR/latest-is-*.txt ]; then
|
|
|
|
ISO_VERSION=`ls $ISO_DIR/latest-is-*.txt 2>/dev/null| sed "s/.*latest-is-\(.*\)\.txt/\1/"`
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ "$ISO_VERSION" ] || {
|
|
|
|
echo "makedist-recordvm: ERROR: unable to find latest version file in $ISO_DIR; running in view mode only."
|
|
|
|
VIEWMODE=1
|
|
|
|
}
|
|
|
|
|
2012-07-22 17:21:25 +02:00
|
|
|
if [ ! "$RECREATE_IMAGES" ]; then
|
|
|
|
echo "Preparing ISO image $ISO_PATH"
|
|
|
|
ln -sf $ISO_PATH $RECORDVM_DATA/recordvm.iso
|
|
|
|
echo "Starting virtual machine for $ISO_PATH"
|
|
|
|
export HOME=$RECORDVM_DATA
|
|
|
|
xinit -- $VBOX_DISPLAY &
|
|
|
|
|
|
|
|
if [ "$VBOX" ]; then
|
|
|
|
trap "VBoxManage controlvm $VBOX_VMNAME poweroff" INT QUIT TSTP
|
|
|
|
|
|
|
|
sleepcnt=0
|
|
|
|
while true; do
|
|
|
|
if [ "`VBoxManage list runningvms | grep $VBOX_VMNAME`" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
if [ $sleepcnt -gt 20 ]; then
|
|
|
|
echo "VirtualBox did not start; aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
let sleepcnt=sleepcnt+1
|
|
|
|
done
|
|
|
|
WINID=`xwininfo -display $VBOX_DISPLAY -name "$VBOX_VMNAME - Oracle VM VirtualBox" 2>/dev/null |grep "Window id:"| sed "s|.*Window id: \([0-9a-fx]*\).*|\1|"`
|
|
|
|
VBoxManage controlvm $VBOX_VMNAME reset
|
|
|
|
else
|
|
|
|
sleepcnt=0
|
|
|
|
while true; do
|
|
|
|
WINID=`xwininfo -display $VBOX_DISPLAY -name "QEMU (qemu-recordvm)" 2>/dev/null |grep "Window id:"| sed "s|.*Window id: \([0-9a-fx]*\).*|\1|"`
|
|
|
|
[ "$WINID" ] && break
|
|
|
|
if [ $sleepcnt -gt 20 ]; then
|
|
|
|
echo "qemu did not start; aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
let sleepcnt=sleepcnt+1
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
fi
|
2012-07-09 19:12:57 +02:00
|
|
|
|
2012-07-22 17:21:25 +02:00
|
|
|
echo "Windowid is: $WINID"
|
2012-07-09 19:12:57 +02:00
|
|
|
|
2012-11-29 12:24:13 +01:00
|
|
|
if [ ! "$VIEWMODE" ]; then
|
|
|
|
echo "Capturing window output"
|
|
|
|
mkdir -p $ISO_DIR/preview/
|
|
|
|
DBUS_SESSION_BUS_ADDRESS= HOME=$RECORDVM_DATA DISPLAY=$VBOX_DISPLAY xvidcap \
|
|
|
|
--cap_geometry 1024x768+0+0 \
|
|
|
|
--verbose 2 --gui no --audio no \
|
|
|
|
--time $EXECUTION_TIME --file $ISO_DIR/preview/${ISO_NAME}${VIDEO_EXT} \
|
|
|
|
--quality 100 >>$RECORDVM_DATA/recordvm.log
|
|
|
|
else
|
|
|
|
sleep $EXECUTION_TIME
|
|
|
|
fi
|
2012-07-09 19:12:57 +02:00
|
|
|
|
2012-07-22 17:21:25 +02:00
|
|
|
echo "Powering off VM"
|
|
|
|
if [ "$VBOX" ]; then
|
|
|
|
VBoxManage controlvm $VBOX_VMNAME poweroff &
|
2012-07-09 19:12:57 +02:00
|
|
|
|
2012-07-22 17:21:25 +02:00
|
|
|
count=0
|
|
|
|
while [ "`pidof VBoxManage`" ]; do
|
|
|
|
let count=count+1
|
|
|
|
sleep 1
|
|
|
|
if [ $count -gt 60 ]; then
|
|
|
|
killall -9 VBoxManage
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
xkill -id $WINID -display $VBOX_DISPLAY
|
2012-07-09 19:12:57 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2012-11-29 12:24:13 +01:00
|
|
|
if [ ! "$VIEWMODE" ]; then
|
|
|
|
echo "Creating preview images"
|
2013-01-27 16:11:56 +01:00
|
|
|
rm -f $ISO_DIR/preview/image-${ISO_ARCH}-*.jpg
|
|
|
|
ffmpeg -y -i $ISO_DIR/preview/$ISO_NAME${VIDEO_EXT} -r 0.1 -f image2 $ISO_DIR/preview/image-${ISO_ARCH}-%02d.jpg >/dev/null
|
2012-11-29 12:24:13 +01:00
|
|
|
for i in `seq 22 -1 1`; do
|
|
|
|
f=`printf %02d $i`
|
2013-01-27 16:11:56 +01:00
|
|
|
convert -resize 50x40 $ISO_DIR/preview/image-${ISO_ARCH}-$f.jpg $ISO_DIR/preview/image-${ISO_ARCH}-$f-50x40.jpg
|
|
|
|
done
|
|
|
|
for i in `seq 22 -1 1`; do
|
|
|
|
f=`printf %02d $i`
|
|
|
|
[ -e $ISO_DIR/preview/image-${ISO_ARCH}-$f.jpg ] && {
|
|
|
|
convert -resize 320x200 $ISO_DIR/preview/image-${ISO_ARCH}-$f.jpg $ISO_DIR/preview/preview-${ISO_ARCH}-$ISO_VERSION.jpg
|
|
|
|
ln -sf preview-${ISO_ARCH}-$ISO_VERSION.jpg $ISO_DIR/preview/preview-${ISO_ARCH}.jpg
|
|
|
|
convert -resize 400x300 $ISO_DIR/preview/image-${ISO_ARCH}-$f.jpg $ISO_DIR/preview/preview-${ISO_ARCH}-$ISO_VERSION-400x300.jpg
|
|
|
|
ln -sf preview-${ISO_ARCH}-$ISO_VERSION-400x300.jpg $ISO_DIR/preview/preview-${ISO_ARCH}-400x300.jpg
|
2012-11-29 12:24:13 +01:00
|
|
|
break
|
|
|
|
}
|
|
|
|
done
|
2012-07-09 19:12:57 +02:00
|
|
|
|
2012-11-29 12:24:13 +01:00
|
|
|
if [ ! "$RECREATE_IMAGES" ]; then
|
|
|
|
echo "Creating ${VIDEO_EXT2} video from ${VIDEO_EXT}"
|
|
|
|
ffmpeg2theora -y -i $ISO_DIR/preview/$ISO_NAME${VIDEO_EXT} $ISO_DIR/preview/$ISO_NAME${VIDEO_EXT2} >/dev/null
|
2012-07-09 19:12:57 +02:00
|
|
|
|
2012-11-29 12:27:01 +01:00
|
|
|
# cleanup old files
|
2013-01-27 16:11:56 +01:00
|
|
|
for f in `ls $ISO_DIR/preview/*.${ISO_ARCH}.*${VIDEO_EXT}`; do
|
2012-11-29 12:24:13 +01:00
|
|
|
[ "$f" = "$ISO_DIR/preview/$ISO_NAME${VIDEO_EXT}" ] || rm -f $f
|
|
|
|
done
|
2013-01-27 16:11:56 +01:00
|
|
|
for f in `ls $ISO_DIR/preview/*.${ISO_ARCH}.*${VIDEO_EXT2}`; do
|
2012-11-29 12:24:13 +01:00
|
|
|
[ "$f" = "$ISO_DIR/preview/$ISO_NAME${VIDEO_EXT2}" ] || rm -f $f
|
|
|
|
done
|
|
|
|
fi
|
2012-07-22 17:21:25 +02:00
|
|
|
fi
|
2012-07-09 19:12:57 +02:00
|
|
|
|
|
|
|
echo "Done."
|
|
|
|
exit 0
|