1 | #!/bin/bash
|
---|
2 | # $Id: VirtualBox_Uninstall.tool 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # VirtualBox Uninstaller 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 uninstaller script."
|
---|
37 | echo ""
|
---|
38 |
|
---|
39 | #
|
---|
40 | # Check for arguments and display
|
---|
41 | #
|
---|
42 | my_default_prompt=0
|
---|
43 | if test "$#" != "0"; then
|
---|
44 | if test "$#" != "1" -o "$1" != "--unattended"; then
|
---|
45 | echo "Error: Unknown argument(s): $*"
|
---|
46 | echo ""
|
---|
47 | echo "Usage: uninstall.sh [--unattended]"
|
---|
48 | echo ""
|
---|
49 | echo "If the '--unattended' option is not given, you will be prompted"
|
---|
50 | echo "for a Yes/No before doing the actual uninstallation."
|
---|
51 | echo ""
|
---|
52 | exit 4;
|
---|
53 | fi
|
---|
54 | my_default_prompt="Yes"
|
---|
55 | fi
|
---|
56 |
|
---|
57 | #
|
---|
58 | # Collect directories and files to remove.
|
---|
59 | # Note: Do NOT attempt adding directories or filenames with spaces!
|
---|
60 | #
|
---|
61 | declare -a my_directories
|
---|
62 | declare -a my_files
|
---|
63 |
|
---|
64 | # Users files first
|
---|
65 | test -f "${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist" && my_files+=("${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist")
|
---|
66 |
|
---|
67 | test -d /Library/StartupItems/VirtualBox/ && my_directories+=("/Library/StartupItems/VirtualBox/")
|
---|
68 | test -d /Library/Receipts/VBoxStartupItems.pkg/ && my_directories+=("/Library/Receipts/VBoxStartupItems.pkg/")
|
---|
69 |
|
---|
70 | test -d "/Library/Application Support/VirtualBox/LaunchDaemons/" && my_directories+=("/Library/Application Support/VirtualBox/LaunchDaemons/")
|
---|
71 | test -d "/Library/Application Support/VirtualBox/VBoxDrv.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxDrv.kext/")
|
---|
72 | test -d "/Library/Application Support/VirtualBox/VBoxUSB.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxUSB.kext/")
|
---|
73 | test -d "/Library/Application Support/VirtualBox/VBoxNetFlt.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxNetFlt.kext/")
|
---|
74 | test -d "/Library/Application Support/VirtualBox/VBoxNetAdp.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxNetAdp.kext/")
|
---|
75 | # Pre 4.3.0rc1 locations:
|
---|
76 | test -d /Library/Extensions/VBoxDrv.kext/ && my_directories+=("/Library/Extensions/VBoxDrv.kext/")
|
---|
77 | test -d /Library/Extensions/VBoxUSB.kext/ && my_directories+=("/Library/Extensions/VBoxUSB.kext/")
|
---|
78 | test -d /Library/Extensions/VBoxNetFlt.kext/ && my_directories+=("/Library/Extensions/VBoxNetFlt.kext/")
|
---|
79 | test -d /Library/Extensions/VBoxNetAdp.kext/ && my_directories+=("/Library/Extensions/VBoxNetAdp.kext/")
|
---|
80 | # Tiger support is obsolete, but we leave it here for a clean removing of older
|
---|
81 | # VirtualBox versions
|
---|
82 | test -d /Library/Extensions/VBoxDrvTiger.kext/ && my_directories+=("/Library/Extensions/VBoxDrvTiger.kext/")
|
---|
83 | test -d /Library/Extensions/VBoxUSBTiger.kext/ && my_directories+=("/Library/Extensions/VBoxUSBTiger.kext/")
|
---|
84 | test -d /Library/Receipts/VBoxKEXTs.pkg/ && my_directories+=("/Library/Receipts/VBoxKEXTs.pkg/")
|
---|
85 |
|
---|
86 | test -f /usr/bin/VirtualBox && my_files+=("/usr/bin/VirtualBox")
|
---|
87 | test -f /usr/bin/VirtualBoxVM && my_files+=("/usr/bin/VirtualBoxVM")
|
---|
88 | test -f /usr/bin/VBoxManage && my_files+=("/usr/bin/VBoxManage")
|
---|
89 | test -f /usr/bin/VBoxVRDP && my_files+=("/usr/bin/VBoxVRDP")
|
---|
90 | test -f /usr/bin/VBoxHeadless && my_files+=("/usr/bin/VBoxHeadless")
|
---|
91 | test -f /usr/bin/vboxwebsrv && my_files+=("/usr/bin/vboxwebsrv")
|
---|
92 | test -f /usr/bin/VBoxBugReport && my_files+=("/usr/bin/VBoxBugReport")
|
---|
93 | test -f /usr/bin/VBoxBalloonCtrl && my_files+=("/usr/bin/VBoxBalloonCtrl")
|
---|
94 | test -f /usr/bin/VBoxAutostart && my_files+=("/usr/bin/VBoxAutostart")
|
---|
95 | test -f /usr/bin/VBoxDTrace && my_files+=("/usr/bin/VBoxDTrace")
|
---|
96 | test -f /usr/bin/VBoxAudioTest && my_files+=("/usr/bin/VBoxAudioTest")
|
---|
97 | test -f /usr/bin/vbox-img && my_files+=("/usr/bin/vbox-img")
|
---|
98 | test -f /usr/local/bin/VirtualBox && my_files+=("/usr/local/bin/VirtualBox")
|
---|
99 | test -f /usr/local/bin/VirtualBoxVM && my_files+=("/usr/local/bin/VirtualBoxVM")
|
---|
100 | test -f /usr/local/bin/VBoxManage && my_files+=("/usr/local/bin/VBoxManage")
|
---|
101 | test -f /usr/local/bin/VBoxVRDP && my_files+=("/usr/local/bin/VBoxVRDP")
|
---|
102 | test -f /usr/local/bin/VBoxHeadless && my_files+=("/usr/local/bin/VBoxHeadless")
|
---|
103 | test -f /usr/local/bin/vboxwebsrv && my_files+=("/usr/local/bin/vboxwebsrv")
|
---|
104 | test -f /usr/local/bin/VBoxBugReport && my_files+=("/usr/local/bin/VBoxBugReport")
|
---|
105 | test -f /usr/local/bin/VBoxBalloonCtrl && my_files+=("/usr/local/bin/VBoxBalloonCtrl")
|
---|
106 | test -f /usr/local/bin/VBoxAutostart && my_files+=("/usr/local/bin/VBoxAutostart")
|
---|
107 | test -f /usr/local/bin/VBoxDTrace && my_files+=("/usr/local/bin/VBoxDTrace")
|
---|
108 | test -f /usr/local/bin/VBoxAudioTest && my_files+=("/usr/local/bin/VBoxAudioTest")
|
---|
109 | test -f /usr/local/bin/vbox-img && my_files+=("/usr/local/bin/vbox-img")
|
---|
110 | test -d /Library/Receipts/VirtualBoxCLI.pkg/ && my_directories+=("/Library/Receipts/VirtualBoxCLI.pkg/")
|
---|
111 | test -f /Library/LaunchDaemons/org.virtualbox.startup.plist && my_files+=("/Library/LaunchDaemons/org.virtualbox.startup.plist")
|
---|
112 |
|
---|
113 | test -d /Applications/VirtualBox.app/ && my_directories+=("/Applications/VirtualBox.app/")
|
---|
114 | test -d /Library/Receipts/VirtualBox.pkg/ && my_directories+=("/Library/Receipts/VirtualBox.pkg/")
|
---|
115 |
|
---|
116 | # legacy
|
---|
117 | test -d /Library/Receipts/VBoxDrv.pkg/ && my_directories+=("/Library/Receipts/VBoxDrv.pkg/")
|
---|
118 | test -d /Library/Receipts/VBoxUSB.pkg/ && my_directories+=("/Library/Receipts/VBoxUSB.pkg/")
|
---|
119 |
|
---|
120 | # python stuff
|
---|
121 | python_versions="2.3 2.5 2.6 2.7"
|
---|
122 | for p in $python_versions; do
|
---|
123 | test -f /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.py && my_files+=("/Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.py")
|
---|
124 | test -f /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.pyc && my_files+=("/Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.pyc")
|
---|
125 | test -f /Library/Python/$p/site-packages/vboxapi/__init__.py && my_files+=("/Library/Python/$p/site-packages/vboxapi/__init__.py")
|
---|
126 | test -f /Library/Python/$p/site-packages/vboxapi/__init__.pyc && my_files+=("/Library/Python/$p/site-packages/vboxapi/__init__.pyc")
|
---|
127 | test -f /Library/Python/$p/site-packages/vboxapi-1.0-py$p.egg-info && my_files+=("/Library/Python/$p/site-packages/vboxapi-1.0-py$p.egg-info")
|
---|
128 | test -d /Library/Python/$p/site-packages/vboxapi/ && my_directories+=("/Library/Python/$p/site-packages/vboxapi/")
|
---|
129 | done
|
---|
130 |
|
---|
131 | #
|
---|
132 | # Collect KEXTs to remove.
|
---|
133 | # Note that the unload order is significant.
|
---|
134 | #
|
---|
135 | declare -a my_kexts
|
---|
136 | for kext in org.virtualbox.kext.VBoxUSB org.virtualbox.kext.VBoxNetFlt org.virtualbox.kext.VBoxNetAdp org.virtualbox.kext.VBoxDrv; do
|
---|
137 | if /usr/sbin/kextstat -b $kext -l | grep -q $kext; then
|
---|
138 | my_kexts+=("$kext")
|
---|
139 | fi
|
---|
140 | done
|
---|
141 |
|
---|
142 | #
|
---|
143 | # Collect packages to forget
|
---|
144 | #
|
---|
145 | my_pb='org\.virtualbox\.pkg\.'
|
---|
146 | my_pkgs=`/usr/sbin/pkgutil --pkgs="${my_pb}vboxkexts|${my_pb}vboxstartupitems|${my_pb}virtualbox|${my_pb}virtualboxcli"`
|
---|
147 |
|
---|
148 | #
|
---|
149 | # Did we find anything to uninstall?
|
---|
150 | #
|
---|
151 | if test -z "${my_directories[*]}" -a -z "${my_files[*]}" -a -z "${my_kexts[*]}" -a -z "$my_pkgs"; then
|
---|
152 | echo "No VirtualBox files, directories, KEXTs or packages to uninstall."
|
---|
153 | echo "Done."
|
---|
154 | exit 0;
|
---|
155 | fi
|
---|
156 |
|
---|
157 | #
|
---|
158 | # Look for running VirtualBox processes and warn the user
|
---|
159 | # if something is running. Since deleting the files of
|
---|
160 | # running processes isn't fatal as such, we will leave it
|
---|
161 | # to the user to choose whether to continue or not.
|
---|
162 | #
|
---|
163 | # Note! comm isn't supported on Tiger, so we make -c to do the stripping.
|
---|
164 | #
|
---|
165 | my_processes="`ps -axco 'pid uid command' | grep -wEe '(VirtualBox|VirtualBoxVM|VBoxManage|VBoxHeadless|vboxwebsrv|VBoxXPCOMIPCD|VBoxSVC|VBoxNetDHCP|VBoxNetNAT)' | grep -vw grep | grep -vw VirtualBox_Uninstall.tool | tr '\n' '\a'`";
|
---|
166 | if test -n "$my_processes"; then
|
---|
167 | echo 'Warning! Found the following active VirtualBox processes:'
|
---|
168 | echo "$my_processes" | tr '\a' '\n'
|
---|
169 | echo ""
|
---|
170 | echo "We recommend that you quit all VirtualBox processes before"
|
---|
171 | echo "uninstalling the product."
|
---|
172 | echo ""
|
---|
173 | if test "$my_default_prompt" != "Yes"; then
|
---|
174 | echo "Do you wish to continue none the less (Yes/No)?"
|
---|
175 | read my_answer
|
---|
176 | if test "$my_answer" != "Yes" -a "$my_answer" != "YES" -a "$my_answer" != "yes"; then
|
---|
177 | echo "Aborting uninstall. (answer: '$my_answer')".
|
---|
178 | exit 2;
|
---|
179 | fi
|
---|
180 | echo ""
|
---|
181 | my_answer=""
|
---|
182 | fi
|
---|
183 | fi
|
---|
184 |
|
---|
185 | #
|
---|
186 | # Display the files and directories that will be removed
|
---|
187 | # and get the user's consent before continuing.
|
---|
188 | #
|
---|
189 | if test -n "${my_files[*]}" -o -n "${my_directories[*]}"; then
|
---|
190 | echo "The following files and directories (bundles) will be removed:"
|
---|
191 | for file in "${my_files[@]}"; do echo " $file"; done
|
---|
192 | for dir in "${my_directories[@]}"; do echo " $dir"; done
|
---|
193 | echo ""
|
---|
194 | fi
|
---|
195 | if test -n "${my_kexts[*]}"; then
|
---|
196 | echo "And the following KEXTs will be unloaded:"
|
---|
197 | for kext in "${my_kexts[@]}"; do echo " $kext"; done
|
---|
198 | echo ""
|
---|
199 | fi
|
---|
200 | if test -n "$my_pkgs"; then
|
---|
201 | echo "And the traces of following packages will be removed:"
|
---|
202 | for kext in $my_pkgs; do echo " $kext"; done
|
---|
203 | echo ""
|
---|
204 | fi
|
---|
205 |
|
---|
206 | if test "$my_default_prompt" != "Yes"; then
|
---|
207 | echo "Do you wish to uninstall VirtualBox (Yes/No)?"
|
---|
208 | read my_answer
|
---|
209 | if test "$my_answer" != "Yes" -a "$my_answer" != "YES" -a "$my_answer" != "yes"; then
|
---|
210 | echo "Aborting uninstall. (answer: '$my_answer')".
|
---|
211 | exit 2;
|
---|
212 | fi
|
---|
213 | echo ""
|
---|
214 | fi
|
---|
215 |
|
---|
216 | my_fuse_macos_core_uninstall=0
|
---|
217 | if test "$my_default_prompt" != "Yes" -a -f "/Library/Filesystems/osxfuse.fs/Contents/Resources/uninstall_osxfuse.app/Contents/Resources/Scripts/uninstall_osxfuse.sh"; then
|
---|
218 | echo "VirtualBox detected the FUSE for macOS core package which might've been installed"
|
---|
219 | echo "by VirtualBox itself for the vboximg-mount utility. Do you wish to uninstall"
|
---|
220 | echo "the FUSE for macOS core package (Yes/No)?"
|
---|
221 | read my_answer
|
---|
222 | if test "$my_answer" == "Yes" -o "$my_answer" == "YES" -o "$my_answer" == "yes"; then
|
---|
223 | my_fuse_macos_core_uninstall=1;
|
---|
224 | fi
|
---|
225 | echo ""
|
---|
226 | fi
|
---|
227 |
|
---|
228 | #
|
---|
229 | # Unregister has to be done before the files are removed.
|
---|
230 | #
|
---|
231 | LSREGISTER=/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
|
---|
232 | if [ -e ${LSREGISTER} ]; then
|
---|
233 | ${LSREGISTER} -u /Applications/VirtualBox.app > /dev/null
|
---|
234 | ${LSREGISTER} -u /Applications/VirtualBox.app/Contents/Resources/vmstarter.app > /dev/null
|
---|
235 | fi
|
---|
236 |
|
---|
237 | #
|
---|
238 | # Display the sudo usage instructions and execute the command.
|
---|
239 | #
|
---|
240 | echo "The uninstallation processes requires administrative privileges"
|
---|
241 | echo "because some of the installed files cannot be removed by a normal"
|
---|
242 | echo "user. You may be prompted for your password now..."
|
---|
243 | echo ""
|
---|
244 |
|
---|
245 | if test -n "${my_files[*]}" -o -n "${my_directories[*]}"; then
|
---|
246 | /usr/bin/sudo -p "Please enter %u's password:" /bin/rm -Rf "${my_files[@]}" "${my_directories[@]}"
|
---|
247 | my_rc=$?
|
---|
248 | if test "$my_rc" -ne 0; then
|
---|
249 | echo "An error occurred durning 'sudo rm', there should be a message above. (rc=$my_rc)"
|
---|
250 | test -x /usr/bin/sudo || echo "warning: Cannot find /usr/bin/sudo or it's not an executable."
|
---|
251 | test -x /bin/rm || echo "warning: Cannot find /bin/rm or it's not an executable"
|
---|
252 | echo ""
|
---|
253 | echo "The uninstall failed. Please retry."
|
---|
254 | test "$my_default_prompt" != "Yes" && read -p "Press <ENTER> to exit"
|
---|
255 | exit 1;
|
---|
256 | fi
|
---|
257 | fi
|
---|
258 |
|
---|
259 | if test "$my_fuse_macos_core_uninstall" != 0; then
|
---|
260 | echo "Uninstalling the FUSE for macOS core package"
|
---|
261 | /usr/bin/sudo -p "Please enter %u's password:" /Library/Filesystems/osxfuse.fs/Contents/Resources/uninstall_osxfuse.app/Contents/Resources/Scripts/uninstall_osxfuse.sh
|
---|
262 | fi
|
---|
263 |
|
---|
264 | my_rc=0
|
---|
265 | for kext in "${my_kexts[@]}"; do
|
---|
266 | echo unloading $kext
|
---|
267 | /usr/bin/sudo -p "Please enter %u's password (unloading $kext):" /sbin/kextunload -m $kext
|
---|
268 | my_rc2=$?
|
---|
269 | if test "$my_rc2" -ne 0; then
|
---|
270 | echo "An error occurred durning 'sudo /sbin/kextunload -m $kext', there should be a message above. (rc=$my_rc2)"
|
---|
271 | test -x /usr/bin/sudo || echo "warning: Cannot find /usr/bin/sudo or it's not an executable."
|
---|
272 | test -x /sbin/kextunload || echo "warning: Cannot find /sbin/kextunload or it's not an executable"
|
---|
273 | my_rc=$my_rc2
|
---|
274 | fi
|
---|
275 | done
|
---|
276 | if test "$my_rc" -eq 0; then
|
---|
277 | echo "Successfully unloaded VirtualBox kernel extensions."
|
---|
278 | else
|
---|
279 | echo "Failed to unload one or more KEXTs, please reboot the machine to complete the uninstall."
|
---|
280 | test "$my_default_prompt" != "Yes" && read -p "Press <ENTER> to exit"
|
---|
281 | exit 1;
|
---|
282 | fi
|
---|
283 |
|
---|
284 | # Cleaning up pkgutil database
|
---|
285 | for my_pkg in $my_pkgs; do
|
---|
286 | /usr/bin/sudo -p "Please enter %u's password (removing $my_pkg):" /usr/sbin/pkgutil --forget "$my_pkg"
|
---|
287 | done
|
---|
288 |
|
---|
289 | echo "Done."
|
---|
290 | exit 0;
|
---|
291 |
|
---|