1a84601801d5bd045712787a3ef59313795389a1vboxsync#!/bin/sh
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsync#
1a84601801d5bd045712787a3ef59313795389a1vboxsync# Copyright (C) 2007-2013 Oracle Corporation
1a84601801d5bd045712787a3ef59313795389a1vboxsync#
1a84601801d5bd045712787a3ef59313795389a1vboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
1a84601801d5bd045712787a3ef59313795389a1vboxsync# available from http://www.virtualbox.org. This file is free software;
1a84601801d5bd045712787a3ef59313795389a1vboxsync# you can redistribute it and/or modify it under the terms of the GNU
1a84601801d5bd045712787a3ef59313795389a1vboxsync# General Public License (GPL) as published by the Free Software
1a84601801d5bd045712787a3ef59313795389a1vboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
1a84601801d5bd045712787a3ef59313795389a1vboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1a84601801d5bd045712787a3ef59313795389a1vboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1a84601801d5bd045712787a3ef59313795389a1vboxsync#
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsyncset -e
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsync# Setup environment.
1a84601801d5bd045712787a3ef59313795389a1vboxsyncexport PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsyncunload_service()
1a84601801d5bd045712787a3ef59313795389a1vboxsync{
1a84601801d5bd045712787a3ef59313795389a1vboxsync ITEM_ID=$1
1a84601801d5bd045712787a3ef59313795389a1vboxsync ITEM_PATH=$2
1a84601801d5bd045712787a3ef59313795389a1vboxsync FORCED_USER=$3
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsync loaded="NO"
1a84601801d5bd045712787a3ef59313795389a1vboxsync test -n "$(sudo -u "$FORCED_USER" launchctl list | grep $ITEM_ID)" && loaded="YES"
1a84601801d5bd045712787a3ef59313795389a1vboxsync if [ "$loaded" = "YES" ] ; then
1a84601801d5bd045712787a3ef59313795389a1vboxsync echo "Unloading previously installed service: $ITEM_ID"
1a84601801d5bd045712787a3ef59313795389a1vboxsync sudo -u "$FORCED_USER" launchctl unload -F "$ITEM_PATH/$ITEM_ID.plist"
1a84601801d5bd045712787a3ef59313795389a1vboxsync fi
1a84601801d5bd045712787a3ef59313795389a1vboxsync}
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsyncload_service()
1a84601801d5bd045712787a3ef59313795389a1vboxsync{
1a84601801d5bd045712787a3ef59313795389a1vboxsync ITEM_ID=$1
1a84601801d5bd045712787a3ef59313795389a1vboxsync ITEM_PATH=$2
1a84601801d5bd045712787a3ef59313795389a1vboxsync FORCED_USER=$3
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsync echo "Loading newly installed service: $ITEM_ID"
1a84601801d5bd045712787a3ef59313795389a1vboxsync sudo -u "$FORCED_USER" launchctl load -F "$ITEM_PATH/$ITEM_ID.plist"
1a84601801d5bd045712787a3ef59313795389a1vboxsync}
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsyncunload_service "org.virtualbox.additions.vboxservice" "/Library/LaunchDaemons" "root"
1a84601801d5bd045712787a3ef59313795389a1vboxsyncunload_service "org.virtualbox.additions.vboxclient" "/Library/LaunchAgents" "${USER}"
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsyncitems="VBoxGuest"
1a84601801d5bd045712787a3ef59313795389a1vboxsyncfor item in $items; do
1a84601801d5bd045712787a3ef59313795389a1vboxsync kext_item="org.virtualbox.kext.$item"
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsync loaded="NO"
1a84601801d5bd045712787a3ef59313795389a1vboxsync test -n "$(kextstat | grep $kext_item)" && loaded="YES"
1a84601801d5bd045712787a3ef59313795389a1vboxsync if [ "$loaded" = "YES" ] ; then
1a84601801d5bd045712787a3ef59313795389a1vboxsync echo "Unloading $item kernel extension..."
1a84601801d5bd045712787a3ef59313795389a1vboxsync kextunload -b $kext_item
1a84601801d5bd045712787a3ef59313795389a1vboxsync fi
1a84601801d5bd045712787a3ef59313795389a1vboxsyncdone
1a84601801d5bd045712787a3ef59313795389a1vboxsyncecho "Loading newly installed kernel extensions."
1a84601801d5bd045712787a3ef59313795389a1vboxsynckextload "/Library/Extensions/VBoxGuest.kext"
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsyncload_service "org.virtualbox.additions.vboxservice" "/Library/LaunchDaemons" "root"
1a84601801d5bd045712787a3ef59313795389a1vboxsyncload_service "org.virtualbox.additions.vboxclient" "/Library/LaunchAgents" "${USER}"
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsyncecho "Done."
1a84601801d5bd045712787a3ef59313795389a1vboxsync
1a84601801d5bd045712787a3ef59313795389a1vboxsyncexit 0;