Support systemd-style output via lsb-functions
[grml-etc-core.git] / etc / grml / lsb-functions
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