VirtualBox_Uninstall.tool revision 66ab05d147fcb24a5fec1cd3c37a1799db26c804
20593760b116c90f3e439552763eef632a3bbb17vboxsync#!/bin/bash
20593760b116c90f3e439552763eef632a3bbb17vboxsync# $Id$
20593760b116c90f3e439552763eef632a3bbb17vboxsync## @file
20593760b116c90f3e439552763eef632a3bbb17vboxsync# VirtualBox Uninstaller Script.
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsync
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsync# Copyright (C) 2007-2013 Oracle Corporation
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
20593760b116c90f3e439552763eef632a3bbb17vboxsync# available from http://www.virtualbox.org. This file is free software;
20593760b116c90f3e439552763eef632a3bbb17vboxsync# you can redistribute it and/or modify it under the terms of the GNU
20593760b116c90f3e439552763eef632a3bbb17vboxsync# General Public License (GPL) as published by the Free Software
20593760b116c90f3e439552763eef632a3bbb17vboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
20593760b116c90f3e439552763eef632a3bbb17vboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
20593760b116c90f3e439552763eef632a3bbb17vboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsync
20593760b116c90f3e439552763eef632a3bbb17vboxsync# Override any funny stuff from the user.
20593760b116c90f3e439552763eef632a3bbb17vboxsyncexport PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"
20593760b116c90f3e439552763eef632a3bbb17vboxsync
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsync# Display a simple welcome message first.
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsyncecho ""
20593760b116c90f3e439552763eef632a3bbb17vboxsyncecho "Welcome to the VirtualBox uninstaller script."
20593760b116c90f3e439552763eef632a3bbb17vboxsyncecho ""
20593760b116c90f3e439552763eef632a3bbb17vboxsync
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsync# Check for arguments and display
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsyncmy_default_prompt=0
20593760b116c90f3e439552763eef632a3bbb17vboxsyncif test "$#" != "0"; then
20593760b116c90f3e439552763eef632a3bbb17vboxsync if test "$#" != "1" -o "$1" != "--unattended"; then
20593760b116c90f3e439552763eef632a3bbb17vboxsync echo "Error: Unknown argument(s): $*"
20593760b116c90f3e439552763eef632a3bbb17vboxsync echo ""
20593760b116c90f3e439552763eef632a3bbb17vboxsync echo "Usage: uninstall.sh [--unattended]"
20593760b116c90f3e439552763eef632a3bbb17vboxsync echo ""
20593760b116c90f3e439552763eef632a3bbb17vboxsync echo "If the '--unattended' option is not given, you will be prompted"
20593760b116c90f3e439552763eef632a3bbb17vboxsync echo "for a Yes/No before doing the actual uninstallation."
ea9fe8748652b3e7b3f1245001f9d7cd8c9eaaccvboxsync echo ""
20593760b116c90f3e439552763eef632a3bbb17vboxsync exit 4;
20593760b116c90f3e439552763eef632a3bbb17vboxsync fi
20593760b116c90f3e439552763eef632a3bbb17vboxsync my_default_prompt="Yes"
0c8eec6f5b79d800c3d25b5c0e0d7ad3f867c25cvboxsyncfi
0c8eec6f5b79d800c3d25b5c0e0d7ad3f867c25cvboxsync
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsync# Collect directories and files to remove.
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync# Note: Do NOT attempt adding directories or filenames with spaces!
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsyncdeclare -a my_directories
20593760b116c90f3e439552763eef632a3bbb17vboxsyncdeclare -a my_files
20593760b116c90f3e439552763eef632a3bbb17vboxsync
ea9fe8748652b3e7b3f1245001f9d7cd8c9eaaccvboxsync# Users files first
ea9fe8748652b3e7b3f1245001f9d7cd8c9eaaccvboxsynctest -f "${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist" && my_files+=("${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist")
20593760b116c90f3e439552763eef632a3bbb17vboxsync
ea9fe8748652b3e7b3f1245001f9d7cd8c9eaaccvboxsynctest -d /Library/StartupItems/VirtualBox/ && my_directories+=("/Library/StartupItems/VirtualBox/")
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -d /Library/Receipts/VBoxStartupItems.pkg/ && my_directories+=("/Library/Receipts/VBoxStartupItems.pkg/")
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -d "/Library/Application Support/VirtualBox/LaunchDaemons/" && my_directories+=("/Library/Application Support/VirtualBox/LaunchDaemons/")
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -d "/Library/Application Support/VirtualBox/VBoxDrv.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxDrv.kext/")
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -d "/Library/Application Support/VirtualBox/VBoxUSB.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxUSB.kext/")
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -d "/Library/Application Support/VirtualBox/VBoxNetFlt.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxNetFlt.kext/")
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -d "/Library/Application Support/VirtualBox/VBoxNetAdp.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxNetAdp.kext/")
20593760b116c90f3e439552763eef632a3bbb17vboxsync# Pre 4.3.0rc1 locations:
e86538a7bc028e823f16f8982e90f0c7ef5d4ecevboxsynctest -d /Library/Extensions/VBoxDrv.kext/ && my_directories+=("/Library/Extensions/VBoxDrv.kext/")
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -d /Library/Extensions/VBoxUSB.kext/ && my_directories+=("/Library/Extensions/VBoxUSB.kext/")
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -d /Library/Extensions/VBoxNetFlt.kext/ && my_directories+=("/Library/Extensions/VBoxNetFlt.kext/")
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -d /Library/Extensions/VBoxNetAdp.kext/ && my_directories+=("/Library/Extensions/VBoxNetAdp.kext/")
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync# Tiger support is obsolete, but we leave it here for a clean removing of older
20593760b116c90f3e439552763eef632a3bbb17vboxsync# VirtualBox versions
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -d /Library/Extensions/VBoxDrvTiger.kext/ && my_directories+=("/Library/Extensions/VBoxDrvTiger.kext/")
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -d /Library/Extensions/VBoxUSBTiger.kext/ && my_directories+=("/Library/Extensions/VBoxUSBTiger.kext/")
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -d /Library/Receipts/VBoxKEXTs.pkg/ && my_directories+=("/Library/Receipts/VBoxKEXTs.pkg/")
20593760b116c90f3e439552763eef632a3bbb17vboxsync
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -f /usr/bin/VirtualBox && my_files+=("/usr/bin/VirtualBox")
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsynctest -f /usr/bin/VBoxManage && my_files+=("/usr/bin/VBoxManage")
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -f /usr/bin/VBoxVRDP && my_files+=("/usr/bin/VBoxVRDP")
20593760b116c90f3e439552763eef632a3bbb17vboxsynctest -f /usr/bin/VBoxHeadless && my_files+=("/usr/bin/VBoxHeadless")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsynctest -f /usr/bin/vboxwebsrv && my_files+=("/usr/bin/vboxwebsrv")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsynctest -f /usr/bin/VBoxBalloonCtrl && my_files+=("/usr/bin/VBoxBalloonCtrl")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsynctest -f /usr/bin/VBoxAutostart && my_files+=("/usr/bin/VBoxAutostart")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsynctest -f /usr/bin/vbox-img && my_files+=("/usr/bin/vbox-img")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsynctest -d /Library/Receipts/VirtualBoxCLI.pkg/ && my_directories+=("/Library/Receipts/VirtualBoxCLI.pkg/")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsynctest -f /Library/LaunchDaemons/org.virtualbox.startup.plist && my_files+=("/Library/LaunchDaemons/org.virtualbox.startup.plist")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync
0f7b309cca2790ee47e71b5aa1817803b652f253vboxsynctest -d /Applications/VirtualBox.app/ && my_directories+=("/Applications/VirtualBox.app/")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsynctest -d /Library/Receipts/VirtualBox.pkg/ && my_directories+=("/Library/Receipts/VirtualBox.pkg/")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync# legacy
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsynctest -d /Library/Receipts/VBoxDrv.pkg/ && my_directories+=("/Library/Receipts/VBoxDrv.pkg/")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsynctest -d /Library/Receipts/VBoxUSB.pkg/ && my_directories+=("/Library/Receipts/VBoxUSB.pkg/")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync# python stuff
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsyncpython_versions="2.3 2.5 2.6 2.7"
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsyncfor p in $python_versions; do
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync test -f /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.py && my_files+=("/Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.py")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync test -f /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.pyc && my_files+=("/Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.pyc")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync test -f /Library/Python/$p/site-packages/vboxapi/__init__.py && my_files+=("/Library/Python/$p/site-packages/vboxapi/__init__.py")
e9525bea57dc13d82fd3392913aebb33d2cb79e3vboxsync test -f /Library/Python/$p/site-packages/vboxapi/__init__.pyc && my_files+=("/Library/Python/$p/site-packages/vboxapi/__init__.pyc")
20593760b116c90f3e439552763eef632a3bbb17vboxsync 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")
20593760b116c90f3e439552763eef632a3bbb17vboxsync test -d /Library/Python/$p/site-packages/vboxapi/ && my_directories+=("/Library/Python/$p/site-packages/vboxapi/")
20593760b116c90f3e439552763eef632a3bbb17vboxsyncdone
20593760b116c90f3e439552763eef632a3bbb17vboxsync
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync# Collect KEXTs to remove.
20593760b116c90f3e439552763eef632a3bbb17vboxsync# Note that the unload order is significant.
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsyncdeclare -a my_kexts
20593760b116c90f3e439552763eef632a3bbb17vboxsyncfor kext in org.virtualbox.kext.VBoxUSB org.virtualbox.kext.VBoxNetFlt org.virtualbox.kext.VBoxNetAdp org.virtualbox.kext.VBoxDrv; do
20593760b116c90f3e439552763eef632a3bbb17vboxsync if /usr/sbin/kextstat -b $kext -l | grep -q $kext; then
20593760b116c90f3e439552763eef632a3bbb17vboxsync my_kexts+=("$kext")
20593760b116c90f3e439552763eef632a3bbb17vboxsync fi
20593760b116c90f3e439552763eef632a3bbb17vboxsyncdone
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsync# Collect packages to forget
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsyncmy_pb='org\.virtualbox\.pkg\.'
20593760b116c90f3e439552763eef632a3bbb17vboxsyncmy_pkgs=`/usr/sbin/pkgutil --pkgs="${my_pb}vboxkexts|${my_pb}vboxstartupitems|${my_pb}virtualbox|${my_pb}virtualboxcli"`
20593760b116c90f3e439552763eef632a3bbb17vboxsync
20593760b116c90f3e439552763eef632a3bbb17vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsync# Did we find anything to uninstall?
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync#
20593760b116c90f3e439552763eef632a3bbb17vboxsyncif test -z "${my_directories[*]}" -a -z "${my_files[*]}" -a -z "${my_kexts[*]}" -a -z "$my_pkgs"; then
a18faae7b59910c9f2da2886ac10d7f31e29cd83vboxsync echo "No VirtualBox files, directories, KEXTs or packages to uninstall."
a18faae7b59910c9f2da2886ac10d7f31e29cd83vboxsync echo "Done."
a18faae7b59910c9f2da2886ac10d7f31e29cd83vboxsync exit 0;
a18faae7b59910c9f2da2886ac10d7f31e29cd83vboxsyncfi
a18faae7b59910c9f2da2886ac10d7f31e29cd83vboxsync
a18faae7b59910c9f2da2886ac10d7f31e29cd83vboxsync#
a18faae7b59910c9f2da2886ac10d7f31e29cd83vboxsync# 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|VBoxNetNAT)' | 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')".
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
echo ""
fi
if test -n "${my_kexts[*]}"; then
echo "And the following KEXTs will be unloaded:"
for kext in "${my_kexts[@]}"; do echo " $kext"; done
echo ""
fi
if test -n "$my_pkgs"; then
echo "And the traces of following packages will be removed:"
for kext in $my_pkgs; do echo " $kext"; done
echo ""
fi
if test "$my_default_prompt" != "Yes"; then
echo "Do you wish to uninstall VirtualBox (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')".
exit 2;
fi
echo ""
fi
#
# 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
#
# Display the sudo usage instructions and execute the command.
#
echo "The uninstallation processes requires administrative privileges"
echo "because some of the installed files cannot be removed by a normal"
echo "user. You may be prompted for your password now..."
echo ""
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 unloaded VirtualBox kernel extensions."
else
echo "Failed to unload one or more KEXTs, please reboot the machine to complete the uninstall."
exit 1;
fi
# Cleaning up pkgutil database
for my_pkg in $my_pkgs; do
/usr/bin/sudo -p "Please enter %u's password (removing $my_pkg):" /usr/sbin/pkgutil --forget "$my_pkg"
done
echo "Done."
exit 0;