Blame src/cli/abrt-console-notification.sh

Packit 8ea169
#!/bin/sh
Packit 8ea169
# If shell is not connect to a terminal, return immediately, because this script
Packit 8ea169
# should print out ABRT's status and it is senseless to continue without
Packit 8ea169
# terminal.
Packit 8ea169
tty -s || return 0
Packit 8ea169
Packit 8ea169
# Skip all for noninteractive shells for the same reason as above.
Packit 8ea169
[ -z "$PS1" ] && return 0
Packit 8ea169
Packit 8ea169
# If $HOME is not set, a non human user is logging in to shell but this script
Packit 8ea169
# should provide information to human users, therefore returning immediately
Packit 8ea169
# without showing the notification.
Packit 8ea169
if [ -z "$HOME" ]; then
Packit 8ea169
    return 0
Packit 8ea169
fi
Packit 8ea169
Packit 8ea169
if [ -z "$ABRT_DEBUG_LOG" ]; then
Packit 8ea169
    ABRT_DEBUG_LOG="/dev/null"
Packit 8ea169
fi
Packit 8ea169
Packit 8ea169
LPATHDIR="$HOME/.cache/abrt"
Packit 8ea169
SINCEFILE="$LPATHDIR/lastnotification"
Packit 8ea169
Packit 8ea169
if [ ! -f "$LPATHDIR" ]; then
Packit 8ea169
    # It might happen that user doesn't have write access on his home.
Packit 8ea169
    mkdir -p "$LPATHDIR" >"$ABRT_DEBUG_LOG" 2>&1 || return 0
Packit 8ea169
fi
Packit 8ea169
Packit 8ea169
TMPPATH=$(mktemp --tmpdir="$LPATHDIR" lastnotification.XXXXXXXX 2> "$ABRT_DEBUG_LOG")
Packit 8ea169
Packit 8ea169
SINCE=0
Packit 8ea169
if [ -f "$SINCEFILE" ]; then
Packit 8ea169
    SINCE=$(cat "$SINCEFILE" 2>"$ABRT_DEBUG_LOG")
Packit 8ea169
fi
Packit 8ea169
Packit 8ea169
# always update the lastnotification
Packit 8ea169
if [ -f "$TMPPATH" ]; then
Packit 8ea169
    # Be quite in case of errors and don't scare users by strange error messages.
Packit 8ea169
    date +%s > "$TMPPATH" 2>"$ABRT_DEBUG_LOG"
Packit 8ea169
    mv -f "$TMPPATH" "$SINCEFILE" >"$ABRT_DEBUG_LOG" 2>&1
Packit 8ea169
fi
Packit 8ea169
Packit 8ea169
timeout 10s abrt-cli status --since="$SINCE" 2>"$ABRT_DEBUG_LOG" || echo "'abrt-cli status' timed out"
Packit 8ea169
Packit 8ea169
unset ABRT_DEBUG_LOG LPATHDIR SINCEFILE TMPPATH SINCE