diff options
author | James Rayner <james@archlinux.org> | 2009-08-10 12:48:31 +0200 |
---|---|---|
committer | James Rayner <james@archlinux.org> | 2009-08-10 12:48:31 +0200 |
commit | 95b0fd57c0487cf6cb557fbc63de177099ca867c (patch) | |
tree | 16b748b837732f45419333edf8855fd2ef495ab4 | |
parent | 78e2fa6621750e4f2a108f90598d9a7e798b46b3 (diff) | |
download | netctl-95b0fd57c0487cf6cb557fbc63de177099ca867c.tar.gz netctl-95b0fd57c0487cf6cb557fbc63de177099ca867c.tar.xz |
add missing globals and 'arch' hook
-rw-r--r-- | src/globals | 93 | ||||
-rw-r--r-- | src/hooks/arch | 38 |
2 files changed, 131 insertions, 0 deletions
diff --git a/src/globals b/src/globals new file mode 100644 index 0000000..616468c --- /dev/null +++ b/src/globals @@ -0,0 +1,93 @@ +################################## +## +# /usr/lib/network/globals +## +################################## + +# 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) +# this lets us keep netcfg simple but gives it the flexibility for users +# to make modular use of it to do more complex things + + +### Globals +PROFILE_DIR="/etc/network.d/" +HOOKS_DIR="/usr/lib/network/hooks/" +SUBR_DIR="/usr/lib/network/" +CONN_DIR="${SUBR_DIR}/connections/" +STATE_DIR="/var/run/network/" + + +### Logging/Error reporting +# + +function report_err { + echo "$*" +} + +function report_warn { + echo "$*" +} + +function report_notify { + true +} + +function report_debug { + [[ -n $NETCFG_DEBUG ]] && echo "DEBUG: $*" +} + +function report_try { + echo ":: $*" + REPORT_TRYING=1 +} + +function report_fail { + if [[ -n "$*" ]]; then + if [[ -n "$REPORT_TRYING" ]]; then + echo "- $*" + REPORT_TRYING= + echo "[fail]" + else + echo "$*" + fi + elif [[ -n "$REPORT_TRYING" ]]; then + REPORT_TRYING= + echo "[fail]" + fi +} + +function report_success { + if [[ -n "$*" ]]; then + echo "- $*" + fi + 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 + local hook + for hook in $(find -L "$HOOKS_DIR/" -maxdepth 1 -type f -executable | sort); do + source "$hook" + done +} + +load_hooks + diff --git a/src/hooks/arch b/src/hooks/arch new file mode 100644 index 0000000..e8f20f1 --- /dev/null +++ b/src/hooks/arch @@ -0,0 +1,38 @@ +. /etc/rc.d/functions + +### Logging/Error reporting for Arch Linux + +function report_err { + printhl "$*" +} + +function report_warn { + printhl "$*" +} + +function report_try { + stat_busy "$*" + REPORT_TRYING=1 +} + +function report_fail { + if [[ -n "$*" ]]; then + 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 + stat_done +} |