2 #emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
3 #ex: set sts=4 ts=4 sw=4 noet:
10 echo "Usage: $0 [-p PRESEED -i ISO -m MIRROR -t TZ]
12 Create ND VirtualBox appliance.
15 -p PRESEED path to preesed file for d-i
16 -i ISO path to debian installation iso file
17 -m MIRROR debian mirror to use for installation
18 -t TZ time zone of virtual machine
19 -h Show this help and exit
23 while getopts "p:" OPTION
32 # TODO: arguments later on to become cmdline args
33 #iso=debian-squeeze-di-beta1-amd64-businesscard.iso
34 #iso=debian-6.0.3-${ARCH:=amd64}-businesscard.iso
35 #iso=debian-wheezy-DI-a1-${ARCH:=amd64}-businesscard.iso
37 di_cd=/backup/isos/debian-wheezy-DI-b1-amd64-netinst.iso
38 # look here for more details about the default IP of the host:
39 # # http://www.virtualbox.org/manual/ch09.html#changenat
40 di_host=10.0.2.2 # where to look for di preseed
42 di_preseed=/home/tiziano/git/neurodebian/vm/d-i/wheezy/preseed.cfg
48 vm_version="6.999.20120827"
50 vendor_url="http://neuro.debian.net"
51 product_url="${vendor_url}/vm.html"
54 eula="This virtual appliance contains Free and Open Source Software (FOSS) released under licenses compliant with the Debian Free Software Guidelines (DFSG, see http://www.debian.org/social_contract), such as, GPL, BSD, MIT, etc. Such software is free to be used or customized for any purpose.
56 However, by default this virtual machine is also enabled to install additional software from Debian and NeuroDebian repositories that is distributed under more restrictive licenses (e.g. closed-source, non-commercial, research-only). It is the user's responsibility to adhere to the terms and conditions of any particular software that is installed and used in this virtual machine. Copyright and license details for any installed PACKAGE are available in /usr/share/doc/PACKAGE/copyright inside the virtual machine."
62 # By default 32bit unless installer image has amd64
63 # TODO: might need to make more robust?
65 vm_arch_name=" (32bit)"
66 if file $di_cd | grep -q ' amd64 '; then
69 vm_arch_name=" (64bit)"
72 vm_fprefix="${vendor}_${vm_version}_${vm_arch}" # common prefix for files
73 #vm_disk="$build_dir/nd-${vm_version}_${vm_arch}.vdi"
74 vm_disk="$build_dir/${vm_fprefix}.vdi"
75 vm_name="${vendor} ${vm_version} ${vm_arch_name}"
76 # Let's use OVA since 4.x
77 # vm_ovf="${dist_dir}/${vm_fprefix}.ovf"
78 vm_ova="${dist_dir}/${vm_fprefix}.ova"
79 product_name="${vendor} VirtualMachine (${vm_arch})"
86 # TODO: remove whenever done
87 VBoxManage storagectl "${vm_name}" \
88 --name "SATA Controller" --remove || :
89 VBoxManage storagectl "${vm_name}" \
90 --name "IDE Controller" --remove || :
92 VBoxManage closemedium disk "${vm_disk}" || :
93 VBoxManage unregistervm "${vm_name}" --delete || :
97 clean_buildvm >&/dev/null # clean things up
100 # Check that no previous VM was left (can happen if previous failures
102 if VBoxManage list vms | grep -q "^\"${vm_name}\".*"; then
103 echo "VM $vm_name still exists -- something is wrong, Can't continue" >&2
107 _info Assure build directory
110 _info Create HardDisk for the VM
111 VBoxManage createhd --filename $vm_disk \
112 --size 40960 --format VDI
113 # documented but not implemented:
114 # --comment "Drive for NeuroDebian VM installer"
117 VBoxManage createvm --name "${vm_name}" --register \
118 --ostype "${vm_ostype}" --basefolder $build_dir
121 VBoxManage modifyvm "${vm_name}" \
123 --audiocontroller ac97 \
136 VBoxManage storagectl "${vm_name}" \
137 --name "IDE Controller" \
140 VBoxManage storageattach "${vm_name}" \
141 --storagectl "IDE Controller" \
147 VBoxManage storagectl "${vm_name}" \
148 --name "SATA Controller" \
150 --controller "IntelAHCI"
152 VBoxManage storageattach "${vm_name}" \
153 --storagectl "SATA Controller" \
157 --medium "${vm_disk}"
159 VBoxManage showvminfo "${vm_name}"
161 _info "Run Debian Installer"
162 # When boot menu appears you will have to
164 # type auto url=$di_host
167 # start local web server to serve preseed file
168 cd $(dirname ${di_preseed}) && python -m SimpleHTTPServer ${di_port} >&/dev/null &
170 VBoxManage startvm "${vm_name}"
172 sleep 5 # give some time to make sure we get to menu
173 # Send our sequence -- cruel way
174 #VBoxManage controlvm "${vm_name}" keyboardputscancode \
176 # 1e 9e 16 96 14 94 18 98 39 b9 16 96 13 93 26 a6 0d 8d 23 a3 15 95 20 a0 13 93 1e 9e \
177 # 1c 9c # ESCAPE, auto url=hydra, ENTER
178 echo "typeGuest \"${vm_name}\" \"&ESC;Wauto url=${di_host}|;${di_port}/$(basename ${di_preseed})&ENTER;\"" | /usr/lib/virtualbox/vboxshell.py
180 # wait for it to finish! -- found no cleaner way :-/
182 while VBoxManage showvminfo "${vm_name}" | grep -q running; do
186 # kill the web server
187 #kill ${webserver_pid}
190 sudo ./nd_compactvdi "${vm_disk}"
192 _info Exporting the appliance
193 if [ -e "$vm_ova" ]; then
194 vm_ova_old=$vm_ova.`date +"20%y%m%d%H%M"`
195 _info Previous OVA image exists, renaming it to $vm_ova_old
196 mv "$vm_ova" "$vm_ova_old"
198 VBoxManage export "${vm_name}" -o "$vm_ova" \
200 --product "${product_name}" \
201 --producturl "${product_url}" \
202 --vendor "${vendor}" \
203 --vendorurl "http://neuro.debian.net" \
204 --version "$vm_version" \
207 _info Cleaning after ourselves
210 _info Testing import of the appliance
211 VBoxManage import "$vm_ova" --vsys 0 --eula accept
213 _info Starting imported machine
214 VBoxManage startvm "${vm_name}"