summaryrefslogtreecommitdiffstats
path: root/bin/cd_tester.sh
blob: af473d1ea4ec2f9b0e698f6f1e6a2946a1ae22ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash

# Copyright 2012 Holger Levsen <holger@layer-acht.org>
# released under the GPLv=2

# $1 = vnc-display
# $2 = name
# $3 = wget url/jigdo url

if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ] ; then
	echo "need three params"
	echo '# $1 = vnc-display'
	echo '# $2 = name'
	echo '# $3 = wget url/jigdo url'
	exit 1
fi

#
# default settings
#
set -x
set -e
export LC_ALL=C
export MIRROR=http://ftp.de.debian.org/debian
export http_proxy="http://localhost:3128"

#
# init
#
DISPLAY=$1
NAME=$2
URL=$3
if [ "$(basename $URL)" != "amd64" ] ; then
	IMAGE=$(pwd)/$(basename $URL)
	IMAGE_MNT="/media/cd-$NAME.iso"
else
	KERNEL=linux
	INITRD=initrd.gz
fi

#
# define workspace + results
#
rm -rf results
mkdir -p results
WORKSPACE=$(pwd)
RESULTS=$WORKSPACE/results

cleanup_all() {
	set -x
	cd $RESULTS
	#
	# create video
	#
	ffmpeg2theora --videobitrate 700 --no-upscaling snapshot_%06d.ppm --framerate 12 --max_size 800x600 -o cd-test-$NAME.ogv
	set +x
	rm snapshot_??????.ppm
	set -x
	#
	# kill qemu and image
	#
	sudo kill -9 $(ps fax | grep -v grep | grep -v sudo | grep qemu-system | grep ${NAME}-preseed.cfg 2>/dev/null | cut -d " " -f1)
	sleep 0.3s
	rm $WORKSPACE/$NAME.qcow
	#
	# cleanup
	#
	sudo umount $IMAGE_MNT
}

bootstrap() {
	cd $WORKSPACE
	echo "Doing cd tests for $NAME now."
	qemu-img create -f qcow $NAME.qcow 20g
	case $NAME in
		debian-edu-wheezy)
				echo "fire up qemu now..."
				sudo qemu-system-x86_64 -cdrom $IMAGE -hda $NAME.qcow -boot d -m 1024 -display vnc=localhost:$DISPLAY --kernel $IMAGE_MNT/install.amd/vmlinuz --append "auto=true priority=critical locale=en_US keymap=us url=http://10.0.2.2/userContent/${NAME}-preseed.cfg video=vesa:ywrap,mtrr vga=788 initrd=/install.amd/gtk/initrd.gz -- quiet" --initrd $IMAGE_MNT/install.amd/gtk/initrd.gz &
				;;
		lxde-wheezy)
				echo "fire up qemu now..."
				sudo qemu-system-x86_64 -hda $NAME.qcow -boot c -m 1024 -display vnc=localhost:$DISPLAY --kernel $KERNEL --append "auto=true priority=critical desktop=lxde locale=en_US keymap=us url=http://10.0.2.2/userContent/${NAME}-preseed.cfg video=vesa:ywrap,mtrr vga=788 --" --initrd $INITRD &
				# wheezy: qemu-system-x86_64 -cdrom debian-6.0.6-amd64-businesscard.iso -hda debian.qcow -boot d -m 2048 -display vnc=localhost:1 --kernel /mnt/install.amd/vmlinuz --append "auto=true priority=critical url=http://10.0.2.2/userContent/preseed.cfg vga=788 initrd=/install.amd/initrd.gz" --initrd /mnt/install.amd/initrd.gz
				# kernel /install.amd/vmlinuz
				# append desktop=lxde video=vesa:ywrap,mtrr vga=788 initrd=/install.amd/gtk/initrd.gz -- quiet
				;;
		*)		echo "unsupported distro."
				exit 1
				;;
	esac
}

monitor_installation() {
	cd $RESULTS
	sleep 4
	echo "Taking screenshots every 2secs now, until the installation is finished or 5h have passed"
	NR=0
	while [ $NR -lt 9000 ] ; do
		set +x
		#
		# break if qemu-system has finished
		#
		if [ $(ps fax | grep -v grep | grep qemu-system | grep ${NAME}-preseed.cfg 2>/dev/null | wc -l) -eq 0 ] ; then
			break
		fi
		vncsnapshot -quiet -allowblank localhost:$DISPLAY snapshot_$(printf "%06d" $NR).jpg 2>/dev/null
		convert snapshot_$(printf "%06d" $NR).jpg snapshot_$(printf "%06d" $NR).ppm 
		rm snapshot_$(printf "%06d" $NR).jpg 
		let NR=NR+1
		sleep 2
		# give signal we are still running
		if [ $(($NR % 15)) -eq 0 ] ; then
			date
		fi
		# press ctrl-key to avoid screensaver kicking in
		if [ $(($NR % 150)) -eq 0 ] ; then
			vncdo -s localhost:$DISPLAY key ctrl
		fi
	done
	set -x
	if [ $NR -eq 9000 ] ; then
		echo Warning: running for 5h, forceing termination.
	fi
}

trap cleanup_all INT TERM EXIT

#
# if there is a CD image...
#
if [ ! -z $IMAGE ] ; then
	# only download if $IMAGE is older than a week (60*24*7=10080) (+9500 is a bit less than a week)
	if test $(find $IMAGE -mmin +9500) || ! test -f $IMAGE ; then
		curl $URL > $IMAGE
	fi
	sudo mkdir -p $IMAGE_MNT
	sudo mount -o loop,ro $IMAGE $IMAGE_MNT
else
	#
	# else netboot gtk
	#
	# only download if $KERNEL is older than a week...
	if test $(find $KERNEL -mmin +9500) || ! test -f $KERNEL ; then
		curl $URL/$KERNEL > $KERNEL
		curl $URL/$INITRD > $INITRD
	fi

fi
bootstrap 
monitor_installation

cleanup_all
trap - INT TERM EXIT