1 | #!/bin/sh
|
---|
2 | # $Id: Uninstall.tool 76553 2019-01-01 01:45:53Z vboxsync $
|
---|
3 | ## #file
|
---|
4 | # VirtualBox Guest Additions uninstall script.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2007-2019 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 | # Override any funny stuff from the user.
|
---|
20 | export PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"
|
---|
21 |
|
---|
22 | #
|
---|
23 | # Display a simple welcome message first.
|
---|
24 | #
|
---|
25 | echo ""
|
---|
26 | echo "Welcome to the VirtualBox Guest Additions uninstall script."
|
---|
27 | echo ""
|
---|
28 |
|
---|
29 | # Check if user interraction is required to start uninstall process.
|
---|
30 | fUnattended=0
|
---|
31 | if test "$#" != "0"; then
|
---|
32 | if test "$#" != "1" -o "$1" != "--unattended"; then
|
---|
33 | echo "Error: Unknown argument(s): $*"
|
---|
34 | echo ""
|
---|
35 | echo "Usage: $0 [--unattended]"
|
---|
36 | echo ""
|
---|
37 | echo "If the '--unattended' option is not given, you will be prompted"
|
---|
38 | echo "for a Yes/No before doing the actual uninstallation."
|
---|
39 | echo ""
|
---|
40 | exit 4;
|
---|
41 | fi
|
---|
42 | fUnattended="Yes"
|
---|
43 | fi
|
---|
44 |
|
---|
45 | if test "$fUnattended" != "Yes"; then
|
---|
46 | echo "Do you wish to continue none the less (Yes/No)?"
|
---|
47 | read fUnattended
|
---|
48 | if test "$fUnattended" != "Yes" -a "$fUnattended" != "YES" -a "$fUnattended" != "yes"; then
|
---|
49 | echo "Aborting uninstall. (answer: '$fUnattended')".
|
---|
50 | exit 2;
|
---|
51 | fi
|
---|
52 | echo ""
|
---|
53 | fi
|
---|
54 |
|
---|
55 | # Stop services
|
---|
56 | echo "Checking running services..."
|
---|
57 | unload()
|
---|
58 | {
|
---|
59 | ITEM_ID=$1
|
---|
60 | ITEM_PATH=$2
|
---|
61 | FORCED_USER=$3
|
---|
62 |
|
---|
63 | echo "Unloading $ITEM_ID"
|
---|
64 |
|
---|
65 |
|
---|
66 | loaded="NO"
|
---|
67 | test -n "$(sudo -u "$FORCED_USER" launchctl list | grep $ITEM_ID)" && loaded="YES"
|
---|
68 | if [ "$loaded" = "YES" ] ; then
|
---|
69 | sudo -p "Please enter $FORCED_USER's password (unloading $ITEM_ID):" sudo -u "$FORCED_USER" launchctl unload -F "$ITEM_PATH/$ITEM_ID.plist"
|
---|
70 | fi
|
---|
71 |
|
---|
72 | }
|
---|
73 |
|
---|
74 | unload "org.virtualbox.additions.vboxservice" "/Library/LaunchDaemons" "root"
|
---|
75 | unload "org.virtualbox.additions.vboxclient" "/Library/LaunchAgents" `whoami`
|
---|
76 |
|
---|
77 | # Unload kernel extensions
|
---|
78 | echo "Checking running kernel extensions..."
|
---|
79 | items="VBoxGuest"
|
---|
80 | for item in $items; do
|
---|
81 | kext_item="org.virtualbox.kext.$item"
|
---|
82 | loaded=`kextstat | grep $kext_item`
|
---|
83 | if [ ! -z "$loaded" ] ; then
|
---|
84 | echo "Unloading $item kernel extension"
|
---|
85 | sudo -p "Please enter %u's password (unloading $item):" kextunload -b $kext_item
|
---|
86 | fi
|
---|
87 | done
|
---|
88 |
|
---|
89 | # Remove files and directories
|
---|
90 | echo "Checking files and directories..."
|
---|
91 | sudo -p "Please enter %u's password (removing files and directories):" rm -rf "/Library/Application Support/VirtualBox Guest Additions"
|
---|
92 | sudo -p "Please enter %u's password (removing files and directories):" rm -rf "/Library/Extensions/VBoxGuest.kext"
|
---|
93 | sudo -p "Please enter %u's password (removing files and directories):" rm -rf "/Library/LaunchAgents/org.virtualbox.additions.vboxclient.plist"
|
---|
94 | sudo -p "Please enter %u's password (removing files and directories):" rm -rf "/Library/LaunchDaemons/org.virtualbox.additions.vboxservice.plist"
|
---|
95 |
|
---|
96 | # Cleaning up pkgutil database
|
---|
97 | echo "Checking package database ..."
|
---|
98 | items="kexts tools-and-services"
|
---|
99 | for item in $items; do
|
---|
100 | pkg_item="org.virtualbox.pkg.additions.$item"
|
---|
101 | installed=`pkgutil --pkgs="$pkg_item"`
|
---|
102 | if [ ! -z "$installed" ] ; then
|
---|
103 | sudo -p "Please enter %u's password (removing $pkg_item):" pkgutil --forget "$pkg_item"
|
---|
104 | fi
|
---|
105 | done
|
---|
106 |
|
---|
107 | # Remove our kexts from the cache.
|
---|
108 | echo "Updating kernel cache."
|
---|
109 | sudo -p "Please enter %u's password (refreshing kext cache):" touch "/System/Library/Extensions/"
|
---|
110 | sudo -p "Please enter %u's password (refreshing kext cache):" kextcache -update-volume /
|
---|
111 |
|
---|
112 | echo "Done."
|
---|
113 | exit 0;
|
---|
114 |
|
---|