Created
June 8, 2013 15:33
-
-
Save mauron85/5735526 to your computer and use it in GitHub Desktop.
OS X version of ipfilter.dat updater
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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