VirtualBox Mac版官方卸載代碼

VirtualBox Version 5.2.6 r120293 (Qt5.6.3)

#!/bin/bash
# $Id: VirtualBox_Uninstall.tool 118839 2017-10-28 15:14:05Z bird $
## @file
# VirtualBox Uninstaller Script.
#

#
# Copyright (C) 2007-2017 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.
#

# Override any funny stuff from the user.
export PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"

#
# Display a simple welcome message first.
#
echo ""
echo "Welcome to the VirtualBox uninstaller script."
echo ""

#
# Check for arguments and display
#
my_default_prompt=0
if test "$#" != "0"; then
    if test "$#" != "1" -o "$1" != "--unattended"; then
        echo "Error: Unknown argument(s): $*"
        echo ""
        echo "Usage: uninstall.sh [--unattended]"
        echo ""
        echo "If the '--unattended' option is not given, you will be prompted"
        echo "for a Yes/No before doing the actual uninstallation."
        echo ""
        exit 4;
    fi
    my_default_prompt="Yes"
fi

#
# Collect directories and files to remove.
# Note: Do NOT attempt adding directories or filenames with spaces!
#
declare -a my_directories
declare -a my_files

# Users files first
test -f "${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist"  && my_files+=("${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist")

test -d /Library/StartupItems/VirtualBox/          && my_directories+=("/Library/StartupItems/VirtualBox/")
test -d /Library/Receipts/VBoxStartupItems.pkg/    && my_directories+=("/Library/Receipts/VBoxStartupItems.pkg/")

test -d "/Library/Application Support/VirtualBox/LaunchDaemons/"    && my_directories+=("/Library/Application Support/VirtualBox/LaunchDaemons/")
test -d "/Library/Application Support/VirtualBox/VBoxDrv.kext/"     && my_directories+=("/Library/Application Support/VirtualBox/VBoxDrv.kext/")
test -d "/Library/Application Support/VirtualBox/VBoxUSB.kext/"     && my_directories+=("/Library/Application Support/VirtualBox/VBoxUSB.kext/")
test -d "/Library/Application Support/VirtualBox/VBoxNetFlt.kext/"  && my_directories+=("/Library/Application Support/VirtualBox/VBoxNetFlt.kext/")
test -d "/Library/Application Support/VirtualBox/VBoxNetAdp.kext/"  && my_directories+=("/Library/Application Support/VirtualBox/VBoxNetAdp.kext/")
# Pre 4.3.0rc1 locations:
test -d /Library/Extensions/VBoxDrv.kext/          && my_directories+=("/Library/Extensions/VBoxDrv.kext/")
test -d /Library/Extensions/VBoxUSB.kext/          && my_directories+=("/Library/Extensions/VBoxUSB.kext/")
test -d /Library/Extensions/VBoxNetFlt.kext/       && my_directories+=("/Library/Extensions/VBoxNetFlt.kext/")
test -d /Library/Extensions/VBoxNetAdp.kext/       && 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+=("/Library/Extensions/VBoxDrvTiger.kext/")
test -d /Library/Extensions/VBoxUSBTiger.kext/     && my_directories+=("/Library/Extensions/VBoxUSBTiger.kext/")
test -d /Library/Receipts/VBoxKEXTs.pkg/           && my_directories+=("/Library/Receipts/VBoxKEXTs.pkg/")

test -f /usr/bin/VirtualBox                        && my_files+=("/usr/bin/VirtualBox")
test -f /usr/bin/VBoxManage                        && my_files+=("/usr/bin/VBoxManage")
test -f /usr/bin/VBoxVRDP                          && my_files+=("/usr/bin/VBoxVRDP")
test -f /usr/bin/VBoxHeadless                      && my_files+=("/usr/bin/VBoxHeadless")
test -f /usr/bin/vboxwebsrv                        && my_files+=("/usr/bin/vboxwebsrv")
test -f /usr/bin/VBoxBugReport                     && my_files+=("/usr/bin/VBoxBugReport")
test -f /usr/bin/VBoxBalloonCtrl                   && my_files+=("/usr/bin/VBoxBalloonCtrl")
test -f /usr/bin/VBoxAutostart                     && my_files+=("/usr/bin/VBoxAutostart")
test -f /usr/bin/VBoxDTrace                        && my_files+=("/usr/bin/VBoxDTrace")
test -f /usr/bin/vbox-img                          && my_files+=("/usr/bin/vbox-img")
test -f /usr/local/bin/VirtualBox                  && my_files+=("/usr/local/bin/VirtualBox")
test -f /usr/local/bin/VBoxManage                  && my_files+=("/usr/local/bin/VBoxManage")
test -f /usr/local/bin/VBoxVRDP                    && my_files+=("/usr/local/bin/VBoxVRDP")
test -f /usr/local/bin/VBoxHeadless                && my_files+=("/usr/local/bin/VBoxHeadless")
test -f /usr/local/bin/vboxwebsrv                  && my_files+=("/usr/local/bin/vboxwebsrv")
test -f /usr/local/bin/VBoxBugReport               && my_files+=("/usr/local/bin/VBoxBugReport")
test -f /usr/local/bin/VBoxBalloonCtrl             && my_files+=("/usr/local/bin/VBoxBalloonCtrl")
test -f /usr/local/bin/VBoxAutostart               && my_files+=("/usr/local/bin/VBoxAutostart")
test -f /usr/local/bin/VBoxDTrace                  && my_files+=("/usr/local/bin/VBoxDTrace")
test -f /usr/local/bin/vbox-img                    && my_files+=("/usr/local/bin/vbox-img")
test -d /Library/Receipts/VirtualBoxCLI.pkg/       && my_directories+=("/Library/Receipts/VirtualBoxCLI.pkg/")
test -f /Library/LaunchDaemons/org.virtualbox.startup.plist && my_files+=("/Library/LaunchDaemons/org.virtualbox.startup.plist")

test -d /Applications/VirtualBox.app/              && my_directories+=("/Applications/VirtualBox.app/")
test -d /Library/Receipts/VirtualBox.pkg/          && my_directories+=("/Library/Receipts/VirtualBox.pkg/")

# legacy
test -d /Library/Receipts/VBoxDrv.pkg/             && my_directories+=("/Library/Receipts/VBoxDrv.pkg/")
test -d /Library/Receipts/VBoxUSB.pkg/             && 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+=("/Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.py")
    test -f /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.pyc && my_files+=("/Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.pyc")
    test -f /Library/Python/$p/site-packages/vboxapi/__init__.py              && my_files+=("/Library/Python/$p/site-packages/vboxapi/__init__.py")
    test -f /Library/Python/$p/site-packages/vboxapi/__init__.pyc             && 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+=("/Library/Python/$p/site-packages/vboxapi-1.0-py$p.egg-info")
    test -d /Library/Python/$p/site-packages/vboxapi/                         && my_directories+=("/Library/Python/$p/site-packages/vboxapi/")
done

#
# Collect KEXTs to remove.
# Note that the unload order is significant.
#
declare -a 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+=("$kext")
    fi
done

#
# Collect packages to forget
#
my_pb='org\.virtualbox\.pkg\.'
my_pkgs=`/usr/sbin/pkgutil --pkgs="${my_pb}vboxkexts|${my_pb}vboxstartupitems|${my_pb}virtualbox|${my_pb}virtualboxcli"`

#
# Did we find anything to uninstall?
#
if test -z "${my_directories[*]}"  -a  -z "${my_files[*]}"   -a  -z "${my_kexts[*]}"  -a  -z "$my_pkgs"; then
    echo "No VirtualBox files, directories, KEXTs or packages to uninstall."
    echo "Done."
    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|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;
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末屠列,一起剝皮案震驚了整個(gè)濱河市肠缔,隨后出現(xiàn)的幾起案子蹲堂,更是在濱河造成了極大的恐慌,老刑警劉巖痹屹,帶你破解...
    沈念sama閱讀 219,188評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異士聪,居然都是意外死亡某饰,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,464評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門剃袍,熙熙樓的掌柜王于貴愁眉苦臉地迎上來黄刚,“玉大人,你說我怎么就攤上這事民效°疚” “怎么了?”我有些...
    開封第一講書人閱讀 165,562評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵畏邢,是天一觀的道長业扒。 經(jīng)常有香客問我,道長舒萎,這世上最難降的妖魔是什么程储? 我笑而不...
    開封第一講書人閱讀 58,893評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮臂寝,結(jié)果婚禮上章鲤,老公的妹妹穿的比我還像新娘。我一直安慰自己咆贬,他們只是感情好败徊,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,917評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著掏缎,像睡著了一般皱蹦。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上眷蜈,一...
    開封第一講書人閱讀 51,708評(píng)論 1 305
  • 那天沪哺,我揣著相機(jī)與錄音,去河邊找鬼酌儒。 笑死辜妓,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播嫌拣,決...
    沈念sama閱讀 40,430評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼柔袁,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了异逐?” 一聲冷哼從身側(cè)響起捶索,我...
    開封第一講書人閱讀 39,342評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎灰瞻,沒想到半個(gè)月后腥例,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,801評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡酝润,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,976評(píng)論 3 337
  • 正文 我和宋清朗相戀三年燎竖,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片要销。...
    茶點(diǎn)故事閱讀 40,115評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡构回,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出疏咐,到底是詐尸還是另有隱情纤掸,我是刑警寧澤,帶...
    沈念sama閱讀 35,804評(píng)論 5 346
  • 正文 年R本政府宣布浑塞,位于F島的核電站借跪,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏酌壕。R本人自食惡果不足惜掏愁,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,458評(píng)論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望卵牍。 院中可真熱鬧果港,春花似錦、人聲如沸辽慕。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,008評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽溅蛉。三九已至,卻和暖如春他宛,著一層夾襖步出監(jiān)牢的瞬間船侧,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,135評(píng)論 1 272
  • 我被黑心中介騙來泰國打工厅各, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留镜撩,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,365評(píng)論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像袁梗,于是被迫代替她去往敵國和親宜鸯。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,055評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容