]> git.donarmstrong.com Git - neurodebian.git/blob - vm/tools/nd_createappliance
trying to find matching preseeding for keyboard + ship initial_setup from wheezy...
[neurodebian.git] / vm / tools / nd_createappliance
1 #!/bin/bash
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:
4
5 set -eu
6
7 # TODO: arguments later on to become cmdline args
8 #iso=debian-squeeze-di-beta1-amd64-businesscard.iso
9 #iso=debian-6.0.3-${ARCH:=amd64}-businesscard.iso
10 iso=debian-wheezy-DI-a1-${ARCH:=amd64}-businesscard.iso
11 di_cd=$(readlink -f $PWD/../../../neurodebian-images/$iso)
12 di_host=head1.hydra.dartmouth.edu               # where to look for di preseed
13
14 build_dir=$PWD/build
15 dist_dir=$PWD/dist
16 vendor="NeuroDebian"
17 vm_version="6.999.20120716"
18 vm_ostype=Debian
19 vendor_url="http://neuro.debian.net"
20 product_url="${vendor_url}/vm.html"
21
22 # Generic definitions
23 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.
24
25 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."
26
27
28 # Computed settings
29 #vm_basepath=
30
31 # By default 32bit unless installer image has amd64
32 # TODO: might need to make more robust?
33 vm_arch=i386
34 vm_arch_name=" (32bit)"
35 if file $di_cd | grep -q ' amd64 '; then
36     vm_arch=amd64
37     vm_ostype+="_64"
38     vm_arch_name=" (64bit)"
39 fi
40
41 vm_fprefix="${vendor}_${vm_version}_${vm_arch}" # common prefix for files
42 #vm_disk="$build_dir/nd-${vm_version}_${vm_arch}.vdi"
43 vm_disk="$build_dir/${vm_fprefix}.vdi"
44 vm_name="${vendor} ${vm_version} ${vm_arch_name}"
45 # Let's use OVA since 4.x
46 # vm_ovf="${dist_dir}/${vm_fprefix}.ovf"
47 vm_ova="${dist_dir}/${vm_fprefix}.ova"
48 product_name="${vendor} VirtualMachine (${vm_arch})"
49
50 _info() {
51     echo "I: $*"
52 }
53
54 clean_buildvm() {
55 # TODO: remove whenever done
56 VBoxManage storagectl "${vm_name}" \
57     --name "SATA Controller" --remove || :
58 VBoxManage storagectl "${vm_name}" \
59     --name "IDE Controller" --remove || :
60
61 VBoxManage closemedium disk "${vm_disk}" || :
62 VBoxManage unregistervm "${vm_name}" --delete || :
63 rm -f ${vm_disk}
64 }
65
66 clean_buildvm                   # clean things up
67
68 #exit
69 # Check that no previous VM was left (can happen if previous failures
70 # were "valid")
71 if VBoxManage list vms | grep -q "^\"${vm_name}\".*"; then
72     echo "VM $vm_name still exists -- something is wrong, Can't continue" >&2
73     exit 1
74 fi
75
76 _info Assure build directory
77 mkdir -p $build_dir
78
79 _info Create HardDisk for the VM
80 VBoxManage createhd --filename $vm_disk \
81     --size 40960 --format VDI
82   # documented but not implemented:
83   #  --comment "Drive for NeuroDebian VM installer"
84
85 _info Create VM
86 VBoxManage createvm --name "${vm_name}" --register \
87     --ostype "${vm_ostype}" --basefolder $build_dir
88
89 _info Tune VM
90 VBoxManage modifyvm "${vm_name}" \
91     --audio alsa \
92     --audiocontroller  ac97 \
93     --boot1 disk \
94     --boot2 dvd \
95     --cpus 1 \
96     --ioapic  on \
97     --memory 1048 \
98     --mouse usbtablet \
99     --nic1 nat \
100     --rtcuseutc on \
101     --usb on \
102     --vram 32
103
104 # Add HD controllers
105 VBoxManage storagectl "${vm_name}" \
106     --name "IDE Controller" \
107     --add ide \
108     --controller "PIIX4"
109 VBoxManage storageattach "${vm_name}" \
110     --storagectl "IDE Controller" \
111     --port 0 \
112     --device 0 \
113     --type dvddrive \
114     --medium  $di_cd
115
116 VBoxManage storagectl "${vm_name}" \
117     --name "SATA Controller" \
118     --add sata \
119     --controller "IntelAHCI"
120
121 VBoxManage storageattach  "${vm_name}" \
122     --storagectl "SATA Controller" \
123     --port 0 \
124     --device 0 \
125     --type hdd \
126     --medium "${vm_disk}"
127
128 VBoxManage showvminfo  "${vm_name}"
129
130 _info "Run Debian Installer"
131 # When boot menu appears you will have to
132 # press Esc
133 # type  auto url=$di_host
134 # press Enter"
135
136 VBoxManage startvm "${vm_name}"
137
138 sleep 5                         # give some time to make sure we get to menu
139 # Send our sequence -- cruel way
140 #VBoxManage controlvm "${vm_name}" keyboardputscancode \
141 #    01 81 \
142 #    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 \
143 #    1c 9c # ESCAPE, auto url=hydra, ENTER
144 echo "typeGuest \"${vm_name}\" \"&ESC;Wauto url=${di_host}&ENTER;\"" | /usr/lib/virtualbox/vboxshell.py
145
146 : "
147 oops -- asked either I want to store Partitioning on the disk...
148
149 didn't happen before
150 "
151
152 # wait for it to finish! -- found no cleaner way :-/
153 sleep 10
154 while VBoxManage showvminfo "${vm_name}" | grep -q running; do
155     sleep 5
156 done
157
158 _info Compacting VDI
159 sudo ./nd_compactvdi "${vm_disk}"
160
161 _info Exporting the appliance
162 if [ -e "$vm_ova" ]; then
163     vm_ova_old=$vm_ova.`date +"20%y%m%d%H%M"`
164     _info Previous OVA image exists, renaming it to $vm_ova_old
165     mv "$vm_ova" "$vm_ova_old"
166 fi
167 VBoxManage export "${vm_name}" -o "$vm_ova" \
168         --vsys 0 \
169         --product "${product_name}" \
170         --producturl "${product_url}" \
171         --vendor "${vendor}" \
172         --vendorurl "http://neuro.debian.net" \
173         --version "$vm_version" \
174         --eula "$eula"
175
176 _info Cleaning after ourselves
177 clean_buildvm
178
179 _info Testing import of the appliance
180 VBoxManage import "$vm_ova" --vsys 0 --eula accept
181
182 _info Starting imported machine
183 VBoxManage startvm "${vm_name}"