]> git.donarmstrong.com Git - neurodebian.git/blob - vm/tools/nd_createappliance
changelog + nd-vmsetupwizard: Preparing 0.29 release of neurodebian for updated nd...
[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 sleep 5                         # give some time to make sure we get to menu
138 # Send our sequence -- cruel way
139 #VBoxManage controlvm "${vm_name}" keyboardputscancode \
140 #    01 81 \
141 #    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 \
142 #    1c 9c # ESCAPE, auto url=hydra, ENTER
143 echo "typeGuest \"${vm_name}\" \"&ESC;Wauto url=${di_host}&ENTER;\"" | /usr/lib/virtualbox/vboxshell.py
144
145 : "
146 oops -- asked either I want to store Partitioning on the disk...
147
148 didn't happen before
149 "
150
151 # wait for it to finish! -- found no cleaner way :-/
152 sleep 10
153 while VBoxManage showvminfo "${vm_name}" | grep -q running; do
154     sleep 5
155 done
156
157 _info Compacting VDI
158 sudo ./nd_compactvdi "${vm_disk}"
159
160 _info Exporting the appliance
161 if [ -e "$vm_ova" ]; then
162     vm_ova_old=$vm_ova.`date +"20%y%m%d%H%M"`
163     _info Previous OVA image exists, renaming it to $vm_ova_old
164     mv "$vm_ova" "$vm_ova_old"
165 fi
166 VBoxManage export "${vm_name}" -o "$vm_ova" \
167         --vsys 0 \
168         --product "${product_name}" \
169         --producturl "${product_url}" \
170         --vendor "${vendor}" \
171         --vendorurl "http://neuro.debian.net" \
172         --version "$vm_version" \
173         --eula "$eula"
174
175 _info Cleaning after ourselves
176 clean_buildvm
177
178 _info Testing import of the appliance
179 VBoxManage import "$vm_ova" --vsys 0 --eula accept
180
181 _info Starting imported machine
182 VBoxManage startvm "${vm_name}"