-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathvirtualbox.sh
More file actions
63 lines (53 loc) · 2.49 KB
/
Copy pathvirtualbox.sh
File metadata and controls
63 lines (53 loc) · 2.49 KB
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
#!/bin/sh -eux
# set a default HOME_DIR environment variable if not set
HOME_DIR="${HOME_DIR:-/home/vagrant}";
case "$PACKER_BUILDER_TYPE" in
virtualbox-iso|virtualbox-ovf)
if ! ([ "$(uname -m)" = "aarch64" ] && [ -f /etc/os-release ] && (grep -qi 'opensuse' /etc/os-release || grep -qi 'sles' /etc/os-release)); then
ARCHITECTURE="$(uname -m)";
VER="$(cat "$HOME_DIR"/.vbox_version)";
ISO="VBoxGuestAdditions_$VER.iso";
# mount the ISO to /tmp/vbox
mkdir -p /tmp/vbox;
mount -o loop "$HOME_DIR"/"$ISO" /tmp/vbox;
echo "installing deps necessary to compile kernel modules"
# We install things like kernel-headers here vs. kickstart files so we make sure we install them for the updated kernel not the stock kernel
if [ -f "/bin/dnf" ]; then
dnf install -y --skip-broken perl cpp gcc make bzip2 tar kernel-headers kernel-devel kernel-uek-devel || true # not all these packages are on every system
elif [ -f "/usr/bin/apt-get" ]; then
apt-get install -y build-essential dkms bzip2 tar linux-headers-"$(uname -r)"
elif [ -f "/usr/bin/zypper" ]; then
zypper install -y perl cpp gcc make bzip2 tar kernel-default-devel
elif [ -f "/sbin/apk" ]; then
apk add perl musl-dev gcc make bzip2 tar linux-headers
fi
echo "installing the vbox additions for architecture $ARCHITECTURE"
# this install script fails with non-zero exit codes for no apparent reason so we need better ways to know if it worked
if [ "$ARCHITECTURE" = "aarch64" ]; then
/tmp/vbox/VBoxLinuxAdditions-arm64.run --nox11 || true
else
/tmp/vbox/VBoxLinuxAdditions.run --nox11 || true
fi
if ! modinfo vboxsf >/dev/null 2>&1; then
echo "Cannot find vbox kernel module. Installation of guest additions unsuccessful!"
exit 1
fi
echo "unmounting and removing the vbox ISO"
umount /tmp/vbox;
rm -rf /tmp/vbox;
rm -f "$HOME_DIR"/*.iso;
echo "removing kernel dev packages and compilers we no longer need"
if [ -f "/bin/dnf" ]; then
dnf remove -y gcc cpp kernel-headers kernel-devel kernel-uek-devel
elif [ -f "/usr/bin/apt-get" ]; then
apt-get remove -y build-essential gcc g++ make libc6-dev dkms linux-headers-"$(uname -r)"
elif [ -f "/usr/bin/zypper" ]; then
zypper -n rm -u kernel-default-devel gcc make
fi
echo "removing leftover logs"
rm -rf /var/log/vboxadd*
else
echo "Skipping Virtualbox guest additions installation on aarch64 architecture for opensuse and derivatives"
fi
;;
esac