VirtualBox

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

最後變更 在這個檔案從47362是 46977,由 vboxsync 提交於 12 年 前

pkgutil doesn't forget receipt files.

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

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