]> git.donarmstrong.com Git - neurodebian.git/blob - vm/tools/nd_createappliance
2c794cb79afd0eaea2fa71c8c7f84c1003eb19d6
[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.0-${ARCH:=amd64}-businesscard.iso
10 di_cd=$(readlink -f $PWD/../../../neurodebian-images/$iso)
11 di_host=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.2"
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 vm_ovf="${dist_dir}/${vm_fprefix}.ovf"
45 product_name="${vendor} VirtualMachine (${vm_arch})"
46
47 _info() {
48     echo "I: $*"
49 }
50
51 clean_buildvm() {
52 # TODO: remove whenever done
53 VBoxManage storagectl "${vm_name}" \
54     --name "SATA Controller" --remove || :
55 VBoxManage storagectl "${vm_name}" \
56     --name "IDE Controller" --remove || :
57
58 VBoxManage closemedium disk "${vm_disk}" || :
59 VBoxManage unregistervm "${vm_name}" --delete || :
60 rm -f ${vm_disk}
61 }
62
63 clean_buildvm                   # clean things up
64
65 #exit
66 # Check that no previous VM was left (can happen if previous failures
67 # were "valid")
68 if VBoxManage list vms | grep -q "^\"${vm_name}\".*"; then
69     echo "VM $vm_name still exists -- something is wrong, Can't continue" >&2
70     exit 1
71 fi
72
73 _info Assure build directory
74 mkdir -p $build_dir
75
76 _info Create HardDisk for the VM
77 VBoxManage createhd --filename $vm_disk \
78     --size 20480 --format VDI
79   # documented but not implemented:
80   #  --comment "Drive for NeuroDebian VM installer"
81
82 _info Create VM
83 VBoxManage createvm --name "${vm_name}" --register \
84     --ostype "${vm_ostype}" --basefolder $build_dir
85
86 _info Tune VM
87 VBoxManage modifyvm "${vm_name}" \
88     --audio alsa \
89     --audiocontroller  ac97 \
90     --boot1 disk \
91     --boot2 dvd \
92     --cpus 1 \
93     --ioapic  on \
94     --memory 1048 \
95     --mouse usbtablet \
96     --nic1 nat \
97     --rtcuseutc on \
98     --usb on \
99     --vram 32
100
101 # Add HD controllers
102 VBoxManage storagectl "${vm_name}" \
103     --name "IDE Controller" \
104     --add ide \
105     --controller "PIIX4"
106 VBoxManage storageattach "${vm_name}" \
107     --storagectl "IDE Controller" \
108     --port 0 \
109     --device 0 \
110     --type dvddrive \
111     --medium  $di_cd
112
113 VBoxManage storagectl "${vm_name}" \
114     --name "SATA Controller" \
115     --add sata \
116     --controller "IntelAHCI"
117
118 VBoxManage storageattach  "${vm_name}" \
119     --storagectl "SATA Controller" \
120     --port 0 \
121     --device 0 \
122     --type hdd \
123     --medium "${vm_disk}"
124
125 VBoxManage showvminfo  "${vm_name}"
126
127 _info "Run Debian Installer"
128 # When boot menu appears you will have to
129 # press Esc
130 # type  auto url=$di_host
131 # press Enter"
132
133 VBoxManage startvm "${vm_name}"
134
135 sleep 5                         # give some time to make sure we get to menu
136 # Send our sequence -- cruel way
137 #VBoxManage controlvm "${vm_name}" keyboardputscancode \
138 #    01 81 \
139 #    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 \
140 #    1c 9c # ESCAPE, auto url=hydra, ENTER
141 echo "typeGuest \"${vm_name}\" \"&ESC;Wauto url=${di_host}&ENTER;\"" | /usr/lib/virtualbox/vboxshell.py
142
143 : "
144 oops -- asked either I want to store Partitioning on the disk...
145
146 didn't happen before
147 "
148
149 # wait for it to finish! -- found no cleaner way :-/
150 sleep 10
151 while VBoxManage showvminfo "${vm_name}" | grep -q running; do
152     sleep 5
153 done
154
155 _info Compacting VDI
156 sudo ./nd_compactvdi "${vm_disk}"
157
158 _info Exporting the appliance
159
160 VBoxManage export "${vm_name}" -o "$vm_ovf" \
161         --vsys 0 \
162         --product "${product_name}" \
163         --producturl "${product_url}" \
164         --vendor "${vendor}" \
165         --vendorurl "http://neuro.debian.net" \
166         --version "$vm_version" \
167         --eula "$eula"
168
169 _info Cleaning after ourselves
170 clean_buildvm
171
172 _info Testing import of the appliance
173 VBoxManage import "$vm_ovf" --vsys 0 --eula accept
174
175 _info Starting imported machine
176 VBoxManage startvm "${vm_name}"