| 1 | #!/usr/bin/env bash
|
|---|
| 2 | set -o errexit -o nounset -o pipefail
|
|---|
| 3 | #set -o xtrace
|
|---|
| 4 |
|
|---|
| 5 | start() {
|
|---|
| 6 | local vm=unattended-templates-dir-bug
|
|---|
| 7 | local ostype=Debian_64
|
|---|
| 8 | local os_iso_url=https://cdimage.debian.org/cdimage/release/9.7.0/amd64/iso-cd/debian-9.7.0-amd64-netinst.iso
|
|---|
| 9 |
|
|---|
| 10 | local os_iso=~/tmp/isos/$(basename $os_iso_url)
|
|---|
| 11 | local base_dir=~/tmp/$USER-vms
|
|---|
| 12 |
|
|---|
| 13 | mkdir -p $(dirname $os_iso)
|
|---|
| 14 |
|
|---|
| 15 | if ! test -e $os_iso; then
|
|---|
| 16 | curl --fail --location --create-dirs --output $os_iso-$$ $os_iso_url
|
|---|
| 17 | mv $os_iso-$$ $os_iso # this only happens if previous cmds succeeds (because of errexit)
|
|---|
| 18 | fi
|
|---|
| 19 |
|
|---|
| 20 | # remove any failed previous attempt
|
|---|
| 21 | VBoxManage controlvm $vm poweroff > /dev/null 2>&1 || true
|
|---|
| 22 | VBoxManage unregistervm $vm --delete > /dev/null 2>&1 || true
|
|---|
| 23 |
|
|---|
| 24 | rm -fr $base_dir/$vm
|
|---|
| 25 | mkdir -p $base_dir/$vm
|
|---|
| 26 |
|
|---|
| 27 | VBoxManage createvm \
|
|---|
| 28 | --name $vm \
|
|---|
| 29 | --basefolder $base_dir \
|
|---|
| 30 | --ostype $ostype \
|
|---|
| 31 | --register \
|
|---|
| 32 |
|
|---|
| 33 | VBoxManage modifyvm $vm \
|
|---|
| 34 | --memory 1024 \
|
|---|
| 35 | --vram 16 \
|
|---|
| 36 |
|
|---|
| 37 | VBoxManage storagectl $vm \
|
|---|
| 38 | --name SAS \
|
|---|
| 39 | --add sas \
|
|---|
| 40 | --portcount 1 \
|
|---|
| 41 | --bootable on \
|
|---|
| 42 |
|
|---|
| 43 | VBoxManage createmedium disk \
|
|---|
| 44 | --filename $base_dir/$vm/$vm.vdi \
|
|---|
| 45 | --size 8192 \
|
|---|
| 46 | --format VDI \
|
|---|
| 47 |
|
|---|
| 48 | # SAS-0-0
|
|---|
| 49 | VBoxManage storageattach $vm \
|
|---|
| 50 | --medium $base_dir/$vm/$vm.vdi \
|
|---|
| 51 | --storagectl SAS \
|
|---|
| 52 | --port 0 \
|
|---|
| 53 | --device 0 \
|
|---|
| 54 | --type hdd \
|
|---|
| 55 |
|
|---|
| 56 | VBoxManage storagectl $vm \
|
|---|
| 57 | --name SATA \
|
|---|
| 58 | --add sata \
|
|---|
| 59 | --portcount 1 \
|
|---|
| 60 | --bootable on \
|
|---|
| 61 |
|
|---|
| 62 | # SATA-0-0
|
|---|
| 63 | VBoxManage storageattach $vm \
|
|---|
| 64 | --medium emptydrive \
|
|---|
| 65 | --storagectl SATA \
|
|---|
| 66 | --port 0 \
|
|---|
| 67 | --device 0 \
|
|---|
| 68 | --type dvddrive \
|
|---|
| 69 | --mtype readonly \
|
|---|
| 70 |
|
|---|
| 71 | if test ${fix:-0} -ne 0; then
|
|---|
| 72 | local script_template=/usr/lib/virtualbox/UnattendedTemplates/debian_preseed.cfg
|
|---|
| 73 | local post_install_template=/usr/lib/virtualbox/UnattendedTemplates/debian_postinstall.sh
|
|---|
| 74 |
|
|---|
| 75 | VBoxManage unattended install $vm \
|
|---|
| 76 | --iso $os_iso \
|
|---|
| 77 | --script-template $script_template \
|
|---|
| 78 | --post-install-template $post_install_template
|
|---|
| 79 | else
|
|---|
| 80 | VBoxManage unattended install $vm \
|
|---|
| 81 | --iso $os_iso
|
|---|
| 82 | fi
|
|---|
| 83 |
|
|---|
| 84 | VBoxManage startvm $vm --type headless
|
|---|
| 85 | }
|
|---|
| 86 | start
|
|---|