1 | #!/bin/sh
|
---|
2 | # $Id: postflight 93115 2022-01-01 11:31:46Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # Post flight installer script for the VirtualBox OS X kernel extensions.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2007-2022 Oracle Corporation
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | # available from http://www.virtualbox.org. This file is free software;
|
---|
12 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | # General Public License (GPL) as published by the Free Software
|
---|
14 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | #
|
---|
18 |
|
---|
19 | set -e
|
---|
20 |
|
---|
21 | # Setup environment.
|
---|
22 | export PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"
|
---|
23 |
|
---|
24 | unload_service()
|
---|
25 | {
|
---|
26 | ITEM_ID=$1
|
---|
27 | ITEM_PATH=$2
|
---|
28 | FORCED_USER=$3
|
---|
29 |
|
---|
30 | loaded="NO"
|
---|
31 | test -n "$(sudo -u "$FORCED_USER" launchctl list | grep $ITEM_ID)" && loaded="YES"
|
---|
32 | if [ "$loaded" = "YES" ] ; then
|
---|
33 | echo "Unloading previously installed service: $ITEM_ID"
|
---|
34 | sudo -u "$FORCED_USER" launchctl unload -F "$ITEM_PATH/$ITEM_ID.plist"
|
---|
35 | fi
|
---|
36 | }
|
---|
37 |
|
---|
38 | load_service()
|
---|
39 | {
|
---|
40 | ITEM_ID=$1
|
---|
41 | ITEM_PATH=$2
|
---|
42 | FORCED_USER=$3
|
---|
43 |
|
---|
44 | echo "Loading newly installed service: $ITEM_ID"
|
---|
45 | sudo -u "$FORCED_USER" launchctl load -F "$ITEM_PATH/$ITEM_ID.plist"
|
---|
46 | }
|
---|
47 |
|
---|
48 | unload_service "org.virtualbox.additions.vboxservice" "/Library/LaunchDaemons" "root"
|
---|
49 |
|
---|
50 | # Remove the old service for all users
|
---|
51 | for user in $(dscl . -list /Users | grep -v -e'^_' -e'root'); do
|
---|
52 | system_user="YES"
|
---|
53 | test -n "$(dscl . -read /Users/$user NFSHomeDirectory | grep '/Users')" && system_user="NO"
|
---|
54 | if [ "$system_user" = "NO" ]; then
|
---|
55 | unload_service "org.virtualbox.additions.vboxclient" "/Library/LaunchAgents" "$user"
|
---|
56 | fi
|
---|
57 | done
|
---|
58 |
|
---|
59 | items="VBoxGuest"
|
---|
60 | for item in $items; do
|
---|
61 | kext_item="org.virtualbox.kext.$item"
|
---|
62 |
|
---|
63 | loaded="NO"
|
---|
64 | test -n "$(kextstat | grep $kext_item)" && loaded="YES"
|
---|
65 | if [ "$loaded" = "YES" ] ; then
|
---|
66 | echo "Unloading $item kernel extension..."
|
---|
67 | kextunload -b $kext_item
|
---|
68 | fi
|
---|
69 | done
|
---|
70 |
|
---|
71 | MACOS_VERS=$(sw_vers -productVersion)
|
---|
72 |
|
---|
73 | echo "Updating kernel cache (should trigger loading of new modules)."
|
---|
74 | # /System/Library/Extensions is readonly in Catalina and later,
|
---|
75 | # so touch returns always false on these systems
|
---|
76 | if [[ ${MACOS_VERS} != 11.* ]] && [[ ${MACOS_VERS} != 10.15.* ]]; then
|
---|
77 | touch "/System/Library/Extensions/"
|
---|
78 | fi
|
---|
79 | kextcache -update-volume / || true
|
---|
80 |
|
---|
81 | load_service "org.virtualbox.additions.vboxservice" "/Library/LaunchDaemons" "root"
|
---|
82 | # Add VBoxClient for all currently defined users
|
---|
83 | for user in $(dscl . -list /Users | grep -v -e'^_' -e'root'); do
|
---|
84 | system_user="YES"
|
---|
85 | test -n "$(dscl . -read /Users/$user NFSHomeDirectory | grep '/Users')" && system_user="NO"
|
---|
86 | if [ "$system_user" = "NO" ]; then
|
---|
87 | load_service "org.virtualbox.additions.vboxclient" "/Library/LaunchAgents" "$user"
|
---|
88 | fi
|
---|
89 | done
|
---|
90 |
|
---|
91 | echo "Warning: If VBoxService adjusts the time backwards (because of --biossystemtimeoffset), the installer may hang."
|
---|
92 | echo "Done."
|
---|
93 |
|
---|
94 | exit 0;
|
---|