This repository has been archived on 2024-07-10. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles-nix/apps/wireguard/wireguard.sh

51 lines
882 B
Bash
Raw Normal View History

2024-03-24 16:15:15 +01:00
#!/usr/bin/env zsh
# variables
2024-03-24 19:56:47 +01:00
hostname_short=$(hostname --short)
2024-03-24 16:15:15 +01:00
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+='✅'
else
vpn_status+='❌'
fi
echo "$vpn_status"
}
# switch vpn
switch_vpn () {
if echo "$tailscale_status" | grep "$hostname_short" &> /dev/null; then
"$tailscale_bin" down
else
"$tailscale_bin" up
fi
}
# main function
case $1 in
switch)
switch_vpn &> /dev/null
;;
status)
status_vpn
;;
*)
echo "Usage: $0 {switch|status}"
exit 1
;;
esac