Skip to content

Instantly share code, notes, and snippets.

@mauron85
Created June 8, 2013 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauron85/5735526 to your computer and use it in GitHub Desktop.
Save mauron85/5735526 to your computer and use it in GitHub Desktop.
OS X version of ipfilter.dat updater
#!/bin/bash
url="http://tbg.iblocklist.com/Lists/ipfilter.dat.gz"
tempDirectory="/tmp"
fileDirectory="/usr/local/var/ipfilter"
tgzfile=$(basename $url)
NAME=$(basename $0)
#get local
wget $url -O $tempDirectory/$tgzfile -o /dev/null && \
gunzip $tempDirectory/$tgzfile
if [ $? != 0 ] ; then
echo "erreur wget & gunzip" 2>&1
rm $tempDirectory/$tgzfile
/usr/bin/logger -p local0.err "$NAME: Error: wget & gunzip"
exit 1
fi
#compare
if [ -e $fileDirectory/$(basename $tgzfile .gz) ] && [ "$(md5 $fileDirectory/$(basename $tgzfile .gz) | awk '{printf $4}')" == "$(md5 $tempDirectory/$(basename $tgzfile .gz) | awk '{printf $4}')" ] ; then
echo "same hash - no change"
rm $tempDirectory/$(basename $tgzfile .gz) && \
/usr/bin/logger -p local0.notice "$NAME: same md5 hash - no change" && \
exit 0
else
echo "different hash - update new"
cp $tempDirectory/$(basename $tgzfile .gz) $fileDirectory/$(basename $tgzfile .gz) && \
rm $tempDirectory/$(basename $tgzfile .gz) && \
/usr/bin/logger -p local0.notice "$NAME: success update new ipfilter IP list" && \
exit 0
fi
echo "erreur" 2>&1
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment