Last active
March 9, 2023 13:10
-
-
Save evertdespiegeleer/d9bdccc5f864e1e2a08619e202f67a4c to your computer and use it in GitHub Desktop.
SwiftBar plugin to monitor and activate/deactivate a virtual machine on Azure.
This file contains 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
#!/usr/bin/env bash | |
# azure cli and jq required | |
AZURE_VM_MACHINE_NAME="docker-runner"; # What the vm is called in azure | |
RESOURCE_GROUP="my-resource-group"; | |
LABEL_VM_NAME='Dev server'; # What the machine should be called in the menubar | |
MACHINE_EMOJI='🤖'; | |
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | |
if [ "$@" == "wake" ]; then | |
# AZ vm wakeup command | |
az vm start --resource-group $RESOURCE_GROUP --name $AZURE_VM_MACHINE_NAME; | |
exit 0; | |
fi; | |
if [ "$@" == "down" ]; then | |
# AZ vm shutdown command | |
az vm deallocate --resource-group $RESOURCE_GROUP --name $AZURE_VM_MACHINE_NAME; | |
exit 0; | |
fi; | |
# Check if dev machine is running | |
# Tweak this query if required. | |
POWERSTATE=$(az vm list --query "[?name=='$AZURE_VM_MACHINE_NAME']" -d | jq -r '.[0].powerState'); | |
if [ "$POWERSTATE" == "VM deallocated" ]; then | |
echo "${MACHINE_EMOJI}🛏️"; | |
echo '---'; | |
echo "$LABEL_VM_NAME is not running"; | |
echo "Awaken | bash='$BASH_SOURCE' param0='wake' terminal='false' refresh='true'" | |
elif [ "$POWERSTATE" == "VM running" ]; then | |
echo "${MACHINE_EMOJI}🏋️"; | |
echo '---'; | |
echo "$LABEL_VM_NAME is running"; | |
echo "Shut down | bash='$BASH_SOURCE' param0='down' terminal='false' refresh='true'" | |
elif [ "$POWERSTATE" == "VM starting" ]; then | |
echo "${MACHINE_EMOJI}⬆️"; | |
echo '---'; | |
echo "$LABEL_VM_NAME is starting"; | |
elif [ "$POWERSTATE" == "VM deallocating" ]; then | |
echo "${MACHINE_EMOJI}⬇️"; | |
echo '---'; | |
echo "$LABEL_VM_NAME is shutting down"; | |
else | |
echo "${MACHINE_EMOJI}❓" | |
fi | |
# <swiftbar.hideAbout>true</swiftbar.hideAbout> | |
# <swiftbar.hideRunInTerminal>true</swiftbar.hideRunInTerminal> | |
# <swiftbar.hideLastUpdated>true</swiftbar.hideLastUpdated> | |
# <swiftbar.hideDisablePlugin>true</swiftbar.hideDisablePlugin> | |
# <swiftbar.hideSwiftBar>true</swiftbar.hideSwiftBar> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment