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