summaryrefslogtreecommitdiff
path: root/src/VBox/Additions/darwin/Installer/VBoxGuestAdditionsToolsAndServices/VBoxServiceWrapper
blob: f656e566074f233621484bc28d94d6f64e1f957b (plain)
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
#!/bin/sh
## @file
# VBoxService wrapper script.
#
# Load required kernel extensions before start service (if necessary).
#

#
# Copyright (C) 2007-2022 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#

export PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"

echo "Check if kernel extensions loaded..."
items="VBoxGuest"
for item in $items; do
    kext_item="org.virtualbox.kext.$item"
    loaded=`kextstat | grep $kext_item`
    if [ -z "$loaded" ] ; then
        echo "Loading $item kernel extension..."
        XNU_VERSION=`LC_ALL=C uname -r | LC_ALL=C cut -d . -f 1`
        if [ "$XNU_VERSION" -ge "10" ]; then
            kextutil /Library/Extensions/$item.kext
        else
            kextload /Library/Extensions/$item.kext
        fi
    fi
done

echo "Check if VBoxClient is added for all non-system users"
for user in $(dscl . -list /Users | grep -v -e'^_' -e'root'); do
    system_user="YES"
    test -n "$(dscl . -read /Users/$user NFSHomeDirectory | grep '/Users')" && system_user="NO"
    if [ "$system_user" = "NO" ]; then
        loaded="NO"
        test -n "$(sudo -u "$user" launchctl list | grep 'org.virtualbox.additions.vboxclient')" && loaded="YES"
        if [ "$loaded" = "NO" ] ; then
            echo "Loading org.virtualbox.additions.vboxclient for $user"
            sudo -u "$user" launchctl load -F "/Library/LaunchAgents/org.virtualbox.additions.vboxclient.plist"
        fi
    fi
done

exec "/Library/Application Support/VirtualBox Guest Additions/VBoxService" -f