Skip to content

Commit 3fa349b

Browse files
committed
automatically generate OVA files, preinstall VirtualBox-Guest-Additions into those OVA files, set password to a generated value and store the information in description of VM
1 parent 3731ba7 commit 3fa349b

File tree

1 file changed

+70
-2
lines changed

1 file changed

+70
-2
lines changed

VirtualBox/make.sh

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,83 @@ VBoxManage modifyvm "$MACHINENAME" --graphicscontroller vboxsvga
4444
VBoxManage modifyvm "$MACHINENAME" --audioout on
4545
VBoxManage modifyvm "$MACHINENAME" --clipboard bidirectional
4646

47+
#we plan to change the password to this random value and keep a record in the description
48+
BBUSER_PASSWORD="$(cat /dev/urandom | tr -dc A-Z-a-z-0-9 | head -c10)"
49+
echo "new password is: $BBUSER_PASSWORD"
50+
VBoxManage modifyvm "$MACHINENAME" --description "Password for user \"bbuser\" is \"$BBUSER_PASSWORD\""
51+
4752
VBoxManage createhd --filename "$BASEFOLDER/VirtualBox/$MACHINENAME.vdi" --size $(("$HDD_MB")) --format VDI
4853
VBoxManage storagectl "$MACHINENAME" --name "SATA Controller" --add sata --controller "IntelAhci" --hostiocache on
4954
VBoxManage storageattach "$MACHINENAME" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$BASEFOLDER/VirtualBox/$MACHINENAME.vdi"
5055

51-
VBoxManage storageattach "$MACHINENAME" --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium "$ISO"
52-
#VBoxManage storageattach "$MACHINENAME" --storagectl "SATA Controller" --port 2 --device 0 --type dvddrive --medium "${GUESTISO##*/}"
56+
VBoxManage storageattach "$MACHINENAME" --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium "$ISO"
5357
VBoxManage modifyvm "$MACHINENAME" --boot1 dvd --boot2 disk --boot3 none --boot4 none
5458

5559
################################################################################
5660
# Run Virtualbox VM
5761
################################################################################
5862
VBoxManage startvm "$MACHINENAME" --type gui
63+
64+
# wait until the netinstaller ISO is ejected
65+
# alternatively check for this: "SATA Controller-1-0"="emptydrive"
66+
while true; do
67+
sleep 1
68+
VBoxManage showvminfo --machinereadable "$MACHINENAME" | grep "\"SATA Controller-IsEjected\"=\"on\""
69+
70+
if [ $? -eq 0 ]; then
71+
echo "CD ejected from $MACHINENAME"
72+
break
73+
fi
74+
done
75+
76+
#################################################################################
77+
# Install Guest-Additions
78+
#################################################################################
79+
80+
# if guest-additions-iso are already installed to this host machine this medium works
81+
#VBoxManage storageattach "$MACHINENAME" --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium additions
82+
# but we better be sure to have the ISO downloaded ourselves
83+
VBoxManage storageattach "$MACHINENAME" --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium "${GUESTISO##*/}"
84+
85+
#################################################################################
86+
# Wait till firefox-esr process is active
87+
# injecting commands into the VM only works if guest additions are working
88+
#################################################################################
89+
while true; do
90+
VBoxManage guestcontrol "$MACHINENAME" --username "bbuser" --password "%password%" run --exe /bin/bash -- bash -c "pidof firefox-esr > /dev/null" > /dev/null 2>&1
91+
if [ $? -eq 0 ]; then
92+
break
93+
fi
94+
sleep 1
95+
done
96+
97+
#################################################################################
98+
# set password
99+
#################################################################################
100+
#change password inside VM to a random password
101+
VBoxManage guestcontrol "$MACHINENAME" --username "bbuser" --password "%password%" run --exe /bin/bash -- bash -c "echo -e \"%password%\n$BBUSER_PASSWORD\n$BBUSER_PASSWORD\" | passwd bbuser"
102+
103+
# shutdown appliance
104+
VBoxManage guestcontrol "$MACHINENAME" --username "bbuser" --password "$BBUSER_PASSWORD" run --exe /bin/bash -- bash -c "sleep 10 && sudo /sbin/shutdown -h now"
105+
106+
# wait until VM is powered off
107+
while true; do
108+
sleep 1
109+
VBoxManage showvminfo --machinereadable "$MACHINENAME" | grep "VMState=\"poweroff\""
110+
111+
if [ $? -eq 0 ]; then
112+
echo "$MACHINENAME powered down"
113+
break
114+
fi
115+
done
116+
117+
#################################################################################
118+
# export appliance
119+
#################################################################################
120+
VBoxManage export "$MACHINENAME" --output "$BASEFOLDER/Releases/$MACHINENAME.ova" --ovf10 \
121+
--options manifest,nomacs \
122+
--vsys 0 \
123+
--vmname "$MACHINENAME" \
124+
--product "BrowserBox" \
125+
--producturl "https://github.com/Torxgewinde/BrowserBox" \
126+
--description "Password for user \"bbuser\" is \"$BBUSER_PASSWORD\""

0 commit comments

Comments
 (0)