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