3 # /lib/lsb/init-functions for Debian -*- shell-script -*-
5 # Copyright (c) 2002-03 Chris Lawrence
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # 3. Neither the name of the author nor the names of other contributors
17 # may be used to endorse or promote products derived from this software
18 # without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 TPUT="${TPUT:-"/usr/bin/tput"}"
35 [ -x "$TPUT" ] && "$TPUT" hpa 60 >/dev/null 2>&1 \
46 RED="$("$TPUT" setaf 1)"
47 #NORMAL="$("$TPUT" op)"
48 printf " ${RED}*${NORMAL} $@\n"
56 YELLOW="$("$TPUT" setaf 3)"
57 #NORMAL="$("$TPUT" op")"
58 # printf " *${NORMAL} $@\n"
59 printf " ${BLUE}*${NORMAL} $@\n"
65 log_warning_msg_nn() {
67 YELLOW="$("$TPUT" setaf 3)"
68 printf " ${BLUE}*${NORMAL} $@"
74 # int log_begin_message (char *message)
76 if [ "$#" -eq 0 ]; then
79 printf " ${GREEN}*${NORMAL} $@\n"
83 if [ "$#" -eq 0 ]; then
86 printf " ${GREEN}*${NORMAL} $@"
90 SUBMSG=" ${GREEN}-${NORMAL} "
92 # int log_end_message (int exitstatus)
95 # If no arguments were passed, return
96 [ "$#" -eq 0 ] && return 1
98 # Only do the fancy stuff if we have an appropriate terminal
99 # and if /usr is already mounted
101 COLS="$("$TPUT" cols)"
102 if [ -n "$COLS" ]; then
108 END="$("$TPUT" hpa "$COL")"
109 START="$("$TPUT" hpa 0)"
110 #RED="$("$TPUT" setaf 1)"
111 #NORMAL="$("$TPUT" op)"
112 if [ "$1" -eq 0 ]; then
113 printf "${UP}${END}${BLUE}[ ${GREEN}ok ${BLUE}]${NORMAL}\n"
115 printf "${UP}${START} ${RED}*${NORMAL}${END}[${RED}fail${NORMAL}]\n"
118 if [ "$1" -eq 0 ]; then
127 # Copyright 1999-2005 Gentoo Foundation
128 # Distributed under the terms of the GNU General Public License v2
129 # $Header: /var/cvsroot/gentoo-src/rc-scripts/sbin/functions.sh,v 1.81.2.6 2005/05/15 20:00:31 vapier Exp $
133 # Dont output to stdout?
136 # Default values for e-message indentation and dots
142 # Should we use color?
143 if [ -r /proc/cmdline ] ; then
144 grep -q ' nocolor' /proc/cmdline && RC_NOCOLOR='yes'
146 [ -n "$NOCOLORS" ] && RC_NOCOLOR='yes'
147 RC_NOCOLOR="${RC_NOCOLOR:-no}"
149 # Can the terminal handle endcols?
152 # Setup COLS and ENDCOL so eend can line up the [ ok ]
153 # width of [ ok ] == 7
154 COLS="$(stty size 2>/dev/null | cut -d' ' -f2)"
155 if [ -z "${COLS}" ] || [ "${COLS}" -le 0 ] ; then
159 if [ "${RC_ENDCOL}" = "yes" ]; then
160 ENDCOL="
\e[A
\e[$(( ${COLS} - 8 ))G"
165 # Setup the colors so our messages all look pretty
166 if [ "${RC_NOCOLOR}" = "yes" ]; then
167 unset GOOD WARN BAD NORMAL HILITE BRACKET
177 # void esyslog(char* priority, char* tag, char* message)
179 # use the system logger to log a message
185 [ "$#" -le 2 ] && return 0
186 if [ -x /usr/bin/logger ] ; then
191 /usr/bin/logger -p "${pri}" -t "${tag}" -- "$@"
197 # void eindent(int num)
199 # increase the indent used for e-commands.
203 [ "$i" -gt 0 ] || i="${RC_DEFAULT_INDENT}"
204 esetdent $(( ${#RC_INDENTATION} + $i ))
207 # void eoutdent(int num)
209 # decrease the indent used for e-commands.
213 [ "$i" -gt 0 ] || i="${RC_DEFAULT_INDENT}"
214 esetdent $(( ${#RC_INDENTATION} - $i ))
217 # void esetdent(int num)
219 # hard set the indent used for e-commands.
224 [ "$i" -lt 0 ] && i=0
225 RC_INDENTATION="$(printf "%${i}s" '')"
228 # void einfo(char* message)
230 # show an informative message (with a newline)
238 # void einfon(char* message)
240 # show an informative message (without a newline)
243 [ "${RC_QUIET_STDOUT}" = "yes" ] && return 0
244 [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
245 printf " ${GOOD}*${NORMAL} ${RC_INDENTATION}$*"
250 # void ewarn(char* message)
252 # show a warning message + log it
255 if [ "${RC_QUIET_STDOUT}" = "yes" ]; then
258 [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
259 printf " ${WARN}*${NORMAL} ${RC_INDENTATION}$*\n"
262 # Log warnings to system log
263 esyslog "daemon.warning" "rc-scripts" "$@"
269 # void eerror(char* message)
271 # show an error message + log it
274 if [ "${RC_QUIET_STDOUT}" = "yes" ]; then
275 printf " $*\n" >/dev/stderr
277 [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
278 printf " ${BAD}*${NORMAL} ${RC_INDENTATION}$*\n"
281 # Log errors to system log
282 esyslog "daemon.err" "rc-scripts" "$@"
288 # void ebegin(char* message)
290 # show a message indicating the start of a process
293 local msg="$@" dots spaces
294 spaces="$(printf '%'"${#RC_DOT_PATTERN}"'s' '')"
295 [ "${RC_QUIET_STDOUT}" = "yes" ] && return 0
297 if [ -n "${RC_DOT_PATTERN}" ]; then
298 dots="$(printf "%$(( $COLS - 3 - ${#RC_INDENTATION} - ${#msg} - 7 ))s" '')"
299 while [ "${dots#${spaces}}" != "${dots}" ] ; do
300 dots="${dots#${spaces}}${RC_DOT_PATTERN}"
307 [ "${RC_ENDCOL}" = "yes" ] && echo
309 LAST_E_LEN=$(( 3 + ${#RC_INDENTATION} + ${#msg} ))
314 # void _eend(int error, char *efunc, char* errstr)
316 # indicate the completion of process, called from eend/ewend
317 # if error, show errstr via efunc
319 # This function is private to functions.sh. Do not call it from a
323 local retval="${1:-0}" efunc="${2:-eerror}" msg
326 if [ "${retval}" -eq 0 ]; then
327 [ "${RC_QUIET_STDOUT}" = "yes" ] && return 0
328 msg="${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}"
330 if [ "$#" -gt 0 ] ; then
333 msg="${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}"
336 if [ "${RC_ENDCOL}" = "yes" ]; then
337 printf "${ENDCOL} ${msg}\n"
339 [ "${LAST_E_CMD}" = "ebegin" ] || LAST_E_LEN=0
340 printf "%$(( ${COLS} - ${LAST_E_LEN} - 6 ))s%b\n" '' "${msg}"
346 # void eend(int error, char* errstr)
348 # indicate the completion of process
349 # if error, show errstr via eerror
352 local retval="${1:-0}"
355 _eend "${retval}" eerror "$@"
361 # void ewend(int error, char* errstr)
363 # indicate the completion of process
364 # if error, show errstr via ewarn
367 local retval="${1:-0}"
370 _eend "${retval}" ewarn "$@"