]> git.infradead.org Git - users/dwmw2/vpnc-scripts.git/commitdiff
Add script hooks
authorDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 23 Apr 2012 00:20:34 +0000 (01:20 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 23 Apr 2012 00:20:34 +0000 (01:20 +0100)
This is based loosely in concept on the Debian patch, and is also needed for
OpenWrt unless we want to add a bunch of OpenWrt-specific stuff in here too.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
vpnc-script

index bb144648363db1362b14545b0a5548666167aafb..98a72cf9fccfaca440dcc3424c9fa9b721099a89 100755 (executable)
@@ -56,6 +56,7 @@ PATH=/sbin:/usr/sbin:$PATH
 
 OS="`uname -s`"
 
+HOOKS_DIR=/etc/vpnc
 DEFAULT_ROUTE_FILE=/var/run/vpnc/defaultroute
 RESOLV_CONF_BACKUP=/var/run/vpnc/resolv.conf-backup
 SCRIPTNAME=`basename $0`
@@ -113,6 +114,19 @@ else # Generic for any OS
        RESTORERESOLVCONF=restore_resolvconf_generic
 fi
 
+
+# =========== script hooks =================================================
+
+run_hooks() {
+       HOOK="$1"
+
+       if [ -d ${HOOKS_DIR}/${HOOK}.d ]; then
+           for script in ${HOOKS_DIR}/${HOOK}.d/* ; do
+               [ -f $script ] && . $script
+           done
+       fi
+}
+
 # =========== tunnel interface handling ====================================
 
 do_ifconfig() {
@@ -689,13 +703,21 @@ fi
 
 case "$reason" in
        pre-init)
+               run_hooks pre-init
                do_pre_init
                ;;
        connect)
+               run_hooks connect
                do_connect
+               run_hooks post-connect
                ;;
        disconnect)
+               run_hooks disconnect
                do_disconnect
+               run_hooks post-disconnect
+               ;;
+       reconnect)
+               run_hooks reconnect
                ;;
        *)
                echo "unknown reason '$reason'. Maybe vpnc-script is out of date" 1>&2