-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtailnet-switcher
More file actions
executable file
·31 lines (24 loc) · 1 KB
/
tailnet-switcher
File metadata and controls
executable file
·31 lines (24 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh
# picker for easily switching between Tailscale tailnets
# needs a graphical polkit agent or to run `sudo tailscale set --operator=$USER` on each tailnet
construct_list() {
echo "$1" | while read line; do
printf " $(printf "$line" | awk '{print $2}')\n"
done
}
if ! pgrep tailscaled >/dev/null 2>&1; then
notify-send -u critical "tailscaled is not running!"
exit 1
fi
if ! tailscale switch --list >/dev/null 2>&1; then # tailscale operator is root
PKEXEC="pkexec"
fi
TAILNET_LIST="$($PKEXEC tailscale switch --list | tail -n +2)"
SELECTION="$(construct_list "$TAILNET_LIST" | fuzzel --dmenu --prompt='Tailnet: ' | awk '{print $2}')"
[ -z "$SELECTION" ] && exit 1 # exit if no selection has been made
TAILNET_ID="$(printf "$TAILNET_LIST" | grep "$SELECTION" | awk '{print $1}')"
if $PKEXEC tailscale switch "$TAILNET_ID"; then
notify-send -u low "Switched to tailnet $SELECTION (ID: $TAILNET_ID)"
else
notify-send -u critical "Failed to switch to tailnet $SELECTION (ID: $TAILNET_ID)"
fi