From 54e39849f1e60eb043f9d8f0904acf3c79d96a1c Mon Sep 17 00:00:00 2001 From: James Rayner Date: Sat, 8 Aug 2009 00:23:45 +1000 Subject: Patch from Jim Pryor --- contrib/common.hook | 49 +++++++++++++++++++++++++++ contrib/ifplugd.action | 25 ++++++++++++++ contrib/logging.hook | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ contrib/pm-utils.handler | 68 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 228 insertions(+) create mode 100755 contrib/common.hook create mode 100755 contrib/ifplugd.action create mode 100755 contrib/logging.hook create mode 100755 contrib/pm-utils.handler (limited to 'contrib') diff --git a/contrib/common.hook b/contrib/common.hook new file mode 100755 index 0000000..bf5f192 --- /dev/null +++ b/contrib/common.hook @@ -0,0 +1,49 @@ +### 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 daemon [ start | stop ]" will run the daemon only if it's enabled in the DAEMONS array + # "RUNDAEMON -f daemon [ start | stop ]" will run it no matter what + local enabled result + if [[ "$1" = "-f" ]]; then + enabled=1 + shift + fi + local daemon="$1" + shift + if [[ ! -x "/etc/rc.d/$daemon" ]]; then + echo "DAEMON $daemon isn't executable." >&2 + return 1 + elif [[ "$enabled" -ne 1 ]]; then + for f in "${DAEMONS[@]}"; do + if [[ "$f" = "$daemon" || "$f" = "@$daemon" ]]; then + enabled=1 + break + fi + done + fi + if [[ "$enabled" -eq 1 ]]; then + "/etc/rc.d/$daemon" "$@" + result=$? + stat_busy "Continuing $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 1 # $daemon isn't enabled in DAEMON array +} + +# 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.) +# +POST_UP='( sleep 3 && echo "mynetworkfun()" | sudo -Hu me /usr/bin/awesome-client 2>/dev/null) & RUNDAEMON netfs start' +PRE_DOWN='RUNDAEMON netfs stop' +POST_DOWN='( sleep 3 && echo "mynetworkfun()" | sudo -Hu me /usr/bin/awesome-client 2>/dev/null) &' + +# Quirks and other variables defined here will apply to all your profiles... +QUIRKS=() +WPA_GROUP="network" + + diff --git a/contrib/ifplugd.action b/contrib/ifplugd.action new file mode 100755 index 0000000..4700c46 --- /dev/null +++ b/contrib/ifplugd.action @@ -0,0 +1,25 @@ +#!/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 + diff --git a/contrib/logging.hook b/contrib/logging.hook new file mode 100755 index 0000000..27a7c39 --- /dev/null +++ b/contrib/logging.hook @@ -0,0 +1,86 @@ +### Sample netcfg hook script for logging/debugging connections +### To install, make this executable and put it in /etc/network.d/hooks + + +# These functions are loaded after, and override, the ones in /usr/lib/network/globals + +# uncomment one of the following lines +#function report_log { report_syslog "$@"; } +#function report_log { report_stderr "$@"; } + + + + + +# What facility to send log messages to? +NETCFGLOG="${NETCFGLOG-local0}" + +function report_syslog { + if [[ -n "$NETCFGLOG" ]]; 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 "${NETCFGLOG}.$level" -t "$caller" -- "$*" + fi +} + +function report_stderr { + local level="$1" + shift + echo "netcfg $level: $*" >&2 +} + +function report_err { + report_log err "$*" + printhl "$*" +} + +function report_warn { + report_log warning "$*" + # printhl "$*" +} + +function report_notify { + report_log notice "$*" + # print "$*" >&2 +} + +function report_debug { + report_log debug "$*" +} + +function report_try { + report_log notice "trying $*..." + REPORT_TRYING=1 + stat_busy "$*" +} + +function report_fail { + if [[ -n "$*" ]]; then + report_log err "$*" + if [[ -n "$REPORT_TRYING" ]]; then + stat_append "- $*" + REPORT_TRYING= + stat_fail + else + printhl "$*" + fi + elif [[ -n "$REPORT_TRYING" ]]; then + REPORT_TRYING= + stat_fail + fi +} + +function report_success { + if [[ -n "$*" ]]; then + stat_append "- $*" + fi + report_log notice "${*:-succeeded}" + stat_done +} + diff --git a/contrib/pm-utils.handler b/contrib/pm-utils.handler new file mode 100755 index 0000000..5115b75 --- /dev/null +++ b/contrib/pm-utils.handler @@ -0,0 +1,68 @@ +#!/bin/bash + +. /etc/rc.conf +. /etc/rc.d/functions +. /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"; then # ret=0 when iface down and available + /usr/bin/netcfg-auto-wireless "$1" + fi + fi +} + + +case "$1" in + hibernate|suspend_hybrid|suspend) + report_log notice "suspending all interfaces..." + interface_suspend all + ;; + thaw|resume) + if "$CONN_DIR/wireless" query wlan0 enabled; then + report_log notice "resuming all interfaces..." + auto_resume wlan0 + else + report_log notice "resuming all interfaces except wireless..." + all_resume wlan0 + fi + ;; + + # radio_off and radio_on aren't actions that pm-utils will ever send + # but if you're able to detect the toggling of your rfkill switch with acpid, + # you could have your acpid handler call this script as e.g. "SCRIPT radio_off" + radio_off) + report_log notice "suspending wireless interface..." + interface_suspend wlan0 no + "$CONN_DIR/wireless" control wlan0 disable + ifconfig wlan0 down + ;; + radio_on) + report_log notice "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 $? + + -- cgit v1.2.3-24-g4f1b