#!/bin/bash
if [ $# != 2 ]
then echo "Usage: ./ThreadCheck.sh forum_address thread_extension"
exit
fi

if [ ! -d $HOME/.ThreadCheck ]
then
mkdir $HOME/.ThreadCheck
fi

cd $HOME/.ThreadCheck

echo "Downloading thread file"
rm $2 > /dev/null 2>&1
wget $1$2 > /dev/null 2>&1
echo "File downloaded, checking for new posts"

grep Showing $2 > NewPosts

if [ ! -s NewPosts ]
then grep '<table id="post' $2 | wc -l > NewPosts
fi

if [ -s CurPosts ]

then
if cmp NewPosts CurPosts | grep differ; #> /dev/null 2>&1;
then 
echo "New post(s)!"
x-www-browser $1$2"&goto=newpost" &
cp -T NewPosts CurPosts
else
echo "No new posts."
fi

else
echo "New thread!"
x-www-browser $1$2"&goto=newpost" &

fi

cp NewPosts CurPosts
# rm NewPosts $1