diff --git a/doesItNeedUpdating.sh b/doesItNeedUpdating.sh new file mode 100644 index 0000000000000000000000000000000000000000..784dc256f15d74df97c088b24a608794f718c9ea --- /dev/null +++ b/doesItNeedUpdating.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# TRACKDIR is the place where downloaded content and checkums are stored +TRACKDIR=/usr/local/lib/doesItNeedUpdating + +URL=$1 +MAILTO=$2 + +mkdir -p $TRACKDIR +if [ $? -ne 0 ]; then + echo "Error, can't make my tracking directory $TRACKDIR. It is needed to remember changes on tracked ressources" + exit 1 +fi + +echo $URL | grep -q -e "^.*tp.*://" +if [ $? -ne 0 ]; then + echo "No http/https/ftp detected in provided URL..." + exit 1 +fi + +if [ "x$MAILTO\x" == "x\x" ]; then + MAILTO=root@localhost +fi + +cd $TRACKDIR + +# Extract item name from URL +item=`echo $URL | sed 's/.*\///g'` + +wget --quiet $URL +if [ $? -ne 0 ]; then + echo "Error: can't download $URL" + exit 1 +fi + +# On first run, nothing to compare +if [ ! -f $item.sha256 ]; then + sha256sum $item > $item.sha256 + rm -f $item + exit 0 +fi + +sha256sum $item > $item.$$.sha256 + +current=`cat $item.$$.sha256 | awk '{print $1}'` +previous=`cat $item.sha256 | awk '{print $1}'` + +if [ ! "$current" = "$previous" ]; then + # different content: update ! + echo "Detected a change in $item ... you may need to update upgrade ($URL)" | mail -s "[doesItNeedUpdating] $item" $MAILTO + rm -f $item.sha256 + mv $item.$$.sha256 $item.sha256 +fi + +rm -f $item $item.$$.sha256 + +exit 0