From c1b7b022611bca8c470c2ebc3678675a436390f3 Mon Sep 17 00:00:00 2001 From: Xiao Pan Date: Sat, 11 Jan 2025 21:03:52 -0800 Subject: wireguard switch to use cfg repo branches as names --- sh/vip | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'sh/vip') 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 -- cgit v1.2.3-70-g09d2