forked from AntonioMeireles/ClearLinux-packer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvboxguestsetup.sh
More file actions
79 lines (65 loc) · 2.47 KB
/
vboxguestsetup.sh
File metadata and controls
79 lines (65 loc) · 2.47 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
default="/home/clear/VBoxGuestAdditions.iso"
mountpoint=$(mktemp -d -t vbga.XXXXXXXXXX)
guest_additions=$(mktemp -d -t vbga.XXXXXXXXXX)
linux_bits=$(mktemp -d -t vbga.XXXXXXXXXX)
function error() {
echo "E: $*" >>/dev/stderr
exit 1
}
function cleanup() {
umount "${mountpoint}"
rm -rf "${guest_additions}" "${default}" "${mountpoint}" "${linux_bits}"
}
trap cleanup EXIT
if [ "$(id -u)" -ne 0 ]; then
error "You must be 'root' to execute this script"
fi
if [[ -f "${default}" ]]; then
mount "${default}" "${mountpoint}" -t iso9660 -o ro
else
drives_found=$(lsblk | grep sr | cut -c -3)
if [ -z "${drives_found}" ]; then
error 'CDROM drives NOT FOUND - Please attach the Guest Additions CD image...'
fi
ga_found=0
for cdrom in ${drives_found}; do
mount "/dev/${cdrom}" "${mountpoint}" -t iso9660 -o ro
if [ -f "${mountpoint}/VBoxLinuxAdditions.run" ]; then
ga_found=1
break
fi
umount "${mountpoint}"
done
[[ ga_found -eq 1 ]] || error 'CDROM drives NOT FOUND - Please attach the Guest Additions CD image...'
fi
"${mountpoint}/VBoxLinuxAdditions.run" --noexec --keep --nox11 --target "${guest_additions}"
tar xjf "${guest_additions}/VBoxGuestAdditions-amd64.tar.bz2" -C "${linux_bits}"
for f in "${linux_bits}"{/bin/{VBoxClient,VBoxControl},/sbin/VBoxService,/other/mount.vboxsf}; do
install -m0755 "${f}" '/usr/bin'
done
install -Dm0755 "${linux_bits}/other/98vboxadd-xclient" '/usr/bin/VBoxClient-all'
install -Dm0644 "${linux_bits}/other/vboxclient.desktop" '/usr/share/xdg/autostart/vboxclient.desktop'
install -m0755 "${linux_bits}/lib/"VBoxOGL*.so '/usr/lib64/'
install -d '/usr/lib64/dri'
ln -s '/usr/lib64/VBoxOGL.so' '/usr/lib64/dri/vboxvideo_dri.so'
install -Dm0755 -D "${linux_bits}/other/pam_vbox.so" '/usr/lib64/security/pam_vbox.so'
install -d '/etc/udev/rules.d'
printf %s '
ACTION=="add", KERNEL=="vboxguest", SUBSYSTEM=="misc", OWNER="root", MODE="0600"
ACTION=="add", KERNEL=="vboxuser", SUBSYSTEM=="misc", OWNER="root", MODE="0666"
' | tee '/etc/udev/rules.d/60-vboxguest.rules'
chmod 0644 '/etc/udev/rules.d/60-vboxguest.rules'
printf %s '
[Unit]
Description=VirtualBox Guest Service
ConditionVirtualization=oracle
[Service]
ExecStartPre=-/usr/bin/modprobe vboxguest
ExecStartPre=-/usr/bin/modprobe vboxvideo
ExecStartPre=-/usr/bin/modprobe vboxsf
ExecStart=/usr/bin/VBoxService -f
[Install]
WantedBy=multi-user.target
' | tee '/etc/systemd/system/vboxservice.service'
chmod 0644 '/etc/systemd/system/vboxservice.service'