2017-08-24 18:38:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# Util to pretty-print logfile of NetworkManager
|
|
|
|
|
#
|
|
|
|
|
# Unless setting NM_LOG_NO_COLOR it will colorize the output.
|
|
|
|
|
# Suppress coloring with:
|
|
|
|
|
# $ NM_LOG_NO_COLOR=1 NM-log ...
|
|
|
|
|
#
|
|
|
|
|
# If called without arguments, it either reads from stdin (if not
|
|
|
|
|
# connected to a terminal) or it shows the journal content.
|
|
|
|
|
#
|
|
|
|
|
# If called with first argument "j", it always shows the journal content.
|
|
|
|
|
#
|
|
|
|
|
# You can pass multiple filenames.
|
|
|
|
|
|
2017-09-07 13:58:31 +02:00
|
|
|
if [[ "$_" == "$0" ]]; then
|
|
|
|
|
NM_not_sourced=1
|
|
|
|
|
else
|
|
|
|
|
unset NM_not_sourced
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
NM-show-journal() {
|
2017-08-24 18:38:34 +02:00
|
|
|
local since="$(systemctl show NetworkManager | sed -n 's/^ExecMainStartTimestamp=\(.*\) [A-Z0-9]\+$/\1/p')"
|
|
|
|
|
|
|
|
|
|
if [[ "$since" == "" ]]; then
|
|
|
|
|
echo "error detecting NM. Is it running?"
|
|
|
|
|
systemctl status NetworkManager
|
|
|
|
|
else
|
|
|
|
|
exec journalctl -o short-precise --since "$since" -b 0 -u NetworkManager "$@"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 13:58:31 +02:00
|
|
|
NM-colorize() {
|
2017-08-24 18:38:34 +02:00
|
|
|
if [[ "$NM_LOG_NO_COLOR" == "" ]]; then
|
2017-09-07 13:58:31 +02:00
|
|
|
# poor man's coloring using grep.
|
|
|
|
|
# TODO: do it somehow better (and more efficient).
|
|
|
|
|
GREP_COLOR='01;33' grep -a --color=always '^\|^\(.* \)\?<\(warn>\|info> \|error>\) \(.*\<is starting\>.*$\)\?' | \
|
|
|
|
|
GREP_COLOR='01;37' grep -a --color=always '^\|\<platform: signal: .*$' | \
|
|
|
|
|
GREP_COLOR='01;34' grep -a --color=always '^\|\<platform-linux: link: change \|\<platform: link: setting .*$\|\<platform: \(route\|address\): .*$\|\<platform-linux: sysctl: setting .*$' | \
|
|
|
|
|
GREP_COLOR='01;35' grep -a --color=always '^\| audit: .*$' | \
|
|
|
|
|
GREP_COLOR='01;32' grep -a --color=always '^\|\<device (.*): state change: '
|
2017-08-24 18:38:34 +02:00
|
|
|
else
|
2017-09-07 13:58:31 +02:00
|
|
|
/usr/bin/cat -
|
2017-08-24 18:38:34 +02:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 13:58:31 +02:00
|
|
|
NM-log() {
|
|
|
|
|
(
|
|
|
|
|
if [ "$1" == "j" ]; then
|
|
|
|
|
shift
|
|
|
|
|
NM-show-journal "$@"
|
|
|
|
|
elif [ "$#" -eq 0 -a -t 0 ]; then
|
|
|
|
|
NM-show-journal
|
|
|
|
|
else
|
|
|
|
|
a="${1--}"
|
|
|
|
|
shift
|
|
|
|
|
/usr/bin/cat "$a" "$@"
|
|
|
|
|
fi
|
|
|
|
|
) | \
|
|
|
|
|
NM-colorize | \
|
|
|
|
|
LESS=FRSXMK exec less -R
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [[ "$NM_not_sourced" != "" ]]; then
|
|
|
|
|
NM-log "$@"
|
|
|
|
|
fi
|