Commit 7fab9eaf authored by Jouke Witteveen's avatar Jouke Witteveen
Browse files

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.
parent fda34d4a
......@@ -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 "- $*"
......
......@@ -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
......
#!/bin/bash
. /usr/lib/network/globals
. /etc/rc.conf
. /etc/rc.d/functions
. /usr/lib/network/globals
. /etc/conf.d/netcfg
case "$1" in
......
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
. /usr/lib/network/globals
case "$1" in
......
......@@ -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
}
......
. /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:
# 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:
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment