VirtualBox

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

最後變更 在這個檔案從96313是 93115,由 vboxsync 提交於 3 年 前

scm --update-copyright-year

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

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