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