Skip to content

Commit

Permalink
Support systemd-style output via lsb-functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mika committed Jan 13, 2017
1 parent 1ce2c6d commit aaa1e7f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
29 changes: 29 additions & 0 deletions etc/grml/lsb-functions
Expand Up @@ -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"}"

Expand Down Expand Up @@ -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
24 changes: 17 additions & 7 deletions etc/grml_colors
Expand Up @@ -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 #################################################################
Expand Down

0 comments on commit aaa1e7f

Please sign in to comment.