summaryrefslogtreecommitdiff
path: root/data.d
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2024-02-15 11:28:32 +0100
committerPatrick Spek <p.spek@tyil.nl>2024-02-15 11:28:32 +0100
commit090483be6cf72e353e89c5a4fd118b7bdbe57baf (patch)
tree65fe11525726e63b35ad5c9fc34239747cca9de3 /data.d
parente02e68898f14c9f8c329e14254be18fad4bd4ed3 (diff)
Update post-up hook for wireguard
Diffstat (limited to 'data.d')
-rwxr-xr-xdata.d/vpn-wireguard/hooks/post-up50
1 files changed, 42 insertions, 8 deletions
diff --git a/data.d/vpn-wireguard/hooks/post-up b/data.d/vpn-wireguard/hooks/post-up
index 948a9a8..a824a30 100755
--- a/data.d/vpn-wireguard/hooks/post-up
+++ b/data.d/vpn-wireguard/hooks/post-up
@@ -1,10 +1,44 @@
#!/usr/bin/env bash
-# Ping all known hosts, as it seems that the wireguard interface comes up when
-# only after it gets used on the machine itself.
-while read -r addr;
-do
- ping -c 1 -q -w 1 "$addr" &
-done < <(awk -F= '/vpn-wireguard.ip/ { print $NF }' /etc/bashtard/hosts.d/*)
-
-wait
+readonly COLOR_RESET="\033[0m"
+readonly COLOR_OK="\033[32;1m"
+readonly COLOR_NOK="\033[31;1m"
+
+main() {
+ printf "Verifying connectability...\n"
+
+ # Ping all known hosts, as it seems that the wireguard interface comes up when
+ # only after it gets used on the machine itself.
+ while read -r addr;
+ do
+ check "$addr" &
+ done < <(awk -F= '/vpn-wireguard.ip/ { print $NF }' /etc/bashtard/hosts.d/*)
+
+ wait
+}
+
+check() {
+ local addr="$1"
+
+ if ping -c 1 -q -w 1 "$addr" > /dev/null
+ then
+ log OK "$addr"
+ else
+ log NOK "$addr"
+ fi
+}
+
+log() {
+ local state="$1"
+ local addr="$2"
+ local color="$COLOR_NOK"
+
+ if [[ $state == "OK" ]]
+ then
+ color="$COLOR_OK"
+ fi
+
+ printf "%b%3s%b: %s\n" "$color" "$state" "$COLOR_RESET" "$addr" >&2
+}
+
+main "$@"