allow per-user suppression of clinte notifications

If a user places a file at $HOME/.hushclinte, they will not be
notified of new posts on login.

Moved check logic to a function. Test if .hushclinte exists. If
it doesn't, run the announce function (check_clinte).

Also fixed a shellcheck error - unquoted variable expansion.
Changed string literals to single-quotes.
This commit is contained in:
Benjamin Morrison 2020-07-02 19:02:45 -04:00
parent e63da0b7e0
commit 9d8bbab3ce
Signed by untrusted user: gbmor
GPG Key ID: 8F192E4720BB0DAC
1 changed files with 21 additions and 15 deletions

View File

@ -1,20 +1,26 @@
#!/bin/sh
OS=$(uname)
check_clinte()
{
OS=$(uname)
LOCAL_FILE="$HOME/.clinte.json"
DBFILE='/usr/local/clinte/clinte.json'
LOCAL_FILE="$HOME/.clinte.json"
DBFILE="/usr/local/clinte/clinte.json"
if [ "$OS" = 'Linux' ]
then
LOCAL_HASH=$(sha256sum "$LOCAL_FILE" 2>/dev/null | cut -d' ' -f1)
DBFILE_HASH=$(sha256sum "$DBFILE" | cut -d' ' -f1)
else
LOCAL_HASH=$(sha256 "$LOCAL_FILE" 2>/dev/null | cut -d' ' -f1)
DBFILE_HASH=$(sha256 "$DBFILE" | cut -d' ' -f1)
fi
if [ "$LOCAL_HASH" != "$DBFILE_HASH" ]
then
printf '%s\n\n' 'New posts on clinte!'
fi
}
if [ $OS = "Linux" ]
then
LOCAL_HASH=$(sha256sum "$LOCAL_FILE" 2>/dev/null | cut -d' ' -f1)
DBFILE_HASH=$(sha256sum "$DBFILE" | cut -d' ' -f1)
else
LOCAL_HASH=$(sha256 "$LOCAL_FILE" 2>/dev/null | cut -d' ' -f1)
DBFILE_HASH=$(sha256 "$DBFILE" | cut -d' ' -f1)
fi
if [ "$LOCAL_HASH" != "$DBFILE_HASH" ]
then
printf "%s\n\n" "New posts on clinte!"
if [ ! -e "$HOME/.hushclinte" ]; then
check_clinte
fi