Track updates - mlt/swat GitHub Wiki

Simple job can be scheduled via cron using crontab -e like @daily /home/mlt/Downloads/swat/get_swat.sh where get_swat.sh is shown below.

#!/bin/sh

DIR=$(dirname $0)
pushd $DIR > /dev/null

LINE=$(curl http://swat.tamu.edu/software/swat-model/ 2>/dev/null | grep _code)
# grep on windows somehow does not know -o
CUR=$(echo $LINE | perl -ne '/(...)_code.zip/ && print $1')
LAST=$(<last)
LAST=${LAST:-"0"}
if test $CUR -ne $LAST ; then
  URL=$(echo $LINE | perl -ne '/href="(.+?_code.zip)/ && print "http://swat.tamu.edu" . $1')
  echo Found new revision $URL
  curl -O $URL
  echo $CUR > last
fi

popd > /dev/null