summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcontrib/11netcfg57
-rwxr-xr-xcontrib/common.hook91
-rwxr-xr-xcontrib/ifplugd.action26
-rwxr-xr-xcontrib/logging.hook43
-rwxr-xr-xcontrib/pm-utils.handler62
5 files changed, 230 insertions, 49 deletions
diff --git a/contrib/11netcfg b/contrib/11netcfg
index 9a453d9..b1a5d5f 100755
--- a/contrib/11netcfg
+++ b/contrib/11netcfg
@@ -4,41 +4,42 @@ source /usr/lib/pm-utils/functions
source /etc/pm/config.d/netcfg
suspend_netcfg() {
- case $NETCFG_SUSPEND in
- daemons)
- stopservice net-profiles
- stopservice net-auto
- ;;
- retain|*)
- netcfg all-suspend
- ;;
- esac
+ case $NETCFG_SUSPEND in
+ daemons)
+ stopservice net-profiles
+ stopservice net-auto
+ ;;
+ retain|*)
+ netcfg all-suspend
+ ;;
+ esac
}
resume_netcfg() {
- case $NETCFG_SUSPEND in
- daemons)
- restartservice net-profiles
- restartservice net-auto
- ;;
- retain|*)
- netcfg all-resume
- ;;
- esac
+ case $NETCFG_SUSPEND in
+ daemons)
+ restartservice net-profiles
+ restartservice net-auto
+ ;;
+ retain|*)
+ netcfg all-resume
+ ;;
+ esac
}
if [ -x /usr/bin/netcfg2 ]; then
- case "$1" in
- hibernate|suspend)
- suspend_netcfg
- ;;
- thaw|resume)
- resume_netcfg
- ;;
- *)
- ;;
- esac
+ case "$1" in
+ hibernate|suspend)
+ suspend_netcfg
+ ;;
+ thaw|resume)
+ resume_netcfg
+ ;;
+ *)
+ ;;
+ esac
fi
exit $?
+# vim: ft=sh ts=4 et sw=4:
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:
diff --git a/contrib/ifplugd.action b/contrib/ifplugd.action
new file mode 100755
index 0000000..720b576
--- /dev/null
+++ b/contrib/ifplugd.action
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# /etc/ifplugd/ifplugd.action script for Arch Linux
+# can replace the one that comes with extra/ifplugd
+
+# . /etc/rc.conf
+# . /etc/rc.d/functions
+
+case "$2" in
+ up)
+ if [ "${1:0:3}" == eth ]; then
+ /usr/bin/netcfg "myethernet" # replace with name of your desired profile
+ fi
+ ;;
+ down)
+ /usr/bin/netcfg iface-down "$1"
+ /sbin/ifconfig "$1" down # note that we'll return 0 even if the netcfg call failed, e.g. because iface was already down
+ # hence no "failure" messages to syslog
+ ;;
+ *)
+ echo "Wrong arguments" > /dev/stderr
+ exit 1
+ ;;
+esac
+
+# vim: ft=sh ts=4 et sw=4:
diff --git a/contrib/logging.hook b/contrib/logging.hook
index 163bbfa..b7af62e 100755
--- a/contrib/logging.hook
+++ b/contrib/logging.hook
@@ -14,17 +14,17 @@ NETCFG_LOG="${NETCFG_LOG-local0}"
function report_log {
- if [[ -n "$NETCFG_LOG" ]]; then
- local caller level="$1"
- shift
- case "$0" in
- net-auto|netcfg-auto-*) caller=net-auto;;
- net-profiles) caller=net-profiles;;
- net-rename) caller=net-rename;;
- *) caller=netcfg;;
- esac
- logger -p "${NETCFG_LOG}.$level" -t "$caller" -- "$*"
- fi
+ if [[ -n "$NETCFG_LOG" ]]; then
+ local caller level="$1"
+ shift
+ case "$0" in
+ net-auto|netcfg-auto-*) caller=net-auto;;
+ net-profiles) caller=net-profiles;;
+ net-rename) caller=net-rename;;
+ *) caller=netcfg;;
+ esac
+ logger -p "${NETCFG_LOG}.$level" -t "$caller" -- "$*"
+ fi
}
@@ -36,23 +36,23 @@ function report_err {
function report_warn {
report_log warning "$*"
# printhl "$*"
- checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2
+ checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2
}
function report_notify {
- report_log notice "$*"
- # print "$*" >&2
- checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2
+ report_log notice "$*"
+ # print "$*" >&2
+ checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2
}
function report_debug {
- if checkyesno "$NETCFG_DEBUG"; then
- echo "DEBUG: $*" >&2
- else
- report_log debug "$*"
- fi
+ if checkyesno "$NETCFG_DEBUG"; then
+ echo "DEBUG: $*" >&2
+ else
+ report_log debug "$*"
+ fi
}
@@ -82,9 +82,10 @@ function report_fail {
function report_success {
if [[ -n "$*" ]]; then
stat_append "- $*"
- REPORT_TRYING=
+ REPORT_TRYING=
fi
report_log notice "${*:-succeeded}"
stat_done
}
+# vim: ft=sh ts=4 et sw=4:
diff --git a/contrib/pm-utils.handler b/contrib/pm-utils.handler
new file mode 100755
index 0000000..f369a6b
--- /dev/null
+++ b/contrib/pm-utils.handler
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+. /usr/lib/pm-utils/functions
+
+[[ -f /usr/lib/network/network ]] || exit $NA
+. /usr/lib/network/network
+
+auto_resume()
+{
+ all_resume
+ sleep 2
+ # if didn't successfully resume wifi, and running net-auto daemon, then restart the daemon
+ if [[ -f /var/run/daemons/net-auto && -x /usr/bin/netcfg-auto-wireless ]]; then
+ if ! check_iface "$1" >/dev/null; then # ret=1 when iface down and available
+ /usr/bin/netcfg-auto-wireless "$1"
+ fi
+ fi
+}
+
+
+case "$1" in
+ hibernate|suspend_hybrid|suspend)
+ report_notify "suspending all interfaces..."
+ interface_suspend all
+ ;;
+ thaw|resume)
+ if "$CONN_DIR/wireless" query wlan0 enabled; then
+ report_notify "resuming all interfaces..."
+ auto_resume wlan0
+ else
+ report_notify "resuming all interfaces except wireless..."
+ all_resume wlan0
+ fi
+ ;;
+ radio_off)
+ report_notify "suspending wireless interface..."
+ interface_suspend wlan0 no
+ set_iface disabled wlan0
+ bring_interface forcedown wlan0
+ ;;
+ radio_on)
+ report_notify "resuming wireless interface..."
+ auto_resume wlan0
+ if [ -x /etc/pm/power.d/??wifi ]; then
+ /usr/bin/on_ac_power # this is in pm-utils
+ case $? in
+ 0) # on ac
+ /etc/pm/power.d/??wifi false
+ ;;
+ 1) # on battery
+ /etc/pm/power.d/??wifi true
+ ;;
+ esac
+ fi
+ ;;
+ *)
+ ;;
+esac
+
+exit $?
+
+# vim: ft=sh ts=4 et sw=4: