#!/usr/bin/env zsh
# variables
hostname_short=$(hostname --short)
tailscale_bin="tailscale"
tailscale_status=$("$tailscale_bin" status)
# status vpn
status_vpn () {
vpn_status=""
# check for tailscale status
if echo "$tailscale_status" | grep "$hostname_short" &> /dev/null; then
vpn_status+=' '
else
vpn_status+=' '
fi
# check for direct connectivity
if "$tailscale_bin" status | grep allegro | grep direct &> /dev/null; then
vpn_status+=''
vpn_status+=''
echo "$vpn_status"
}
# switch vpn
switch_vpn () {
"$tailscale_bin" down
"$tailscale_bin" up
# main function
case $1 in
switch)
switch_vpn &> /dev/null
;;
status)
status_vpn
*)
echo "Usage: $0 {switch|status}"
exit 1
esac