summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Pryor <profjim@jimpryor.net>2009-08-11 14:04:50 +0200
committerJames Rayner <james@archlinux.org>2009-08-15 04:28:25 +0200
commit4ede76fb6a5ba81b92b0e3452e954d9eea431a74 (patch)
tree35a778707c544d6604a01aca3027df4924408f8a
parent4ebad5f88abda1b0788ef7ad3cd46d8cd8cfa6d7 (diff)
downloadnetctl-4ede76fb6a5ba81b92b0e3452e954d9eea431a74.tar.gz
netctl-4ede76fb6a5ba81b92b0e3452e954d9eea431a74.tar.xz
Add contrib dir and logging hooks
* Add contrib/logging.hook * Update Makefile and manpage * Propose that hooks go into /etc, not /usr---latter should be shareable and possibly read-only, not good spot for user-configurable files like these. * Since we have hooks/arch as part of the package, this commit attempts to load hooks from both /usr/lib/network/hooks and /etc/network.d/hooks. (Executable hooks in /etc take precedence over hooks with same name from /usr.) * Need to load /etc/rc.conf before /etc/rc.d/functions (e.g. for USECOLORS) Signed-off-by: Jim Pryor <profjim@jimpryor.net>
-rw-r--r--Makefile6
-rwxr-xr-xcontrib/logging.hook89
-rw-r--r--man/netcfg.88
-rw-r--r--src/globals43
-rw-r--r--src/hooks/arch1
5 files changed, 127 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 4744bc2..9220b5d 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ VPATH = doc
install:
install -d $(DESTDIR)/usr/lib/network/{connections,hooks} $(DESTDIR)/etc/network.d/examples \
+ $(DESTDIR)/etc/network.d/hooks \
$(DESTDIR)/var/run/network/{interfaces,profiles} \
$(DESTDIR)/usr/bin/ $(DESTDIR)/etc/rc.d/ \
$(DESTDIR)/usr/share/man/{man5,man8} \
@@ -31,8 +32,9 @@ install-wireless:
install -m755 src-wireless/net-auto $(DESTDIR)/etc/rc.d
install-docs: docs
- install -d $(DESTDIR)/usr/share/doc/netcfg
+ install -d $(DESTDIR)/usr/share/doc/netcfg/contrib
install -m644 doc/*html $(DESTDIR)/usr/share/doc/netcfg/
+ install -m644 contrib/* $(DESTDIR)/usr/share/doc/netcfg/contrib/
docs: doc/*
for doc in $(?); do \
@@ -42,7 +44,7 @@ docs: doc/*
tarball:
sed -i "s/NETCFG_VER=.*/NETCFG_VER=$(VERSION)/g" src/netcfg
mkdir -p netcfg-$(VERSION)
- cp -r src src-wireless examples man Makefile LICENSE README netcfg-$(VERSION)
+ cp -r src src-wireless examples contrib man Makefile LICENSE README netcfg-$(VERSION)
tar -zcvf netcfg-$(VERSION).tar.gz netcfg-$(VERSION)
mv netcfg-$(VERSION).tar.gz ../
rm -rf netcfg-$(VERSION)
diff --git a/contrib/logging.hook b/contrib/logging.hook
new file mode 100755
index 0000000..b314dd1
--- /dev/null
+++ b/contrib/logging.hook
@@ -0,0 +1,89 @@
+### Sample netcfg hook script for logging/debugging connections
+### To install, make this executable and put it in /etc/network.d/hooks
+
+
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+
+# if NETCFG_DEBUG is set, debugging messages go to stderr instead of syslog
+
+# What facility to send log messages to? if set to "", nothing will be sent to syslog
+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
+}
+
+
+function report_err {
+ report_log err "$*"
+ printhl "$*"
+}
+
+function report_warn {
+ report_log warning "$*"
+ # printhl "$*"
+ [[ -n "$NETCFG_DEBUG" ]] && echo "DEBUG: $*" >&2
+}
+
+
+
+function report_notify {
+ report_log notice "$*"
+ # print "$*" >&2
+ [[ -n "$NETCFG_DEBUG" ]] && echo "DEBUG: $*" >&2
+}
+
+function report_debug {
+ if [[ -n "$NETCFG_DEBUG" ]]; then
+ echo "DEBUG: $*" >&2
+ else
+ report_log debug "$*"
+ fi
+}
+
+
+
+function report_try {
+ report_log notice "trying $*..."
+ stat_busy "$*"
+ REPORT_TRYING=1
+}
+
+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/man/netcfg.8 b/man/netcfg.8
index f07e12a..97bfec2 100644
--- a/man/netcfg.8
+++ b/man/netcfg.8
@@ -1,4 +1,4 @@
-.TH NETCFG 8 "MAY 2007" "Arch Linux" "Network Scripts"
+.TH NETCFG 8 "AUGUST 2009" "Arch Linux" "Network Scripts"
.\" groff -man -Tascii foo.1
.SH NAME
netcfg \- start/stop/control network profiles
@@ -19,6 +19,9 @@ Start the specified profile, only if it's interface is not currently up.
.B \-d, down \fIprofile\fP
Stop the specified profile
.TP
+.B\-r, reconnect \fIprofile\fP
+Disconnect and reconnect the specified profile
+.TP
.B \-i, iface-down \fBinterface\fP
Stop the profile up on the specified interface.
.TP
@@ -44,6 +47,9 @@ Currently installed network profile types.
.TP
.I /etc/network.d/examples
Example configurations for this script
+.TP
+.I /etc/network.d/hooks
+See /usr/share/doc/netcfg/contrib for examples.
.SH BUGS
None, hopefully, but if you do find one of these elusive things, please submit at http://bugs.archlinux.org/ or email one of the authors below.
diff --git a/src/globals b/src/globals
index 616468c..4e2c397 100644
--- a/src/globals
+++ b/src/globals
@@ -4,13 +4,12 @@
##
##################################
-# JP:rather than declare these in several library files, we just declare them
-# once here, so they only need to be changed at a single point
-
# /etc/network.d/hooks directory
-# any +x files in that directory will be sourced when this file is sourced
-# they can override any of the utility functions defined here for custom behavior
-# (such as logging error messages to syslog, as I like to do)
+#
+# any +x files in /usr/lib/network/hooks and /etc/network.d/hooks
+# will be sourced when this file is.
+# hook files can override any of the utility functions defined here for custom behavior
+# (such as logging error messages to syslog)
# this lets us keep netcfg simple but gives it the flexibility for users
# to make modular use of it to do more complex things
@@ -18,11 +17,22 @@
### Globals
PROFILE_DIR="/etc/network.d/"
HOOKS_DIR="/usr/lib/network/hooks/"
+USERHOOKS_DIR="$PROFILE_DIR/hooks/"
SUBR_DIR="/usr/lib/network/"
CONN_DIR="${SUBR_DIR}/connections/"
STATE_DIR="/var/run/network/"
+# Interface up/down hooks
+#
+function at_interface_up {
+ true
+}
+function at_interface_down {
+ true
+}
+
+
### Logging/Error reporting
#
@@ -39,7 +49,7 @@ function report_notify {
}
function report_debug {
- [[ -n $NETCFG_DEBUG ]] && echo "DEBUG: $*"
+ [[ -n "$NETCFG_DEBUG" ]] && echo "DEBUG: $*"
}
function report_try {
@@ -69,23 +79,22 @@ function report_success {
echo "[done]"
}
-function at_interface_up {
- true
-}
-function at_interface_down {
- true
-}
-
### For calling scripts only; don't use in library functions
function exit_stderr { echo "$*" >&2; exit 1; }
function exit_err { report_err "$*"; exit 1; }
function exit_fail { report_fail "$*"; exit 1; }
+
function load_hooks() {
- ### Load any +x files in $HOOKS_DIR
+ ### Load any +x files in $HOOKS_DIR and $USERHOOKS_DIR
local hook
- for hook in $(find -L "$HOOKS_DIR/" -maxdepth 1 -type f -executable | sort); do
- source "$hook"
+ for hook in $(find -L "$HOOKS_DIR/" "$USERHOOKS_DIR/$hook" -maxdepth 1 -type f -executable -printf '%P\n' | sort -u); do
+ # if there's an executable hook of this name in USERHOOKS_DIR, we only load it
+ if [ -x "$USERHOOKS_DIR/$hook" ]; then
+ source "$USERHOOKS_DIR/$hook"
+ else
+ source "$HOOKS_DIR/$hook"
+ fi
done
}
diff --git a/src/hooks/arch b/src/hooks/arch
index e8f20f1..6bf6a41 100644
--- a/src/hooks/arch
+++ b/src/hooks/arch
@@ -1,3 +1,4 @@
+. /etc/rc.conf
. /etc/rc.d/functions
### Logging/Error reporting for Arch Linux