# vim:ft=sh:tw=80:ts=4 # lsb init-functions # # based on: # /lib/lsb/init-functions for Debian -*- shell-script -*- # # Copyright (c) 2002-03 Chris Lawrence # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. Neither the name of the author nor the names of other contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. TPUT="${TPUT:-"/usr/bin/tput"}" _have_tput() { [ -x "$TPUT" ] && "$TPUT" hpa 60 >/dev/null 2>&1 \ && return 0 \ || return 1 } log_success_msg() { printf " * $@\n" } log_failure_msg() { if _have_tput ; then RED="$("$TPUT" setaf 1)" #NORMAL="$("$TPUT" op)" printf " ${RED}*${NORMAL} $@\n" else printf " * $@\n" fi } log_warning_msg() { if _have_tput ; then YELLOW="$("$TPUT" setaf 3)" #NORMAL="$("$TPUT" op")" # printf " *${NORMAL} $@\n" printf " ${BLUE}*${NORMAL} $@\n" else printf " * $@\n" fi } log_warning_msg_nn() { if _have_tput ; then YELLOW="$("$TPUT" setaf 3)" printf " ${BLUE}*${NORMAL} $@" else printf " * $@" fi } # int log_begin_message (char *message) log_begin_msg() { if [ "$#" -eq 0 ]; then return 1 fi printf " ${GREEN}*${NORMAL} $@\n" } log_begin_msg_nn() { if [ "$#" -eq 0 ]; then return 1 fi printf " ${GREEN}*${NORMAL} $@" } SUBMSG=" ${GREEN}-${NORMAL} " # int log_end_message (int exitstatus) log_end_msg() { # If no arguments were passed, return [ "$#" -eq 0 ] && return 1 # Only do the fancy stuff if we have an appropriate terminal # and if /usr is already mounted if _have_tput ; then COLS="$("$TPUT" cols)" if [ -n "$COLS" ]; then COL=$(( $COLS - 7 )) else COL=73 fi UP="$("$TPUT" cuu1)" END="$("$TPUT" hpa "$COL")" START="$("$TPUT" hpa 0)" #RED="$("$TPUT" setaf 1)" #NORMAL="$("$TPUT" op)" if [ "$1" -eq 0 ]; then printf "${UP}${END}${BLUE}[ ${GREEN}ok ${BLUE}]${NORMAL}\n" else printf "${UP}${START} ${RED}*${NORMAL}${END}[${RED}fail${NORMAL}]\n" fi else if [ "$1" -eq 0 ]; then printf " ...done.\n" else printf " ...fail!\n" fi fi return "$1" }