From aaa1e7fa0cf1a864cb163b212c9b9b8a8488541d Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Fri, 13 Jan 2017 13:38:58 +0100 Subject: [PATCH] Support systemd-style output via lsb-functions By properly hooking into /etc/grml/lsb-functions we can get systemd like output without having to rewrite any further scripts. Adjust /etc/grml_colors to have same color style (non-highlighted colors) as systemd iff running under systemd. --- etc/grml/lsb-functions | 29 +++++++++++++++++++++++++++++ etc/grml_colors | 24 +++++++++++++++++------- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/etc/grml/lsb-functions b/etc/grml/lsb-functions index d95be1d..d6513db 100644 --- a/etc/grml/lsb-functions +++ b/etc/grml/lsb-functions @@ -30,6 +30,12 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. +if [ "$(cat /proc/1/comm 2>/dev/null)" = "systemd" ] ; then + SYSTEMD=true +else + SYSTEMD=false +fi + # log_*() functions {{{ TPUT="${TPUT:-"/usr/bin/tput"}" @@ -408,4 +414,27 @@ ewend() { } #}}} +# if we're using systemd then redfine functions for +# output in systemd style +if $SYSTEMD ; then + einfo() { + printf "[ ${GREEN}OK${NORMAL} ] %s\n" "$*" + } + + ewarn() { + printf "[ ${YELLOW}WARN${NORMAL} ] %s\n" "$*" + } + + eerror() { + printf "[ ${RED}FAIL${NORMAL} ] %s\n" "$*" + } + + eend() { + : + } +fi + +# don't expose unneeded local variables +unset SYSTEMD + # vim: ft=sh tw=80 ts=4 foldmethod=marker diff --git a/etc/grml_colors b/etc/grml_colors index 77cb8ba..a78a9ab 100644 --- a/etc/grml_colors +++ b/etc/grml_colors @@ -5,22 +5,32 @@ # License: This file is licensed under the GPL v2. ################################################################################ +# don't use highlighed colors under systemd to match its style +if [ "$(cat /proc/1/comm 2>/dev/null)" = "systemd" ] ; then + HIGHLIGHT=0 +else + HIGHLIGHT=1 +fi + # ANSI COLORS CRE=" " NORMAL="" # RED: Failure or error message -RED="" +RED="[${HIGHLIGHT};31m" # GREEN: Success message -GREEN="" +GREEN="[${HIGHLIGHT};32m" # YELLOW: Descriptions -YELLOW="" +YELLOW="[${HIGHLIGHT};33m" # BLUE: System messages -BLUE="" +BLUE="[${HIGHLIGHT};34m" # MAGENTA: Found devices or drivers -MAGENTA="" +MAGENTA="[${HIGHLIGHT};35m" # CYAN: Questions -CYAN="" +CYAN="[${HIGHLIGHT};36m" # BOLD WHITE: Hint -WHITE="" +WHITE="[${HIGHLIGHT};37m" + +# don't expose unneeded local variables +unset HIGHLIGHT ## END OF FILE ################################################################# -- 2.1.4