#!/bin/sh # Begin /etc/init.d/functions # log file, set to /dev/null if you don't want one #INITLOG=/var/log/boot.log INITLOG=/dev/null # Set onlcr to avoid staircase effect. stty onlcr 0>&1 # Echo with color echoc() { if [ "$RCINITCOLORS" = "NO" ] ; then echo "$1" else case "$2" in black) echo "$1" ;; red) echo "$1" ;; green) echo "$1" ;; yellow) echo "$1" ;; blue) echo "$1" ;; magenta) echo "$1" ;; cyan) echo "$1" ;; white) echo "$1" ;; *) echo "$1" ;; esac fi } ## Echo not newline echon() { echo -n $* } # Echo and log not newline echonl() { echo -n $* echo -n $* >> $INITLOG } # Echo and log echol() { echo $* echo $* >> $INITLOG } # Echo color and log echocl() { echoc "$1" $2 echo "$1" >> $INITLOG } evaluate_retvall() { evaluate_retval | tee -a $INITLOG } # Set a few variables that influence the text that's printed on the # screen. The SET_COL variable starts the text in column number 70 (as # defined by the COL variable). NORMAL prints text in normal mode. # SUCCESS prints text in a green colour and FAILURE prints text in a red # colour # COL=70 SET_COL="echo -en \\033[${COL}G" NORMAL="echo -en \\033[0;39m" SUCCESS="echo -en \\033[1;32m" FAILURE="echo -en \\033[1;31m" # # The evaluate_retval function evaluates the return value of the process # that was run just before this function was called. If the return value # was 0, indicating success, the print_status function is called with # the 'success' parameter. Otherwise the print_status function is called # with the failure parameter. # evaluate_retval() { if [ $? = 0 ] then print_status success else print_status failure fi } # # The print_status prints [ OK ] or [FAILED] to the screen. OK appears # in the colour defined by the SUCCESS variable and FAILED appears in # the colour defined by the FAILURE variable. Both are printed starting # in the column defined by the COL variable. # print_status() { # # If no parameters are given to the print_status function, print usage # information. # if [ $# = 0 ] then echo "Usage: print_status {success|failure}" return 1 fi case "$1" in success) $SET_COL echo -n "[ " $SUCCESS echo -n "OK" $NORMAL echo " ]" ;; failure) $SET_COL echo -n "[" $FAILURE echo -n "FAILED" $NORMAL echo "]" ;; esac } # End /etc/init.d/functions