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