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.
|
---|
17 | export PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"
|
---|
18 |
|
---|
19 | #
|
---|
20 | # Display a simple welcome message first.
|
---|
21 | #
|
---|
22 | echo ""
|
---|
23 | echo "Welcome to the VirtualBox uninstaller script."
|
---|
24 | echo ""
|
---|
25 |
|
---|
26 | #
|
---|
27 | # Check for arguments and display
|
---|
28 | #
|
---|
29 | my_default_prompt=0
|
---|
30 | if 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"
|
---|
42 | fi
|
---|
43 |
|
---|
44 | #
|
---|
45 | # Collect directories and files to remove.
|
---|
46 | # Note: Do NOT attempt adding directories or filenames with spaces!
|
---|
47 | #
|
---|
48 | my_directories=""
|
---|
49 | my_files=""
|
---|
50 |
|
---|
51 | # Users files first
|
---|
52 | test -f "${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist" && my_files="$my_files ${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist"
|
---|
53 |
|
---|
54 | test -d /Library/StartupItems/VirtualBox/ && my_directories="$my_directories /Library/StartupItems/VirtualBox/"
|
---|
55 | test -d /Library/Receipts/VBoxStartupItems.pkg/ && my_directories="$my_directories /Library/Receipts/VBoxStartupItems.pkg/"
|
---|
56 |
|
---|
57 | test -d /Library/Extensions/VBoxDrv.kext/ && my_directories="$my_directories /Library/Extensions/VBoxDrv.kext/"
|
---|
58 | test -d /Library/Extensions/VBoxUSB.kext/ && my_directories="$my_directories /Library/Extensions/VBoxUSB.kext/"
|
---|
59 | test -d /Library/Extensions/VBoxNetFlt.kext/ && my_directories="$my_directories /Library/Extensions/VBoxNetFlt.kext/"
|
---|
60 | test -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
|
---|
63 | test -d /Library/Extensions/VBoxDrvTiger.kext/ && my_directories="$my_directories /Library/Extensions/VBoxDrvTiger.kext/"
|
---|
64 | test -d /Library/Extensions/VBoxUSBTiger.kext/ && my_directories="$my_directories /Library/Extensions/VBoxUSBTiger.kext/"
|
---|
65 | test -d /Library/Receipts/VBoxKEXTs.pkg/ && my_directories="$my_directories /Library/Receipts/VBoxKEXTs.pkg/"
|
---|
66 |
|
---|
67 | test -f /usr/bin/VirtualBox && my_files="$my_files /usr/bin/VirtualBox"
|
---|
68 | test -f /usr/bin/VBoxManage && my_files="$my_files /usr/bin/VBoxManage"
|
---|
69 | test -f /usr/bin/VBoxVRDP && my_files="$my_files /usr/bin/VBoxVRDP"
|
---|
70 | test -f /usr/bin/VBoxHeadless && my_files="$my_files /usr/bin/VBoxHeadless"
|
---|
71 | test -f /usr/bin/vboxwebsrv && my_files="$my_files /usr/bin/vboxwebsrv"
|
---|
72 | test -f /usr/bin/VBoxBalloonCtrl && my_files="$my_files /usr/bin/VBoxBalloonCtrl"
|
---|
73 | test -f /usr/bin/VBoxAutostart && my_files="$my_files /usr/bin/VBoxAutostart"
|
---|
74 | test -f /usr/bin/vbox-img && my_files="$my_files /usr/bin/vbox-img"
|
---|
75 | test -d /Library/Receipts/VirtualBoxCLI.pkg/ && my_directories="$my_directories /Library/Receipts/VirtualBoxCLI.pkg/"
|
---|
76 |
|
---|
77 | test -d /Applications/VirtualBox.app/ && my_directories="$my_directories /Applications/VirtualBox.app/"
|
---|
78 | test -d /Library/Receipts/VirtualBox.pkg/ && my_directories="$my_directories /Library/Receipts/VirtualBox.pkg/"
|
---|
79 |
|
---|
80 | # legacy
|
---|
81 | test -d /Library/Receipts/VBoxDrv.pkg/ && my_directories="$my_directories /Library/Receipts/VBoxDrv.pkg/"
|
---|
82 | test -d /Library/Receipts/VBoxUSB.pkg/ && my_directories="$my_directories /Library/Receipts/VBoxUSB.pkg/"
|
---|
83 |
|
---|
84 | # python stuff
|
---|
85 | python_versions="2.3 2.5 2.6 2.7"
|
---|
86 | for 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/"
|
---|
93 | done
|
---|
94 |
|
---|
95 | #
|
---|
96 | # Collect KEXTs to remove.
|
---|
97 | # Note that the unload order is significant.
|
---|
98 | #
|
---|
99 | my_kexts=""
|
---|
100 | for 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
|
---|
104 | done
|
---|
105 |
|
---|
106 | #
|
---|
107 | # Did we find anything to uninstall?
|
---|
108 | #
|
---|
109 | if test -z "$my_directories" -a -z "$my_files" -a -z "$my_kexts"; then
|
---|
110 | echo "No VirtualBox files, directories or KEXTs to uninstall."
|
---|
111 | echo "Done."
|
---|
112 | exit 0;
|
---|
113 | fi
|
---|
114 |
|
---|
115 | #
|
---|
116 | # Look for running VirtualBox processes and warn the user
|
---|
117 | # if something is running. Since deleting the files of
|
---|
118 | # running processes isn't fatal as such, we will leave it
|
---|
119 | # to the user to choose whether to continue or not.
|
---|
120 | #
|
---|
121 | # Note! comm isn't supported on Tiger, so we make -c to do the stripping.
|
---|
122 | #
|
---|
123 | my_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'`";
|
---|
124 | if test -n "$my_processes"; then
|
---|
125 | echo 'Warning! Found the following active VirtualBox processes:'
|
---|
126 | echo "$my_processes" | tr '\a' '\n'
|
---|
127 | echo ""
|
---|
128 | echo "We recommend that you quit all VirtualBox processes before"
|
---|
129 | echo "uninstalling the product."
|
---|
130 | echo ""
|
---|
131 | if test "$my_default_prompt" != "Yes"; then
|
---|
132 | echo "Do you wish to continue none the less (Yes/No)?"
|
---|
133 | read my_answer
|
---|
134 | if test "$my_answer" != "Yes" -a "$my_answer" != "YES" -a "$my_answer" != "yes"; then
|
---|
135 | echo "Aborting uninstall. (answer: '$my_answer')".
|
---|
136 | exit 2;
|
---|
137 | fi
|
---|
138 | echo ""
|
---|
139 | my_answer=""
|
---|
140 | fi
|
---|
141 | fi
|
---|
142 |
|
---|
143 | #
|
---|
144 | # Display the files and directories that will be removed
|
---|
145 | # and get the user's consent before continuing.
|
---|
146 | #
|
---|
147 | if test -n "$my_files" -o -n "$my_directories"; then
|
---|
148 | echo "The following files and directories (bundles) will be removed:"
|
---|
149 | for file in $my_files; do echo " $file"; done
|
---|
150 | for dir in $my_directories; do echo " $dir"; done
|
---|
151 | fi
|
---|
152 | if test -n "$my_kexts"; then
|
---|
153 | echo "And the following KEXTs will be unloaded:"
|
---|
154 | for kext in $my_kexts; do echo " $kext"; done
|
---|
155 | fi
|
---|
156 | echo ""
|
---|
157 |
|
---|
158 | if test "$my_default_prompt" != "Yes"; then
|
---|
159 | echo "Do you wish to uninstall VirtualBox (Yes/No)?"
|
---|
160 | read my_answer
|
---|
161 | if test "$my_answer" != "Yes" -a "$my_answer" != "YES" -a "$my_answer" != "yes"; then
|
---|
162 | echo "Aborting uninstall. (answer: '$my_answer')".
|
---|
163 | exit 2;
|
---|
164 | fi
|
---|
165 | echo ""
|
---|
166 | fi
|
---|
167 |
|
---|
168 | #
|
---|
169 | # Unregister has to be done before the files are removed.
|
---|
170 | #
|
---|
171 | LSREGISTER=/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
|
---|
172 | if [ -e ${LSREGISTER} ]; then
|
---|
173 | ${LSREGISTER} -u /Applications/VirtualBox.app > /dev/null
|
---|
174 | ${LSREGISTER} -u /Applications/VirtualBox.app/Contents/Resources/vmstarter.app > /dev/null
|
---|
175 | fi
|
---|
176 |
|
---|
177 | #
|
---|
178 | # Display the sudo usage instructions and execute the command.
|
---|
179 | #
|
---|
180 | echo "The uninstallation processes requires administrative privileges"
|
---|
181 | echo "because some of the installed files cannot be removed by a normal"
|
---|
182 | echo "user. You may be prompted for your password now..."
|
---|
183 | echo ""
|
---|
184 |
|
---|
185 | if test -n "$my_files" -o -n "$my_directories"; then
|
---|
186 | /usr/bin/sudo -p "Please enter %u's password:" /bin/rm -Rf $my_files $my_directories
|
---|
187 | my_rc=$?
|
---|
188 | if test "$my_rc" -ne 0; then
|
---|
189 | echo "An error occurred durning 'sudo rm', there should be a message above. (rc=$my_rc)"
|
---|
190 | test -x /usr/bin/sudo || echo "warning: Cannot find /usr/bin/sudo or it's not an executable."
|
---|
191 | test -x /bin/rm || echo "warning: Cannot find /bin/rm or it's not an executable"
|
---|
192 | echo ""
|
---|
193 | echo "The uninstall failed. Please retry."
|
---|
194 | exit 1;
|
---|
195 | fi
|
---|
196 | fi
|
---|
197 |
|
---|
198 | my_rc=0
|
---|
199 | for kext in $my_kexts; do
|
---|
200 | echo unloading $kext
|
---|
201 | /usr/bin/sudo -p "Please enter %u's password (unloading $kext):" /sbin/kextunload -m $kext
|
---|
202 | my_rc2=$?
|
---|
203 | if test "$my_rc2" -ne 0; then
|
---|
204 | echo "An error occurred durning 'sudo /sbin/kextunload -m $kext', there should be a message above. (rc=$my_rc2)"
|
---|
205 | test -x /usr/bin/sudo || echo "warning: Cannot find /usr/bin/sudo or it's not an executable."
|
---|
206 | test -x /sbin/kextunload || echo "warning: Cannot find /sbin/kextunload or it's not an executable"
|
---|
207 | my_rc=$my_rc2
|
---|
208 | fi
|
---|
209 | done
|
---|
210 | if test "$my_rc" -eq 0; then
|
---|
211 | echo "Successfully uninstalled VirtualBox."
|
---|
212 | else
|
---|
213 | echo "Failed to unload on or more KEXTs, please reboot the machine to complete the uninstall."
|
---|
214 | fi
|
---|
215 | echo "Done."
|
---|
216 | exit 0;
|
---|
217 |
|
---|