lots of fixes, new music stuff
[distro-setup] / disabled / home-vpn / vpn-client-connect
diff --git a/disabled/home-vpn/vpn-client-connect b/disabled/home-vpn/vpn-client-connect
new file mode 100755 (executable)
index 0000000..c3c9e8a
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+
+x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*} # directory of this file
+
+# see lan-dyn-dns-update. this is the corresponding script for on connect/disconnect from vpn
+
+d=/p/ovpn-ssh
+ssh_cmd="ssh -F$d/.config -i$d/home root@wrt.b8.nz cedit ovpn-$X509_0_CN /etc/hosts"
+case $script_type in
+    client-connect) $ssh_cmd <<<"$ifconfig_pool_remote_ip $X509_0_CN"|| [[ $? == 1 ]]
+        ;;
+    client-disconnect)
+        $ssh_cmd <<<$(grep -F $X509_0_CN lan-dns) || [[ $? == 1 ]]
+        ;;
+esac