diff options
Diffstat (limited to 'issues/display')
-rwxr-xr-x | issues/display | 74 |
1 files changed, 60 insertions, 14 deletions
diff --git a/issues/display b/issues/display index 6c16166..70f9dca 100755 --- a/issues/display +++ b/issues/display @@ -1,4 +1,13 @@ #!/usr/bin/env bash + +MYTDIR="$(mktemp -d --tmpdir osissue.XXXXXX)" || exit 1 +MYPWD="$(cd "$(dirname "$0")" && pwd)" || exit 2 +function ctrl_c { + if [ ! -z "$MYTDIR" ]; then + rm -rf "$MYTDIR" + fi + exit 130 +} if [ -n "$1" ];then FARR="$1" if [ ! -e "$FARR" ];then FARR="$FARR.issue";fi @@ -7,18 +16,55 @@ else FARR=( $(ls *.issue) "issue.blank.1" "issue.blank.2" ) unset IFS fi -for i in "${FARR[@]}";do - IFS=$'\n' - FLARR=( $(cat "$i") ) - unset IFS - if [ -z "$COLUMNS" ];then - COLUMNS="$(tput cols)" - [ -z "$COLUMNS" ] && COLUMNS=20 +if [ -r "/etc/os-release" ]; then + source "/etc/os-release" +fi +if [ -n "$VARIABLE" ]; then + OSSTR_S="$VARIABLE" +elif [ -n "$PRETTY_NAME" ]; then + OSSTR_S="$PRETTY_NAME" +else + OSSTR_S="$(uname -o)" +fi +OSSTR_M="$(uname -m)" +OSSTR_R="$(uname -r)" +OSSTR_N="$(uname -n)" +OSSTR_L="$(tty | sed 's#^/dev/##')" +# see man:agetty(8), ... kinda: we don't have e.g. 4{IFACENAME} anywhere, so we only do the +# argumentless variants +OSSTR_4="$(ip -4 -o address show nomaster primary scope global up | head -n 1 | awk '{print $4}' | awk -F/ '{print $1}')" +if [ -z "$OSSTR_4" ]; then + OSSTR_4="$(getent ahostsv4 "$(hostname -s)" | head -n1 | awk '{print $1}')" + if [ -z "$OSSTR_4" ]; then OSSTR_4="127.0.0.1"; fi +fi +OSSTR_6="$(ip -6 -o address show nomaster primary scope global up | head -n 1 | awk '{print $4}' | awk -F/ '{print $1}')" +if [ -z "$OSSTR_6" ]; then + OSSTR_6="$(getent ahostsv6 "$(hostname -s)" | head -n1 | awk '{print $1}')" + if [ -z "$OSSTR_6" ]; then + # this could now be a number of reasons, we act as if IPv6 had been deactivated + OSSTR_6="::ffff:127.0.1.1" fi - printf "\\033[;1m" - for ((j=0;j<$COLUMNS;++j)); do printf -- "-"; done - printf "\\n %b\\n" "$i" - for ((j=0;j<$COLUMNS;++j)); do printf -- "-"; done - printf "\\033[0m\\n" - printf "%b\\n" "${FLARR[@]}" -done +fi +( + cd "$MYPWD" || exit 10 + for issuefile in "${FARR[@]}";do + cp -p "$issuefile" "${MYTDIR}/" || break + sed -i "s#\\\\S#$OSSTR_S#;s#\\\\m#$OSSTR_M#;s#\\\\l#$OSSTR_L#" "${MYTDIR}/${issuefile}" &&\ + sed -i "s#\\\\4#$OSSTR_4#;s#\\\\6#$OSSTR_6#" "${MYTDIR}/${issuefile}" &&\ + sed -i "s#\\\\r#$OSSTR_R#;s#\\\\n#$OSSTR_N#" "${MYTDIR}/${issuefile}" || break + IFS=$'\n' + FLARR=( $(cat "${MYTDIR}/${issuefile}") ) + unset IFS + if [ -z "$COLUMNS" ];then + COLUMNS="$(tput cols)" + [ -z "$COLUMNS" ] && COLUMNS=20 + fi + printf "\\033[;1m" + for ((j=0;j<$COLUMNS;++j)); do printf -- "-"; done + printf "\\n %b\\n" "$issuefile" + for ((j=0;j<$COLUMNS;++j)); do printf -- "-"; done + printf "\\033[0m\\n" + printf "%b\\n" "${FLARR[@]}" + done +) +rm -rf "$MYTDIR" |