Support systemd-style output via lsb-functions
authorMichael Prokop <mika@grml.org>
Fri, 13 Jan 2017 12:38:58 +0000 (13:38 +0100)
committerMichael Prokop <mika@grml.org>
Fri, 13 Jan 2017 12:41:27 +0000 (13:41 +0100)
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
etc/grml_colors

index d95be1d..d6513db 100644 (file)
 # 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
index 77cb8ba..a78a9ab 100644 (file)
@@ -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="\r\e[K"
 NORMAL="\e[0;39m"
 # RED: Failure or error message
-RED="\e[1;31m"
+RED="\e[${HIGHLIGHT};31m"
 # GREEN: Success message
-GREEN="\e[1;32m"
+GREEN="\e[${HIGHLIGHT};32m"
 # YELLOW: Descriptions
-YELLOW="\e[1;33m"
+YELLOW="\e[${HIGHLIGHT};33m"
 # BLUE: System messages
-BLUE="\e[1;34m"
+BLUE="\e[${HIGHLIGHT};34m"
 # MAGENTA: Found devices or drivers
-MAGENTA="\e[1;35m"
+MAGENTA="\e[${HIGHLIGHT};35m"
 # CYAN: Questions
-CYAN="\e[1;36m"
+CYAN="\e[${HIGHLIGHT};36m"
 # BOLD WHITE: Hint
-WHITE="\e[1;37m"
+WHITE="\e[${HIGHLIGHT};37m"
+
+# don't expose unneeded local variables
+unset HIGHLIGHT
 
 ## END OF FILE #################################################################