summaryrefslogtreecommitdiffstats
path: root/contrib/common.hook
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/common.hook')
-rwxr-xr-xcontrib/common.hook91
1 files changed, 91 insertions, 0 deletions
diff --git a/contrib/common.hook b/contrib/common.hook
new file mode 100755
index 0000000..88066cf
--- /dev/null
+++ b/contrib/common.hook
@@ -0,0 +1,91 @@
+### Sample netcfg hook script showing how to declare shared settings
+#
+### These functions and variables will be available to all profiles
+### (They can be manually overridden by any profile.)
+### To install, make this executable and put it in /etc/network.d/hooks
+
+function RUNDAEMON {
+ # "RUNDAEMON [options] daemon { start | stop }" will run the daemon
+ # -d DEP: will only run if daemon DEP is registered as also started/stopped in /var/run/daemons
+ # will only stop if daemon is running (or option -f)
+ # will only start if daemon is in the DAEMONS array (or option -f)
+ local force dep
+ while true; do
+ if [[ "$1" = "-f" ]]; then
+ force=1
+ shift
+ elif [[ "$1" = "-d" ]]; then
+ [[ -e "/var/run/daemons/$2" ]]
+ if [ $? -eq 0 ]; then
+ case "$dep" in
+ yes) ;;
+ no) dep=mixed;;
+ *) dep=yes;;
+ esac
+ else
+ case "$dep" in
+ no) ;;
+ yes) dep=mixed;;
+ *) dep=no;;
+ esac
+ fi
+ shift 2
+ else
+ break
+ fi
+ done
+ local daemon="$1"
+ shift
+ if [[ ! -x "/etc/rc.d/$daemon" ]]; then
+ echo "/etc/rc.d/$daemon isn't executable." >&2
+ return 1
+ fi
+ case "$1" in
+ start)
+ if [[ "$dep" = no || "$dep" = mixed ]]; then
+ force=0
+ elif [[ "$force" -ne 1 ]]; then
+ for f in "${DAEMONS[@]}"; do
+ if [[ "$f" = "$daemon" || "$f" = "@$daemon" ]]; then
+ force=1
+ break
+ fi
+ done
+ fi
+ ;;
+ stop)
+ if [[ "$dep" = yes || "$dep" = mixed ]]; then
+ force=0
+ elif [[ "$force" -ne 1 ]]; then
+ [[ ! -e "/var/run/$daemon" ]]
+ force=$?
+ fi
+ ;;
+ *)
+ force=1
+ ;;
+ esac
+ if [[ "$force" -eq 1 ]]; then
+ "/etc/rc.d/$daemon" "$@"
+ local result=$?
+ stat_busy "Resuming netcfg $PROFILE..." # else we'll get a [DONE] or [FAIL] at the end of a third blank line, after messages from $daemon
+ return $result
+ fi
+ return 0 # $daemon doesn't satisfy conditions, fail quietly
+ # returning 1 would make our POST_UP script, and hence our connection attempt, fail
+}
+
+# Example of some things you might do in your POST_UP/PRE_DOWN scripts
+# (In fact, I couldn't get awesome-client to work on its own in this context, I had to call a wrapper instead that
+# sources the file in ~/.dbus/session-bus and then exports DBUS_SESSION_BUS_ADDRESS, and then calls awesome-client.)
+#
+PRE_DOWN='RUNDAEMON -f netfs stop'
+POST_DOWN='( sleep 3 && echo "mynetworkfun()" | sudo -Hu me /usr/bin/awesome-client 2>/dev/null) &'
+
+POST_UP='( sleep 3 && echo "mynetworkfun()" | sudo -Hu me /usr/bin/awesome-client 2>/dev/null) & RUNDAEMON -f -d nfs-common netfs start'
+
+# Quirks and other variables defined here will apply to all your profiles...
+QUIRKS=()
+WPA_GROUP="network"
+
+# vim: ft=sh ts=4 et sw=4: