From b2badb11c7f3f71c80bd768fb62b0ef0b0718254 Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Sun, 13 Sep 2009 23:43:46 -0400 Subject: added more contrib/ files Signed-off-by: Jim Pryor --- contrib/common.hook | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 contrib/common.hook (limited to 'contrib/common.hook') 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: -- cgit v1.2.3-24-g4f1b