Created
October 26, 2017 06:52
-
-
Save berardo/f8a9113706d27fddab6edf270f0a5bdd to your computer and use it in GitHub Desktop.
Script to load kernel extensions in order to allow `brew cask reinstall --force virtualbox`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
unload() { | |
if [ `ps -ef | grep -c VirtualBox$` -ne 0 ] | |
then | |
echo "VirtualBox still seems to be running. Please investigate!!" | |
exit 1; | |
elif [ `ps -ef | grep -c [V]ir` -gt 0 ] | |
then | |
echo "Stopping running processes before unloading Kernel Extensions" | |
ps -ef | grep [V]ir | awk '{print $2}' | xargs kill | |
fi | |
echo "Unloading Kernel Extensions" | |
kextstat | grep "org.virtualbox.kext.VBoxUSB" > /dev/null 2>&1 && sudo kextunload -b org.virtualbox.kext.VBoxUSB | |
kextstat | grep "org.virtualbox.kext.VBoxNetFlt" > /dev/null 2>&1 && sudo kextunload -b org.virtualbox.kext.VBoxNetFlt | |
kextstat | grep "org.virtualbox.kext.VBoxNetAdp" > /dev/null 2>&1 && sudo kextunload -b org.virtualbox.kext.VBoxNetAdp | |
kextstat | grep "org.virtualbox.kext.VBoxDrv" > /dev/null 2>&1 && sudo kextunload -b org.virtualbox.kext.VBoxDrv | |
} | |
load() { | |
echo "Loading Kernel Extentions" | |
sudo kextload "/Library/Application Support/VirtualBox/VBoxDrv.kext" -r "/Library/Application Support/VirtualBox/" | |
sudo kextload "/Library/Application Support/VirtualBox/VBoxNetAdp.kext" -r "/Library/Application Support/VirtualBox/" | |
sudo kextload "/Library/Application Support/VirtualBox/VBoxNetFlt.kext" -r "/Library/Application Support/VirtualBox/" | |
sudo kextload "/Library/Application Support/VirtualBox/VBoxUSB.kext" -r "/Library/Application Support/VirtualBox/" | |
} | |
case "$1" in | |
unload|remove) | |
unload | |
;; | |
load) | |
load | |
;; | |
*|reload) | |
unload | |
load | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment