Use $* instead of "$@" when your arguments will not have spaces.
Instead of
! -f
in the if condition, use
-f
and swap the then and else blocks.
Use != instead of the ! == thing.
Use /bin/sh instead of bash if you can (and you absolutely can here).
Backticks are bad form, and aren't really nestable. Use proper command substitution.
You probably should not use absolute paths, instead opting to fix your cron environment so that PATH is set right, in case somebody has curl somewhere else.
getopts is always nice, and every program as a baseline should have some sort of usage message.
GNU indent style is gross.
This is a bit better (works in Linux with -c md5sum and -n notify-send, when they are installed. You may need to add your dbus export stuff to get notify-send to work right. You can add options to the notify-program, to eg. get notify-send to persist the notification with its own options):
#!/bin/sh
NOTIFY=say
CHECKSUM=md5
USAGE="$0 { -c [hash program] } { -n [notify program] }"
while getopts 'c:hn:' opt; do
case "$opt" in
c)
CHECKSUM="$OPTARG"
;;
n)
NOTIFY="$OPTARG"
;;
h)
echo "$USAGE"
exit 0
;;
?)
echo "$USAGE"
exit 1
;;
esac
done
shift $(($OPTIND - 1))
for board in $*; do
HASH="$(curl --silent http://8ch.net/$board/0.json | $CHECKSUM)"
TMPFILE="/tmp/${board}.hash"
if [ -f "$TMPFILE" ]; then
oldHash="$(cat $TMPFILE)"
if [ "x$oldHash" != "x$HASH" ]; then
echo $HASH > "$TMPFILE"
$NOTIFY "$board has a new post"
fi
else
echo "$HASH" > "$TMPFILE"
fi
done