-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-and-run
executable file
·130 lines (96 loc) · 3.67 KB
/
build-and-run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
set -e
source functions.sh
# Read configuration variable file if it is present
[[ -r "./settings.conf" ]] && . ./settings.conf
if [[ ! -f ./iso/netinstall-18.04.2-desktop-amd64.iso ]]; then
shout "Downloading netinstall iso"
pushd ./iso/
wget -O netinstall-18.04.2-desktop-amd64.iso \
http://mirrors.edge.kernel.org/ubuntu/dists/bionic/main/installer-amd64/current/images/netboot/mini.iso
popd
fi
# NOTE: linux-modules-extra version must match kernel version in the netinstall iso
if [[ ! -f ./iso/linux-modules-extra-4.15.0-20-generic_4.15.0-20.21_amd64.deb ]]; then
shout "Downloading linux-modules-extra"
pushd ./iso/
wget http://mirrors.kernel.org/ubuntu/pool/main/l/linux/linux-modules-extra-4.15.0-20-generic_4.15.0-20.21_amd64.deb
popd
fi
UNIQ=`date | sha1sum | cut -c 1-7`
ISO=`find ./iso/netinstall* | head -n1`
VMS_ROOT="${HOME}/VirtualBox VMs"
VM="Ubuntu-`echo ${ISO} | cut -d "-" -f 2-3`-${UNIQ}"
VM_HDD="${VMS_ROOT}/${VM}/${VM}"
VM_HDD_FILE="${VM_HDD}.vdi"
shout "Setting up"
# Some dependency checks
directory_exists "${VMS_ROOT}" "Cannot find VirtualBox VM directory ${VMS_ROOT}"
file_exists "${ISO}" "Cannot find iso ${ISO}"
is_runnable "vboxmanage" "Cannot find/run vboxmanage"
is_runnable "xorriso" "Cannot find/run xorriso"
is_runnable "7z" "Cannot find/run 7z"
is_runnable "sha1sum" "Cannot find/run sha1sum"
# Remove previously built ISOs
rm -f *.iso
# Cleanup if previous job failed / quit early
rm -rf ./tmp
rm -rf ./initramfs
rm -f ./initramfs.fakeroot
mkdir -p ./tmp
mkdir -p ./initramfs
shout "Extracting ${ISO}"
7z x -o"./tmp/" ${ISO}
pushd ./initramfs
zcat ../tmp/initrd.gz | fakeroot -s ../initramfs.fakeroot cpio -i
mkdir -p seed
cp ../custom.cfg ./seed/
if [[ -f ../proxy.cfg ]]; then
cp ../proxy.cfg ./seed/proxy.cfg
else
cp ../proxy.cfg.sample ./seed/proxy.cfg
fi
# Include extra modules non-free modules for network.
ar p ../iso/linux-modules-extra-4.15.0-20-generic_4.15.0-20.21_amd64.deb data.tar.xz | tar xJ
find | fakeroot -i ../initramfs.fakeroot cpio -o -H newc | gzip -c > ../tmp/initrd.gz
popd
shout "Copying configuration"
cp -f ./isolinux.cfg ./tmp/isolinux.cfg
chmod 0755 ./tmp/boot/grub/grub.cfg
cp -f ./grub.cfg ./tmp/boot/grub/grub.cfg
shout "Building custom iso"
xorriso -as mkisofs \
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
-b isolinux.bin \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-eltorito-alt-boot \
-e boot/grub/efi.img \
-no-emul-boot \
-isohybrid-gpt-basdat \
-o ./${VM}-unattended.iso \
./tmp
shout "Cleanup"
shout "Booting VM to start install"
VBoxManage -v &> /dev/null || { echo "ERROR: VBoxManage not in path!"; exit 1; }
VBoxManage createvm --name "${VM}" --register
VBoxManage modifyvm "${VM}" --ostype Ubuntu_64 --memory 8192 --vram 64 --rtcuseutc on --ioapic on \
--clipboard bidirectional --cpus 2 --firmware efi64
# ISO image to boot
VBoxManage storagectl "${VM}" --name ide0 --add ide
VBoxManage storageattach "${VM}" --storagectl ide0 --device 0 --port 0 --type dvddrive --medium ./${VM}-unattended.iso
# Storage to be used as primary disk
VBoxManage storagectl "${VM}" --name nvme0 --add pcie --controller NVMe --portcount 1
VBoxManage createhd --filename "${VM_HDD_FILE}" --size 40960
VBoxManage storageattach "${VM}" --storagectl nvme0 --port 0 --type hdd --medium "${VM_HDD_FILE}"
# Other stuff
VBoxManage modifyvm "${VM}" --nic1 nat
VBoxManage startvm --type=gui "${VM}"
# Wait until we're done with it
wait_vm_quit ${VM}
echo -n "Remove the ${VM} VM?"
read answer
if [[ "$answer" != "${answer#[Yy]}" ]]; then
VBoxManage unregistervm "$VM" --delete
fi