VirtualBox

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

Last change on this file since 46974 was 46974, checked in by vboxsync, 12 years ago

Don't forget packages related to GAs or anything from the future. Use pkgutil built in regex package selector instead of grep. Collect and display packages in the same way we collect files, directories and kernel extensions, showing them prior to the uninstall question.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 KB
Line 
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.virtualbox.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/"
55
56test -d /Library/Extensions/VBoxDrv.kext/ && my_directories="$my_directories /Library/Extensions/VBoxDrv.kext/"
57test -d /Library/Extensions/VBoxUSB.kext/ && my_directories="$my_directories /Library/Extensions/VBoxUSB.kext/"
58test -d /Library/Extensions/VBoxNetFlt.kext/ && my_directories="$my_directories /Library/Extensions/VBoxNetFlt.kext/"
59test -d /Library/Extensions/VBoxNetAdp.kext/ && my_directories="$my_directories /Library/Extensions/VBoxNetAdp.kext/"
60# Tiger support is obsolete, but we leave it here for a clean removing of older
61# VirtualBox versions
62test -d /Library/Extensions/VBoxDrvTiger.kext/ && my_directories="$my_directories /Library/Extensions/VBoxDrvTiger.kext/"
63test -d /Library/Extensions/VBoxUSBTiger.kext/ && my_directories="$my_directories /Library/Extensions/VBoxUSBTiger.kext/"
64
65test -f /usr/bin/VirtualBox && my_files="$my_files /usr/bin/VirtualBox"
66test -f /usr/bin/VBoxManage && my_files="$my_files /usr/bin/VBoxManage"
67test -f /usr/bin/VBoxVRDP && my_files="$my_files /usr/bin/VBoxVRDP"
68test -f /usr/bin/VBoxHeadless && my_files="$my_files /usr/bin/VBoxHeadless"
69test -f /usr/bin/vboxwebsrv && my_files="$my_files /usr/bin/vboxwebsrv"
70test -f /usr/bin/VBoxBalloonCtrl && my_files="$my_files /usr/bin/VBoxBalloonCtrl"
71test -f /usr/bin/VBoxAutostart && my_files="$my_files /usr/bin/VBoxAutostart"
72test -f /usr/bin/vbox-img && my_files="$my_files /usr/bin/vbox-img"
73
74test -d /Applications/VirtualBox.app/ && my_directories="$my_directories /Applications/VirtualBox.app/"
75
76# python stuff
77python_versions="2.3 2.5 2.6 2.7"
78for p in $python_versions; do
79 test -f /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.py && my_files="$my_files /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.py"
80 test -f /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.pyc && my_files="$my_files /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.pyc"
81 test -f /Library/Python/$p/site-packages/vboxapi/__init__.py && my_files="$my_files /Library/Python/$p/site-packages/vboxapi/__init__.py"
82 test -f /Library/Python/$p/site-packages/vboxapi/__init__.pyc && my_files="$my_files /Library/Python/$p/site-packages/vboxapi/__init__.pyc"
83 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"
84 test -d /Library/Python/$p/site-packages/vboxapi/ && my_directories="$my_directories /Library/Python/$p/site-packages/vboxapi/"
85done
86
87#
88# Collect KEXTs to remove.
89# Note that the unload order is significant.
90#
91my_kexts=""
92for kext in org.virtualbox.kext.VBoxUSB org.virtualbox.kext.VBoxNetFlt org.virtualbox.kext.VBoxNetAdp org.virtualbox.kext.VBoxDrv; do
93 if /usr/sbin/kextstat -b $kext -l | grep -q $kext; then
94 my_kexts="$my_kexts $kext"
95 fi
96done
97
98#
99# Collect packages to forget
100#
101my_pb='org\.virtualbox\.pkg\.'
102my_pkgs=`/usr/sbin/pkgutil --pkgs="${my_pb}vboxkexts|${my_pb}vboxstartupitems|${my_pb}virtualbox|${my_pb}virtualboxcli"`
103
104#
105# Did we find anything to uninstall?
106#
107if test -z "$my_directories" -a -z "$my_files" -a -z "$my_kexts" -a -z "$my_pkgs"; then
108 echo "No VirtualBox files, directories, KEXTs or packages to uninstall."
109 echo "Done."
110 exit 0;
111fi
112
113#
114# Look for running VirtualBox processes and warn the user
115# if something is running. Since deleting the files of
116# running processes isn't fatal as such, we will leave it
117# to the user to choose whether to continue or not.
118#
119# Note! comm isn't supported on Tiger, so we make -c to do the stripping.
120#
121my_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'`";
122if test -n "$my_processes"; then
123 echo 'Warning! Found the following active VirtualBox processes:'
124 echo "$my_processes" | tr '\a' '\n'
125 echo ""
126 echo "We recommend that you quit all VirtualBox processes before"
127 echo "uninstalling the product."
128 echo ""
129 if test "$my_default_prompt" != "Yes"; then
130 echo "Do you wish to continue none the less (Yes/No)?"
131 read my_answer
132 if test "$my_answer" != "Yes" -a "$my_answer" != "YES" -a "$my_answer" != "yes"; then
133 echo "Aborting uninstall. (answer: '$my_answer')".
134 exit 2;
135 fi
136 echo ""
137 my_answer=""
138 fi
139fi
140
141#
142# Display the files and directories that will be removed
143# and get the user's consent before continuing.
144#
145if test -n "$my_files" -o -n "$my_directories"; then
146 echo "The following files and directories (bundles) will be removed:"
147 for file in $my_files; do echo " $file"; done
148 for dir in $my_directories; do echo " $dir"; done
149fi
150if test -n "$my_kexts"; then
151 echo "And the following KEXTs will be unloaded:"
152 for kext in $my_kexts; do echo " $kext"; done
153fi
154if test -n "$my_pkgs"; then
155 echo "And the traces of following packages will be removed:"
156 for kext in $my_pkgs; do echo " $kext"; done
157fi
158echo ""
159
160if test "$my_default_prompt" != "Yes"; then
161 echo "Do you wish to uninstall VirtualBox (Yes/No)?"
162 read my_answer
163 if test "$my_answer" != "Yes" -a "$my_answer" != "YES" -a "$my_answer" != "yes"; then
164 echo "Aborting uninstall. (answer: '$my_answer')".
165 exit 2;
166 fi
167 echo ""
168fi
169
170#
171# Unregister has to be done before the files are removed.
172#
173LSREGISTER=/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
174if [ -e ${LSREGISTER} ]; then
175 ${LSREGISTER} -u /Applications/VirtualBox.app > /dev/null
176 ${LSREGISTER} -u /Applications/VirtualBox.app/Contents/Resources/vmstarter.app > /dev/null
177fi
178
179#
180# Display the sudo usage instructions and execute the command.
181#
182echo "The uninstallation processes requires administrative privileges"
183echo "because some of the installed files cannot be removed by a normal"
184echo "user. You may be prompted for your password now..."
185echo ""
186
187if test -n "$my_files" -o -n "$my_directories"; then
188 /usr/bin/sudo -p "Please enter %u's password:" /bin/rm -Rf $my_files $my_directories
189 my_rc=$?
190 if test "$my_rc" -ne 0; then
191 echo "An error occurred durning 'sudo rm', there should be a message above. (rc=$my_rc)"
192 test -x /usr/bin/sudo || echo "warning: Cannot find /usr/bin/sudo or it's not an executable."
193 test -x /bin/rm || echo "warning: Cannot find /bin/rm or it's not an executable"
194 echo ""
195 echo "The uninstall failed. Please retry."
196 exit 1;
197 fi
198fi
199
200my_rc=0
201for kext in $my_kexts; do
202 echo unloading $kext
203 /usr/bin/sudo -p "Please enter %u's password (unloading $kext):" /sbin/kextunload -m $kext
204 my_rc2=$?
205 if test "$my_rc2" -ne 0; then
206 echo "An error occurred durning 'sudo /sbin/kextunload -m $kext', there should be a message above. (rc=$my_rc2)"
207 test -x /usr/bin/sudo || echo "warning: Cannot find /usr/bin/sudo or it's not an executable."
208 test -x /sbin/kextunload || echo "warning: Cannot find /sbin/kextunload or it's not an executable"
209 my_rc=$my_rc2
210 fi
211done
212if test "$my_rc" -eq 0; then
213 echo "Successfully unloaded VirtualBox kernel extensions."
214else
215 echo "Failed to unload one or more KEXTs, please reboot the machine to complete the uninstall."
216 exit 1;
217fi
218
219# Cleaning up pkgutil database
220for my_pkg in $my_pkgs; do
221 /usr/bin/sudo -p "Please enter %u's password (removing $my_pkg):" /usr/sbin/pkgutil --forget "$my_pkg"
222done
223
224echo "Done."
225exit 0;
226
Note: See TracBrowser for help on using the repository browser.

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