VirtualBox

source: vbox/trunk/src/VBox/Installer/darwin/DiskImage/VirtualBox_Uninstall.tool@ 98709

Last change on this file since 98709 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 13.6 KB
Line 
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.
30export PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"
31
32#
33# Display a simple welcome message first.
34#
35echo ""
36echo "Welcome to the VirtualBox uninstaller script."
37echo ""
38
39#
40# Check for arguments and display
41#
42my_default_prompt=0
43if 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"
55fi
56
57#
58# Collect directories and files to remove.
59# Note: Do NOT attempt adding directories or filenames with spaces!
60#
61declare -a my_directories
62declare -a my_files
63
64# Users files first
65test -f "${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist" && my_files+=("${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist")
66
67test -d /Library/StartupItems/VirtualBox/ && my_directories+=("/Library/StartupItems/VirtualBox/")
68test -d /Library/Receipts/VBoxStartupItems.pkg/ && my_directories+=("/Library/Receipts/VBoxStartupItems.pkg/")
69
70test -d "/Library/Application Support/VirtualBox/LaunchDaemons/" && my_directories+=("/Library/Application Support/VirtualBox/LaunchDaemons/")
71test -d "/Library/Application Support/VirtualBox/VBoxDrv.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxDrv.kext/")
72test -d "/Library/Application Support/VirtualBox/VBoxUSB.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxUSB.kext/")
73test -d "/Library/Application Support/VirtualBox/VBoxNetFlt.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxNetFlt.kext/")
74test -d "/Library/Application Support/VirtualBox/VBoxNetAdp.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxNetAdp.kext/")
75# Pre 4.3.0rc1 locations:
76test -d /Library/Extensions/VBoxDrv.kext/ && my_directories+=("/Library/Extensions/VBoxDrv.kext/")
77test -d /Library/Extensions/VBoxUSB.kext/ && my_directories+=("/Library/Extensions/VBoxUSB.kext/")
78test -d /Library/Extensions/VBoxNetFlt.kext/ && my_directories+=("/Library/Extensions/VBoxNetFlt.kext/")
79test -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
82test -d /Library/Extensions/VBoxDrvTiger.kext/ && my_directories+=("/Library/Extensions/VBoxDrvTiger.kext/")
83test -d /Library/Extensions/VBoxUSBTiger.kext/ && my_directories+=("/Library/Extensions/VBoxUSBTiger.kext/")
84test -d /Library/Receipts/VBoxKEXTs.pkg/ && my_directories+=("/Library/Receipts/VBoxKEXTs.pkg/")
85
86test -f /usr/bin/VirtualBox && my_files+=("/usr/bin/VirtualBox")
87test -f /usr/bin/VirtualBoxVM && my_files+=("/usr/bin/VirtualBoxVM")
88test -f /usr/bin/VBoxManage && my_files+=("/usr/bin/VBoxManage")
89test -f /usr/bin/VBoxVRDP && my_files+=("/usr/bin/VBoxVRDP")
90test -f /usr/bin/VBoxHeadless && my_files+=("/usr/bin/VBoxHeadless")
91test -f /usr/bin/vboxwebsrv && my_files+=("/usr/bin/vboxwebsrv")
92test -f /usr/bin/VBoxBugReport && my_files+=("/usr/bin/VBoxBugReport")
93test -f /usr/bin/VBoxBalloonCtrl && my_files+=("/usr/bin/VBoxBalloonCtrl")
94test -f /usr/bin/VBoxAutostart && my_files+=("/usr/bin/VBoxAutostart")
95test -f /usr/bin/VBoxDTrace && my_files+=("/usr/bin/VBoxDTrace")
96test -f /usr/bin/VBoxAudioTest && my_files+=("/usr/bin/VBoxAudioTest")
97test -f /usr/bin/vbox-img && my_files+=("/usr/bin/vbox-img")
98test -f /usr/local/bin/VirtualBox && my_files+=("/usr/local/bin/VirtualBox")
99test -f /usr/local/bin/VirtualBoxVM && my_files+=("/usr/local/bin/VirtualBoxVM")
100test -f /usr/local/bin/VBoxManage && my_files+=("/usr/local/bin/VBoxManage")
101test -f /usr/local/bin/VBoxVRDP && my_files+=("/usr/local/bin/VBoxVRDP")
102test -f /usr/local/bin/VBoxHeadless && my_files+=("/usr/local/bin/VBoxHeadless")
103test -f /usr/local/bin/vboxwebsrv && my_files+=("/usr/local/bin/vboxwebsrv")
104test -f /usr/local/bin/VBoxBugReport && my_files+=("/usr/local/bin/VBoxBugReport")
105test -f /usr/local/bin/VBoxBalloonCtrl && my_files+=("/usr/local/bin/VBoxBalloonCtrl")
106test -f /usr/local/bin/VBoxAutostart && my_files+=("/usr/local/bin/VBoxAutostart")
107test -f /usr/local/bin/VBoxDTrace && my_files+=("/usr/local/bin/VBoxDTrace")
108test -f /usr/local/bin/VBoxAudioTest && my_files+=("/usr/local/bin/VBoxAudioTest")
109test -f /usr/local/bin/vbox-img && my_files+=("/usr/local/bin/vbox-img")
110test -d /Library/Receipts/VirtualBoxCLI.pkg/ && my_directories+=("/Library/Receipts/VirtualBoxCLI.pkg/")
111test -f /Library/LaunchDaemons/org.virtualbox.startup.plist && my_files+=("/Library/LaunchDaemons/org.virtualbox.startup.plist")
112
113test -d /Applications/VirtualBox.app/ && my_directories+=("/Applications/VirtualBox.app/")
114test -d /Library/Receipts/VirtualBox.pkg/ && my_directories+=("/Library/Receipts/VirtualBox.pkg/")
115
116# legacy
117test -d /Library/Receipts/VBoxDrv.pkg/ && my_directories+=("/Library/Receipts/VBoxDrv.pkg/")
118test -d /Library/Receipts/VBoxUSB.pkg/ && my_directories+=("/Library/Receipts/VBoxUSB.pkg/")
119
120# python stuff
121python_versions="2.3 2.5 2.6 2.7"
122for 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/")
129done
130
131#
132# Collect KEXTs to remove.
133# Note that the unload order is significant.
134#
135declare -a my_kexts
136for 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
140done
141
142#
143# Collect packages to forget
144#
145my_pb='org\.virtualbox\.pkg\.'
146my_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#
151if 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;
155fi
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#
165my_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'`";
166if 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
183fi
184
185#
186# Display the files and directories that will be removed
187# and get the user's consent before continuing.
188#
189if 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 ""
194fi
195if 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 ""
199fi
200if 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 ""
204fi
205
206if 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 ""
214fi
215
216my_fuse_macos_core_uninstall=0
217if 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 ""
226fi
227
228#
229# Unregister has to be done before the files are removed.
230#
231LSREGISTER=/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
232if [ -e ${LSREGISTER} ]; then
233 ${LSREGISTER} -u /Applications/VirtualBox.app > /dev/null
234 ${LSREGISTER} -u /Applications/VirtualBox.app/Contents/Resources/vmstarter.app > /dev/null
235fi
236
237#
238# Display the sudo usage instructions and execute the command.
239#
240echo "The uninstallation processes requires administrative privileges"
241echo "because some of the installed files cannot be removed by a normal"
242echo "user. You may be prompted for your password now..."
243echo ""
244
245if 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
257fi
258
259if 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
262fi
263
264my_rc=0
265for 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
275done
276if test "$my_rc" -eq 0; then
277 echo "Successfully unloaded VirtualBox kernel extensions."
278else
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;
282fi
283
284# Cleaning up pkgutil database
285for 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"
287done
288
289echo "Done."
290exit 0;
291
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette