forked from kalamuna/kalaboxv1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUninstall.tool
executable file
·328 lines (289 loc) · 13.6 KB
/
Uninstall.tool
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/bin/sh
#
# Kalabox Uninstaller Script.
#
# Copyright (C) 2012-2013 Kalamuna LLC
#
# This file also contains modified Vagrant and VirtualBox uninstallers.
#
#
# Override any funny stuff from the user.
export PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"
## @param [Integer] $1 exit code.
function key_exit() {
echo "Press enter to exit."
read
exit $1
}
# Appends a value to an array.
#
# @param [String] $1 Name of the variable to modify
# @param [String] $2 Value to append
function append() {
eval $1[\${#$1[*]}]=$2
}
##
# Display some important knowledge first
#
echo ""
echo "Welcome to the Kalabox uninstaller script."
echo ""
echo "This script will destroy your current Kalabox build. If you want"
echo "to save your current build for later please either vagrant package"
echo "your existing build or export the relevant VirtualBox appliance."
echo ""
echo "MAKE SURE THAT YOU'VE EXITED THE KALABOX APP OR THIS WILL BLOW UP!!!"
echo ""
echo "WHAT YOU WANT TO DO?"
echo ""
echo "1. Remove Kalabox code."
echo "2. Remove Kalabox code AND uninstall VirtualBox and Vagrant. (WARNING: This will delete EVERYTHING except your shared folders)"
echo "3. Forget this ever happened."
echo ""
read my_answer
if [ "$my_answer" == "3" ]; then
echo "This never happened."
key_exit 2
fi
# Initiate the actual uninstall, which requires admin privileges.
echo "The uninstallation process requires administrative privileges"
echo "because some of the installed files cannot be removed by a"
echo "normal user. You may now be prompted for a password..."
# Just start the sudo party
/usr/bin/sudo -p "Please enter %u's password:" echo "Let's get it started"
kala_files=()
append kala_files "/Applications/Kalabox.app"
append kala_files "~/.kalabox/kalastack"
# Actually delete Kalabox vagrant build and associated files
if [ -e $HOME/.kalabox/kalastack/.kalabox/uuid ]; then
cd $HOME/.kalabox/kalastack
/usr/bin/vagrant halt -f
/usr/bin/vagrant destroy -f
sleep 10s
fi
/bin/rm -rf $HOME/.kalabox/kalastack
/bin/rm -rf $HOME/.kalabox/kalastack.tar.gz
/bin/rm $HOME/.kalabox/kalabox.log
/bin/rm -rf $TMPDIR/*vagrant*
/bin/rm -rf $TMPDIR/*virtualbox*
# Delete the Kalabox application
/usr/bin/sudo -p "Please enter %u's password:" /bin/rm -Rf /Applications/Kalabox.app
# Remove Pantheon auth keychain
security delete-generic-password -s KalaboxPantheonAuth
# Print the files and directories that are to be removed and verify
# with the user that that is what he/she really wants to do.
echo "The following files and directories will be removed:"
for file in "${kala_files[@]}"; do
echo " $file"
done
#!/usr/bin/env bash
if [ "$my_answer" == "2" ]; then
#----------------------------------------------------------------------
# Vagrant Uninstall Script
#----------------------------------------------------------------------
# Collect the directories and files to remove
#
echo ""
echo "Preparing to uninstall vagrant."
echo ""
my_files=()
append my_files "/Applications/Vagrant"
append my_files "/usr/bin/vagrant"
append my_files "$HOME/.vagrant.d"
# Print the files and directories that are to be removed and verify
# with the user that that is what he/she really wants to do.
echo "The following files and directories will be removed:"
for file in "${my_files[@]}"; do
echo " $file"
done
# Actually delete Vagrant and remove plugins
/usr/bin/vagrant plugin uninstall vagrant-hostsupdater
/bin/rm -rf $HOME/.vagrant.d
/usr/bin/sudo -p "Please enter %u's password:" /bin/rm -rf /Applications/Vagrant
/usr/bin/sudo -p "Please enter %u's password:" /bin/rm -Rf /usr/bin/vagrant
# Verify that the uninstall succeeded by checking whether every file
# we meant to remove is actually removed.
for file in "${my_files[@]}"; do
if [ -e "${file}" ]; then
echo "An error must have occurred since a file that was supposed to be"
echo "removed still exists: ${file}"
echo ""
echo "Please try again."
key_exit 1
fi
done
echo "Successfully uninstalled Vagrant."
#!/bin/sh
#
# VirtualBox Uninstaller Script.
#
# Copyright (C) 2007-2010 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#
#
# Display a simple welcome message first.
#
echo ""
echo "Preparing to uninstall VirtualBox"
echo ""
#
# Collect directories and files to remove.
# Note: Do NOT attempt adding directories or filenames with spaces!
#
my_directories=""
my_files=""
# Users files first
test -f "${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist" && my_files="$my_files ${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist"
test -d /Library/StartupItems/VirtualBox/ && my_directories="$my_directories /Library/StartupItems/VirtualBox/"
test -d /Library/Receipts/VBoxStartupItems.pkg/ && my_directories="$my_directories /Library/Receipts/VBoxStartupItems.pkg/"
test -d /Library/Extensions/VBoxDrv.kext/ && my_directories="$my_directories /Library/Extensions/VBoxDrv.kext/"
test -d /Library/Extensions/VBoxUSB.kext/ && my_directories="$my_directories /Library/Extensions/VBoxUSB.kext/"
test -d /Library/Extensions/VBoxNetFlt.kext/ && my_directories="$my_directories /Library/Extensions/VBoxNetFlt.kext/"
test -d /Library/Extensions/VBoxNetAdp.kext/ && my_directories="$my_directories /Library/Extensions/VBoxNetAdp.kext/"
# Tiger support is obsolete, but we leave it here for a clean removing of older
# VirtualBox versions
test -d /Library/Extensions/VBoxDrvTiger.kext/ && my_directories="$my_directories /Library/Extensions/VBoxDrvTiger.kext/"
test -d /Library/Extensions/VBoxUSBTiger.kext/ && my_directories="$my_directories /Library/Extensions/VBoxUSBTiger.kext/"
test -d /Library/Receipts/VBoxKEXTs.pkg/ && my_directories="$my_directories /Library/Receipts/VBoxKEXTs.pkg/"
test -f /usr/bin/VirtualBox && my_files="$my_files /usr/bin/VirtualBox"
test -f /usr/bin/VBoxManage && my_files="$my_files /usr/bin/VBoxManage"
test -f /usr/bin/VBoxVRDP && my_files="$my_files /usr/bin/VBoxVRDP"
test -f /usr/bin/VBoxHeadless && my_files="$my_files /usr/bin/VBoxHeadless"
test -f /usr/bin/vboxwebsrv && my_files="$my_files /usr/bin/vboxwebsrv"
test -f /usr/bin/VBoxBalloonCtrl && my_files="$my_files /usr/bin/VBoxBalloonCtrl"
test -f /usr/bin/VBoxAutostart && my_files="$my_files /usr/bin/VBoxAutostart"
test -f /usr/bin/vbox-img && my_files="$my_files /usr/bin/vbox-img"
test -d /Library/Receipts/VirtualBoxCLI.pkg/ && my_directories="$my_directories /Library/Receipts/VirtualBoxCLI.pkg/"
test -d /Applications/VirtualBox.app/ && my_directories="$my_directories /Applications/VirtualBox.app/"
test -d /Library/Receipts/VirtualBox.pkg/ && my_directories="$my_directories /Library/Receipts/VirtualBox.pkg/"
# legacy
test -d /Library/Receipts/VBoxDrv.pkg/ && my_directories="$my_directories /Library/Receipts/VBoxDrv.pkg/"
test -d /Library/Receipts/VBoxUSB.pkg/ && my_directories="$my_directories /Library/Receipts/VBoxUSB.pkg/"
# python stuff
python_versions="2.3 2.5 2.6 2.7"
for p in $python_versions; do
test -f /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.py && my_files="$my_files /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.py"
test -f /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.pyc && my_files="$my_files /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.pyc"
test -f /Library/Python/$p/site-packages/vboxapi/__init__.py && my_files="$my_files /Library/Python/$p/site-packages/vboxapi/__init__.py"
test -f /Library/Python/$p/site-packages/vboxapi/__init__.pyc && my_files="$my_files /Library/Python/$p/site-packages/vboxapi/__init__.pyc"
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"
test -d /Library/Python/$p/site-packages/vboxapi/ && my_directories="$my_directories /Library/Python/$p/site-packages/vboxapi/"
done
#
# Collect KEXTs to remove.
# Note that the unload order is significant.
#
my_kexts=""
for kext in org.virtualbox.kext.VBoxUSB org.virtualbox.kext.VBoxNetFlt org.virtualbox.kext.VBoxNetAdp org.virtualbox.kext.VBoxDrv; do
if /usr/sbin/kextstat -b $kext -l | grep -q $kext; then
my_kexts="$my_kexts $kext"
fi
done
#
# Did we find anything to uninstall?
#
if test -z "$my_directories" -a -z "$my_files" -a -z "$my_kexts"; then
echo "No VirtualBox files, directories or KEXTs to uninstall."
echo "Done."
key_exit 0;
fi
#
# Look for running VirtualBox processes and warn the user
# if something is running. Since deleting the files of
# running processes isn't fatal as such, we will leave it
# to the user to choose whether to continue or not.
#
# Note! comm isn't supported on Tiger, so we make -c to do the stripping.
#
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'`";
if test -n "$my_processes"; then
echo 'Warning! Found the following active VirtualBox processes:'
echo "$my_processes" | tr '\a' '\n'
echo ""
echo "We recommend that you quit all VirtualBox processes before"
echo "uninstalling the product."
echo ""
if test "$my_default_prompt" != "Yes"; then
echo "Do you wish to continue none the less (Yes/No)?"
read my_answer
if test "$my_answer" != "Yes" -a "$my_answer" != "YES" -a "$my_answer" != "yes"; then
echo "Aborting uninstall. (answer: '$my_answer')".
key_exit 2;
fi
echo ""
my_answer=""
fi
fi
#
# Display the files and directories that will be removed
# and get the user's consent before continuing.
#
if test -n "$my_files" -o -n "$my_directories"; then
echo "The following files and directories (bundles) will be removed:"
for file in $my_files; do echo " $file"; done
for dir in $my_directories; do echo " $dir"; done
fi
if test -n "$my_kexts"; then
echo "And the following KEXTs will be unloaded:"
for kext in $my_kexts; do echo " $kext"; done
fi
echo ""
#
# Unregister has to be done before the files are removed.
#
LSREGISTER=/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
if [ -e ${LSREGISTER} ]; then
${LSREGISTER} -u /Applications/VirtualBox.app > /dev/null
${LSREGISTER} -u /Applications/VirtualBox.app/Contents/Resources/vmstarter.app > /dev/null
fi
if test -n "$my_files" -o -n "$my_directories"; then
/usr/bin/sudo -p "Please enter %u's password:" /bin/rm -Rf $my_files $my_directories
my_rc=$?
if test "$my_rc" -ne 0; then
echo "An error occurred durning 'sudo rm', there should be a message above. (rc=$my_rc)"
test -x /usr/bin/sudo || echo "warning: Cannot find /usr/bin/sudo or it's not an executable."
test -x /bin/rm || echo "warning: Cannot find /bin/rm or it's not an executable"
echo ""
echo "The uninstall failed. Please retry."
exit 1;
fi
fi
my_rc=0
for kext in $my_kexts; do
echo unloading $kext
/usr/bin/sudo -p "Please enter %u's password (unloading $kext):" /sbin/kextunload -m $kext
my_rc2=$?
if test "$my_rc2" -ne 0; then
echo "An error occurred durning 'sudo /sbin/kextunload -m $kext', there should be a message above. (rc=$my_rc2)"
test -x /usr/bin/sudo || echo "warning: Cannot find /usr/bin/sudo or it's not an executable."
test -x /sbin/kextunload || echo "warning: Cannot find /sbin/kextunload or it's not an executable"
my_rc=$my_rc2
fi
done
if test "$my_rc" -eq 0; then
echo "Successfully uninstalled VirtualBox."
else
echo "Failed to unload on or more KEXTs, please reboot the machine to complete the uninstall."
fi
fi
if [ "$my_answer" != "3" ]; then
echo ""
echo "Do you want to remove the Kalabox VirtualBox image? This won’t impact anything on your system, but may make future Kalabox installs take longer. (y/n)"
read remove_kalabox64
if [ "$remove_kalabox64" == "y" ]; then
echo ""
echo "Preparing to remove kalabox64.box"
echo ""
/bin/rm -rf $HOME/.kalabox/kalabox64.box
echo "Successfully removed kalabox64.box."
fi
fi
echo "Done."
key_exit 0;