From: Didier Raboud Date: Mon, 20 Feb 2012 21:58:29 +0000 (+0100) Subject: Install lsb-base-logging.sh on Ubuntu. X-Git-Tag: archive/raspbian/10.2018112800+rpi1^2~186 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8943fdb2f35295da4edd27deecfceeb7242f097b;p=lsb.git Install lsb-base-logging.sh on Ubuntu. Signed-off-by: Didier Raboud --- diff --git a/debian/rules b/debian/rules index 599f64e..d923da5 100755 --- a/debian/rules +++ b/debian/rules @@ -1,5 +1,7 @@ #!/usr/bin/make -f +derives_from_ubuntu := $(shell (dpkg-vendor --derives-from Ubuntu && echo "yes") || echo "no") + %: dh --with python2 $@ @@ -46,6 +48,12 @@ override_dh_python2: dh_python2 dh_python2 /usr/lib/lsb +override_dh_install: + dh_install +ifeq ($(derives_from_ubuntu),yes) + cp -p lsb-base-logging-ubuntu.sh debian/lsb-base/etc/lsb-base-logging.sh +endif + override_dh_gencontrol: @echo >> debian/lsb-core.substvars "glibc=${LIBC}" # @[ ${DEB_HOST_GNU_TYPE} != 'arm-linux-gnueabi' ] && echo >> debian/lsb-cxx.substvars "depends=libstdc++5" || true diff --git a/lsb-base-logging-ubuntu.sh b/lsb-base-logging-ubuntu.sh new file mode 100644 index 0000000..ac22357 --- /dev/null +++ b/lsb-base-logging-ubuntu.sh @@ -0,0 +1,141 @@ +# Default init script logging functions suitable for Ubuntu. +# See /lib/lsb/init-functions for usage help. +LOG_DAEMON_MSG="" + +log_use_plymouth () { + if [ "${loop:-n}" = y ]; then + return 1 + fi + plymouth --ping >/dev/null 2>&1 +} + +log_success_msg () { + echo " * $@" +} + +log_failure_msg () { + if log_use_fancy_output; then + RED=`$TPUT setaf 1` + NORMAL=`$TPUT op` + echo " $RED*$NORMAL $@" + else + echo " * $@" + fi +} + +log_warning_msg () { + if log_use_fancy_output; then + YELLOW=`$TPUT setaf 3` + NORMAL=`$TPUT op` + echo " $YELLOW*$NORMAL $@" + else + echo " * $@" + fi +} + +log_begin_msg () { + log_daemon_msg "$1" +} + +log_daemon_msg () { + if [ -z "$1" ]; then + return 1 + fi + + if log_use_fancy_output && $TPUT xenl >/dev/null 2>&1; then + COLS=`$TPUT cols` + if [ "$COLS" ] && [ "$COLS" -gt 6 ]; then + COL=`$EXPR $COLS - 7` + else + COLS=80 + COL=73 + fi + + if log_use_plymouth; then + # If plymouth is running, don't output anything at this time + # to avoid buffering problems (LP: #752393) + if [ -z "$LOG_DAEMON_MSG" ]; then + LOG_DAEMON_MSG=$* + return + fi + fi + + # We leave the cursor `hanging' about-to-wrap (see terminfo(5) + # xenl, which is approximately right). That way if the script + # prints anything then we will be on the next line and not + # overwrite part of the message. + + # Previous versions of this code attempted to colour-code the + # asterisk but this can't be done reliably because in practice + # init scripts sometimes print messages even when they succeed + # and we won't be able to reliably know where the colourful + # asterisk ought to go. + + printf " * $* " + # Enough trailing spaces for ` [fail]' to fit in; if the message + # is too long it wraps here rather than later, which is what we + # want. + $TPUT hpa `$EXPR $COLS - 1` + printf ' ' + else + echo " * $@" + COL= + fi +} + +log_progress_msg () { + : +} + +log_end_msg () { + if [ -z "$1" ]; then + return 1 + fi + + if [ "$COL" ] && [ -x "$TPUT" ]; then + # If plymouth is running, print previously stored output + # to avoid buffering problems (LP: #752393) + if log_use_plymouth; then + if [ -n "$LOG_DAEMON_MSG" ]; then + log_daemon_msg $LOG_DAEMON_MSG + LOG_DAEMON_MSG="" + fi + fi + + printf "\r" + $TPUT hpa $COL + if [ "$1" -eq 0 ]; then + echo "[ OK ]" + else + printf '[' + $TPUT setaf 1 # red + printf fail + $TPUT op # normal + echo ']' + fi + else + if [ "$1" -eq 0 ]; then + echo " ...done." + else + echo " ...fail!" + fi + fi + return $1 +} + +log_action_msg () { + echo " * $@" +} + +log_action_begin_msg () { + log_daemon_msg "$@..." +} + +log_action_cont_msg () { + log_daemon_msg "$@..." +} + +log_action_end_msg () { + # In the future this may do something with $2 as well. + log_end_msg "$1" || true +}