diff options
author | Jouke Witteveen <j.witteveen@gmail.com> | 2012-04-11 02:07:20 +0200 |
---|---|---|
committer | Jouke Witteveen <j.witteveen@gmail.com> | 2012-04-11 11:40:18 +0200 |
commit | 7fab9eaf848004fd742e0513d620ced9ee7667a2 (patch) | |
tree | 2470a3a6643e5ae2cf3d89c50998b92cfffc86db | |
parent | fda34d4a6c03e919786b26876d6a9c051119db1d (diff) | |
download | netctl-7fab9eaf848004fd742e0513d620ced9ee7667a2.tar.gz netctl-7fab9eaf848004fd742e0513d620ced9ee7667a2.tar.xz |
Rewrite output hook to not depend on initscripts
/etc/rc.d/functions is owned by initscripts on which netcfg does not explicitly depend.
The revised layout is inspired by systemd.
-rwxr-xr-x | contrib/logging.hook | 13 | ||||
-rwxr-xr-x | contrib/pm-utils.handler | 10 | ||||
-rwxr-xr-x | rc.d/net-profiles | 3 | ||||
-rwxr-xr-x | rc.d/net-rename | 2 | ||||
-rw-r--r-- | src/globals | 6 | ||||
-rw-r--r-- | src/hooks/arch | 42 | ||||
-rwxr-xr-x | src/hooks/fancy | 84 | ||||
-rw-r--r-- | src/network | 4 |
8 files changed, 100 insertions, 64 deletions
diff --git a/contrib/logging.hook b/contrib/logging.hook index b7af62e..82d0ed1 100755 --- a/contrib/logging.hook +++ b/contrib/logging.hook @@ -33,20 +33,14 @@ function report_err { printhl "$*" } -function report_warn { - report_log warning "$*" - # printhl "$*" - checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2 -} - - -function report_notify { +function report_notice { report_log notice "$*" # print "$*" >&2 checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2 } + function report_debug { if checkyesno "$NETCFG_DEBUG"; then echo "DEBUG: $*" >&2 @@ -56,13 +50,13 @@ function report_debug { } - function report_try { report_log notice "trying $*..." stat_busy "$*" REPORT_TRYING=1 } + function report_fail { if [[ -n "$*" ]]; then report_log err "$*" @@ -79,6 +73,7 @@ function report_fail { fi } + function report_success { if [[ -n "$*" ]]; then stat_append "- $*" diff --git a/contrib/pm-utils.handler b/contrib/pm-utils.handler index 0ad87b3..79cad6a 100755 --- a/contrib/pm-utils.handler +++ b/contrib/pm-utils.handler @@ -29,7 +29,7 @@ daemon_suspend_all() case "$1" in hibernate|suspend_hybrid|suspend) - report_notify "suspending all interfaces..." + report_notice "suspending all interfaces..." daemon_suspend_all if checkyesno "${RESTOREPROFILES:-no}"; then interface_suspend all @@ -37,21 +37,21 @@ case "$1" in ;; thaw|resume) if [ -f "$STATE_DIR/interface/${WIRELESS_INTERFACE}" ]; then - report_notify "resuming all interfaces..." + report_notice "resuming all interfaces..." auto_resume ${WIRELESS_INTERFACE} else - report_notify "resuming all interfaces except wireless..." + report_notice "resuming all interfaces except wireless..." all_resume ${WIRELESS_INTERFACE} fi ;; radio_off) - report_notify "suspending wireless interface..." + report_notice "suspending wireless interface..." interface_suspend ${WIRELESS_INTERFACE} no set_iface disabled ${WIRELESS_INTERFACE} bring_interface forcedown ${WIRELESS_INTERFACE} ;; radio_on) - report_notify "resuming wireless interface..." + report_notice "resuming wireless interface..." auto_resume ${WIRELESS_INTERFACE} if [ -x /etc/pm/power.d/??wifi ]; then /usr/bin/on_ac_power # this is in pm-utils diff --git a/rc.d/net-profiles b/rc.d/net-profiles index be77bac..f8c0992 100755 --- a/rc.d/net-profiles +++ b/rc.d/net-profiles @@ -1,7 +1,8 @@ #!/bin/bash -. /usr/lib/network/globals . /etc/rc.conf +. /etc/rc.d/functions +. /usr/lib/network/globals . /etc/conf.d/netcfg case "$1" in diff --git a/rc.d/net-rename b/rc.d/net-rename index 1a51ffe..42dfa23 100755 --- a/rc.d/net-rename +++ b/rc.d/net-rename @@ -1,5 +1,7 @@ #!/bin/bash +. /etc/rc.conf +. /etc/rc.d/functions . /usr/lib/network/globals case "$1" in diff --git a/src/globals b/src/globals index eb9f934..f8d30ef 100644 --- a/src/globals +++ b/src/globals @@ -23,14 +23,10 @@ function report_err { echo "$*" } -function report_warn { +function report_notice { echo "$*" } -function report_notify { - true -} - function report_debug { checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2 } diff --git a/src/hooks/arch b/src/hooks/arch deleted file mode 100644 index c5d0587..0000000 --- a/src/hooks/arch +++ /dev/null @@ -1,42 +0,0 @@ -. /etc/rc.conf -. /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 "- $*" - REPORT_TRYING= - fi - stat_done -} - -# vim: ft=sh ts=4 et sw=4: diff --git a/src/hooks/fancy b/src/hooks/fancy new file mode 100755 index 0000000..f0ad3bb --- /dev/null +++ b/src/hooks/fancy @@ -0,0 +1,84 @@ +# Fancy output is for terminal output only. +[[ -t 1 ]] || return + + +### Fancy Logging/Error reporting + +function report_err { + print_prefixed "${C_PREFIX}" "${C_HIGHLIGHT}$*" +} + +function report_notice { + print_prefixed "${C_PREFIX}" "$*" +} + +function report_try { + printf "${C_PREFIX}${PREFIX_BUSY}${C_NORMAL} %s " "$*" + report_status " BUSY " "${C_BUSY}" + REPORT_TRYING=1 +} + +function report_fail { + if [[ -n "$*" ]]; then + if [[ -n "$REPORT_TRYING" ]]; then + report_append "$*" + report_status "FAILED" "${C_FAILED}" $'\n' + REPORT_TRYING= + else + print_prefixed "${C_FAILED}" "${C_HIGHLIGHT}$*" + fi + elif [[ -n "$REPORT_TRYING" ]]; then + report_status "FAILED" "${C_FAILED}" $'\n' + REPORT_TRYING= + fi +} + +function report_success { + if [[ -n "$*" ]]; then + if [[ -n "$REPORT_TRYING" ]]; then + report_append "$*" + report_status " DONE " "${C_DONE}" $'\n' + REPORT_TRYING= + else + print_prefixed "${C_DONE}" "$*" + fi + elif [[ -n "$REPORT_TRYING" ]]; then + report_status " DONE " "${C_DONE}" $'\n' + REPORT_TRYING= + fi +} + +function report_append { + printf -- "${RESTORE_POSITION}${C_PREFIX}-${C_NORMAL} %s " "$*" +} + +function report_status { + local status=$1 color=$2 + shift 2 + printf "${CURSOR_STATUS} [${color}%s${C_NORMAL}] %s" "$status" "$*" +} + +function print_prefixed { + local c_prefix=$1 + shift + printf "${c_prefix}${PREFIX_ATTENTION}${C_NORMAL} %s${C_NORMAL}\n" "$*" +} + + +SAVE_POSITION=$(tput sc) +RESTORE_POSITION=$(tput rc) +COLUMNS=$(tput cols) +(( COLUMNS == 0 )) && COLUMNS=80 +CURSOR_STATUS=${SAVE_POSITION}$(tput hpa $(( COLUMNS - 10 )) ) + +C_NORMAL=$(tput sgr0) +C_HIGHLIGHT=${C_NORMAL}$(tput bold) +C_PREFIX=${C_HIGHLIGHT}$(tput setaf 4) # blue +C_BUSY=${C_NORMAL}$(tput setaf 6) # cyan +C_FAILED=${C_HIGHLIGHT}$(tput setaf 1) # red +C_DONE=${C_HIGHLIGHT}$(tput setaf 2) # green + +PREFIX_BUSY="::" +PREFIX_ATTENTION=" >" + +# vim: ft=sh ts=4 et sw=4: diff --git a/src/network b/src/network index 30f9e89..9bdd720 100644 --- a/src/network +++ b/src/network @@ -64,7 +64,7 @@ interface_suspend() # the pipe to "while read" will create a subshell INTERFACE=$(. "$STATE_DIR/profiles/$prof"; echo "$INTERFACE") if [[ "$1" == all || "$1" == "$INTERFACE" ]]; then - report_notify "suspending interface $INTERFACE with profile $prof" + report_notice "suspending interface $INTERFACE with profile $prof" cp "$STATE_DIR/profiles/$prof" "$STATE_DIR/suspend/" if checkyesno "${2:-yes}"; then profile_down "$prof" @@ -88,7 +88,7 @@ all_resume() # the pipe to "while read" will create a subshell INTERFACE=$(. "$STATE_DIR/suspend/$prof"; echo "$INTERFACE") if [[ $# -eq 0 || ! " $* " =~ " $INTERFACE " ]]; then - report_notify "resuming interface $INTERFACE with profile $prof" + report_notice "resuming interface $INTERFACE with profile $prof" profile_up "$prof" rm -f "$STATE_DIR/suspend/$prof" # if profile_up succeeds, it will have already removed this fi |