Skip to content

Commit

Permalink
added tailscale support for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Theoreticallyhugo committed Oct 24, 2024
1 parent 7fbd676 commit 296b738
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions scripts/network_vpn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,43 @@ export LC_ALL=en_US.UTF-8
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $current_dir/utils.sh



vpn_function() {
case $(uname -s) in
Linux)

verbose=$(get_tmux_option "@dracula-network-vpn-verbose" false)

#Show IP of tun0 if connected
vpn=$(ip -o -4 addr show dev tun0 | awk '{print $4}' | cut -d/ -f1)

which -s tailscale > /dev/null
tailscale_installed=$?

if [[ $vpn =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
echo $vpn
elif [ $tailscale_installed ]; then
# if tailscale is installed
#
# https://www.reddit.com/r/Tailscale/comments/18dirro/is_there_a_way_i_can_tell_which_exit_node_i_am/
node=$(tailscale status --peers --json | jq '.ExitNodeStatus')
if [[ -z $node ]] || [[ "$node" == 'null' ]]; then
# no tailscale exit node, no output, since trafic isnt actually rerouted
echo ""
else
exitnode=$(tailscale status | grep "; exit node" | awk '{print $2}')

if $verbose; then
vpn_label=$(get_tmux_option "@dracula-network-vpn-label" "󰌘 ")
echo "$vpn_label$exitnode"
else
vpn_label=$(get_tmux_option "@dracula-network-vpn-label" "Tailscale")
echo "$vpn_label"
fi
fi
else
echo "NO VPN"
echo ""
fi
;;

Expand Down Expand Up @@ -45,18 +72,22 @@ vpn_function() {
exitnode=$(tailscale status | grep "; exit node" | cut -w -f 2)

if $verbose; then
echo "󰌘 $exitnode"
vpn_label=$(get_tmux_option "@dracula-network-vpn-label" "󰌘 ")
echo "$vpn_label$exitnode"
else
echo "Tailscale"
vpn_label=$(get_tmux_option "@dracula-network-vpn-label" "Tailscale")
echo "$vpn_label"
fi
fi

else
if $verbose; then
vpn_name=$(echo $is_not_tailscale | sed "s/.*\"\(.*\)\".*/\1/g")
echo "󰌘 $vpn_name"
vpn_label=$(get_tmux_option "@dracula-network-vpn-label" "󰌘 ")
echo "$vpn_label$vpn_name"
else
echo "VPN"
vpn_label=$(get_tmux_option "@dracula-network-vpn-label" "VPN")
echo "$vpn_label"
fi
fi
;;
Expand Down

0 comments on commit 296b738

Please sign in to comment.