summaryrefslogtreecommitdiff
path: root/sh/vip
diff options
context:
space:
mode:
authorXiao Pan <xyz@flylightning.xyz>2025-01-11 21:03:52 -0800
committerXiao Pan <xyz@flylightning.xyz>2025-01-11 21:03:52 -0800
commitc1b7b022611bca8c470c2ebc3678675a436390f3 (patch)
treefcf48432ae3ef4dce87a8a0bcc9b2ba197105fc2 /sh/vip
parent80d5c54225e115ec0f260c253f14db25fbc7d117 (diff)
wireguard switch to use cfg repo branches as names
Diffstat (limited to 'sh/vip')
-rwxr-xr-xsh/vip25
1 files changed, 6 insertions, 19 deletions
diff --git a/sh/vip b/sh/vip
index 95941be..bce93c5 100755
--- a/sh/vip
+++ b/sh/vip
@@ -1,25 +1,12 @@
#!/bin/sh
# Vpn IP
-case "$(nmcli -t --fields device,state device)" in
- *wg_aa:connected*) echo aa;;
- *wg_ca:connected*) echo ca;;
- *wg_ia:connected*) echo ia;;
- *wg_ib:connected*) echo ib;;
- *wg_mydefault:connected*) echo mydefault;;
- *wg_studio:connected*) echo studio;;
- *) echo none;;
-esac
+# seperate with _ and : , see `man awk.1p` "Otherwise, the string value of FS
+# shall be considered to be an extended regular expression. ...", so -F if
+# multiple chars means it is regex? so [_:] inside [] there's _ and : char
+# which in regex means _ and : char? More maybe see:
+# https://www.gnu.org/software/gawk/manual/html_node/Regexp-Field-Splitting.html
+nmcli -t --fields device,state device | awk -F'[_:]' '/wg_.*:connected/{print $2}'
printf 'default: '; curl -m1 ifconfig.co
printf '4: '; curl -4m1 ifconfig.co
printf '6: '; curl -6m1 ifconfig.co
-
-# the old way, slower and more code
-#nm_device_state="$(nmcli -t --fields device,state device)"
-#if echo "$nm_device_state" | grep -q '^wg_ia:connected$'; then
-# echo ia
-#elif echo "$nm_device_state" | grep -q '^wg_studio:connected$'; then
-# echo studio
-#else
-# echo insp
-#fi