VirtualBox

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

Last change on this file since 31807 was 31673, checked in by vboxsync, 14 years ago

Installer-OSX: change headers

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