Last active
November 15, 2019 07:09
-
-
Save mohemohe/7e3d45b7d9e193c6e31c113e403db295 to your computer and use it in GitHub Desktop.
VBoxManage bitbar or kargos
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 -e | |
PAUSE="/tmp/__bitbar_virtualbox_$(whoami)" | |
function start_watch() { | |
rm -f "$PAUSE" | |
exit $? | |
} | |
function pause_watch() { | |
touch "$PAUSE" | |
exit $? | |
} | |
function render() { | |
echo "📦" | |
if test -x /usr/local/bin/VBoxManage; then | |
VBM=/usr/local/bin/VBoxManage | |
elif test -x /usr/bin/VBoxManage; then | |
VBM=/usr/bin/VBoxManage | |
else | |
echo '---' | |
echo "VBoxManage not found" | |
exit 1 | |
fi | |
echo '---' | |
if [ -e "$PAUSE" ]; then | |
if [ "$BitBar" == "1" ]; then | |
echo "Watch start | bash=$0 param1=start terminal=false refresh=true" | |
else | |
echo "Watch start | bash='$0 start' terminal=false refresh=true" | |
fi | |
exit 0 | |
else | |
if [ "$BitBar" == "1" ]; then | |
echo "Watch pause | bash=$0 param1=pause terminal=false refresh=true" | |
else | |
echo "Watch pause | bash='$0 pause' terminal=false refresh=true" | |
fi | |
fi | |
echo '---' | |
VMS="$(${VBM} list vms | cut -d '"' -f 3 | awk '{print $1}')" | |
for VM in $VMS; do | |
echo '---' | |
$VBM showvminfo "$VM" | grep -i name | head -1 | cut -d ':' -f 2 | sed 's|^[ ]*||' | |
STATE="$($VBM showvminfo "$VM" | grep -i state | awk '{print $2}')" | |
if [ "$BitBar" == "1" ]; then | |
if [ "$STATE" == "running" ]; then | |
echo "--⏹️ Shutdown | bash=$VBM param1=controlvm param2=$VM param3=acpipowerbutton terminal=false refresh=true" | |
echo "--🔌 Poweroff | bash=$VBM param1=controlvm param2=$VM param3=poweroff terminal=false refresh=true" | |
else | |
echo "--▶️ Start | bash=$VBM param1=startvm param2=$VM param3=--type param4=headless terminal=false refresh=true" | |
fi | |
else | |
if [ "$STATE" == "running" ]; then | |
echo "--⏹️ Shutdown | bash='$VBM controlvm $VM acpipowerbutton' terminal=false refresh=true" | |
echo "--🔌 Poweroff | bash='$VBM controlvm $VM poweroff' terminal=false refresh=true" | |
else | |
echo "--▶️ Start | bash='$VBM startvm $VM --type headless' terminal=false refresh=true" | |
fi | |
fi | |
done | |
} | |
case "$1" in | |
"start" ) start_watch ;; | |
"pause" ) pause_watch ;; | |
* ) render ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment