home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Linux / Ubuntu_64-bit / ubuntu-11.04-desktop-amd64.iso / casper / filesystem.squashfs / etc / lsb-base-logging.sh < prev    next >
Text File  |  2011-04-25  |  3KB  |  142 lines

  1. # Default init script logging functions suitable for Ubuntu.
  2. # See /lib/lsb/init-functions for usage help.
  3. LOG_DAEMON_MSG=""
  4.  
  5. log_use_plymouth () {
  6.     if [ "${loop:-n}" = y ]; then
  7.         return 1
  8.     fi
  9.     plymouth --ping >/dev/null 2>&1
  10. }
  11.  
  12. log_success_msg () {
  13.     echo " * $@"
  14. }
  15.  
  16. log_failure_msg () {
  17.     if log_use_fancy_output; then
  18.         RED=`$TPUT setaf 1`
  19.         NORMAL=`$TPUT op`
  20.         echo " $RED*$NORMAL $@"
  21.     else
  22.         echo " * $@"
  23.     fi
  24. }
  25.  
  26. log_warning_msg () {
  27.     if log_use_fancy_output; then
  28.         YELLOW=`$TPUT setaf 3`
  29.         NORMAL=`$TPUT op`
  30.         echo " $YELLOW*$NORMAL $@"
  31.     else
  32.         echo " * $@"
  33.     fi
  34. }
  35.  
  36. log_begin_msg () {
  37.     log_daemon_msg "$1"
  38. }
  39.  
  40. log_daemon_msg () {
  41.     if [ -z "$1" ]; then
  42.         return 1
  43.     fi
  44.  
  45.     if log_use_fancy_output && $TPUT xenl >/dev/null 2>&1; then
  46.         COLS=`$TPUT cols`
  47.         if [ "$COLS" ] && [ "$COLS" -gt 6 ]; then
  48.             COL=`$EXPR $COLS - 7`
  49.         else
  50.             COLS=80
  51.             COL=73
  52.         fi
  53.  
  54.         if log_use_plymouth; then
  55.             # If plymouth is running, don't output anything at this time
  56.             # to avoid buffering problems (LP: #752393)
  57.             if [ -z "$LOG_DAEMON_MSG" ]; then
  58.                 LOG_DAEMON_MSG=$*
  59.                 return
  60.             fi
  61.         fi
  62.  
  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 [ "$COL" ] && [ -x "$TPUT" ]; then
  96.         # If plymouth is running, print previously stored output
  97.         # to avoid buffering problems (LP: #752393)
  98.         if log_use_plymouth; then
  99.             if [ -n "$LOG_DAEMON_MSG" ]; then
  100.                 log_daemon_msg $LOG_DAEMON_MSG
  101.                 LOG_DAEMON_MSG=""
  102.             fi
  103.         fi
  104.  
  105.         printf "\r"
  106.         $TPUT hpa $COL
  107.         if [ "$1" -eq 0 ]; then
  108.             echo "[ OK ]"
  109.         else
  110.             printf '['
  111.             $TPUT setaf 1 # red
  112.             printf fail
  113.             $TPUT op # normal
  114.             echo ']'
  115.         fi
  116.     else
  117.         if [ "$1" -eq 0 ]; then
  118.             echo "   ...done."
  119.         else
  120.             echo "   ...fail!"
  121.         fi
  122.     fi
  123.     return $1
  124. }
  125.  
  126. log_action_msg () {
  127.     echo " * $@"
  128. }
  129.  
  130. log_action_begin_msg () {
  131.     log_daemon_msg "$@..."
  132. }
  133.  
  134. log_action_cont_msg () {
  135.     log_daemon_msg "$@..."
  136. }
  137.  
  138. log_action_end_msg () {
  139.     # In the future this may do something with $2 as well.
  140.     log_end_msg "$1" || true
  141. }
  142.