home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / etc / lsb-base-logging.sh < prev    next >
Encoding:
Text File  |  2006-05-18  |  3.1 KB  |  145 lines

  1. # Default init script logging functions suitable for Ubuntu.
  2. # See /lib/lsb/init-functions for usage help.
  3.  
  4. log_use_usplash () {
  5.     type usplash_write >/dev/null 2>&1
  6. }
  7.  
  8. log_success_msg () {
  9.     if log_use_usplash; then
  10.         usplash_write "STATUS $*" || true
  11.     fi
  12.     echo " * $@"
  13. }
  14.  
  15. log_failure_msg () {
  16.     if log_use_usplash; then
  17.         usplash_write "STATUS $*" || true
  18.     fi
  19.  
  20.     if log_use_fancy_output; then
  21.         RED=`$TPUT setaf 1`
  22.         NORMAL=`$TPUT op`
  23.         echo " $RED*$NORMAL $@"
  24.     else
  25.         echo " * $@"
  26.     fi
  27. }
  28.  
  29. log_warning_msg () {
  30.     if log_use_usplash; then
  31.         usplash_write "STATUS $*" || true
  32.     fi
  33.  
  34.     if log_use_fancy_output; then
  35.         YELLOW=`$TPUT setaf 3`
  36.         NORMAL=`$TPUT op`
  37.         echo " $YELLOW*$NORMAL $@"
  38.     else
  39.         echo " * $@"
  40.     fi
  41. }
  42.  
  43. log_begin_msg () {
  44.     log_daemon_msg "$1"
  45. }
  46.  
  47. log_daemon_msg () {
  48.     if [ -z "$1" ]; then
  49.         return 1
  50.     fi
  51.  
  52.     if log_use_usplash; then
  53.         usplash_write "TEXT $*" || true
  54.     fi
  55.  
  56.     if log_use_fancy_output && $TPUT xenl >/dev/null 2>&1; then
  57.         COLS=`$TPUT cols`
  58.         if [ "$COLS" ]; then
  59.             COL=`$EXPR $COLS - 7`
  60.         else
  61.             COL=73
  62.         fi
  63.         # We leave the cursor `hanging' about-to-wrap (see terminfo(5)
  64.         # xenl, which is approximately right). That way if the script
  65.         # prints anything then we will be on the next line and not
  66.         # overwrite part of the message.
  67.  
  68.         # Previous versions of this code attempted to colour-code the
  69.         # asterisk but this can't be done reliably because in practice
  70.         # init scripts sometimes print messages even when they succeed
  71.         # and we won't be able to reliably know where the colourful
  72.         # asterisk ought to go.
  73.  
  74.         printf " * $*       "
  75.         # Enough trailing spaces for ` [fail]' to fit in; if the message
  76.         # is too long it wraps here rather than later, which is what we
  77.         # want.
  78.         $TPUT hpa `$EXPR $COLS - 1`
  79.         printf ' '
  80.     else
  81.         echo " * $@"
  82.         COL=
  83.     fi
  84. }
  85.  
  86. log_progress_msg () {
  87.     :
  88. }
  89.  
  90. log_end_msg () {
  91.     if [ -z "$1" ]; then
  92.         return 1
  93.     fi
  94.  
  95.     if log_use_usplash; then
  96.         if [ "$1" -eq 0 ]; then
  97.             usplash_write "SUCCESS ok" || true
  98.         else
  99.             usplash_write "FAILURE failed" || true
  100.         fi
  101.     fi
  102.  
  103.     if [ "$COL" ] && [ -x "$TPUT" ]; then
  104.         printf "\r"
  105.         $TPUT hpa $COL
  106.         if [ "$1" -eq 0 ]; then
  107.             echo "[ ok ]"
  108.         else
  109.             printf '['
  110.             $TPUT setaf 1  # red
  111.             printf fail
  112.             $TPUT op  # normal
  113.             echo ']'
  114.         fi
  115.     else
  116.         if [ "$1" -eq 0 ]; then
  117.             echo "   ...done."
  118.         else
  119.             echo "   ...fail!"
  120.         fi
  121.     fi
  122.     return $1
  123. }
  124.  
  125. log_action_msg () {
  126.     if log_use_usplash; then
  127.         usplash_write "TEXT $*" || true
  128.     fi
  129.  
  130.     echo " * $@"
  131. }
  132.  
  133. log_action_begin_msg () {
  134.     log_daemon_msg "$@..."
  135. }
  136.  
  137. log_action_cont_msg () {
  138.     log_daemon_msg "$@..."
  139. }
  140.  
  141. log_action_end_msg () {
  142.     # In the future this may do something with $2 as well.
  143.     log_end_msg "$1"
  144. }
  145.