smart upload with hash check
[martlubbers.net.git] / put.bash
index 46ca44b..cd0b8fd 100644 (file)
--- a/put.bash
+++ b/put.bash
@@ -1,6 +1,18 @@
 #!/bin/bash
 set -e
-for f in $(find . -type f | grep -v "put\|/\.\|^\.$\|/$")
+for f in $(find . -type f -not -name "*hashes*" | grep -v "put\|/\.\|^\.$\|/$")
 do
-       curl -u $(gpg --use-agent -d ~/passwd.gpg | grep ftp-user | awk '{print $2":"$3}') -T $f ftp://martlubbers.net/public_html/$f
+       dir=$(dirname $f)
+       if [ "$(md5sum $f | awk '{print $1}')" = "$(grep $(basename $f) $dir/hashes.txt | awk '{print $1}')" ]
+       then
+               echo "$f didn't change..."
+       else
+               echo "$f did change..."
+               curl -u $(gpg --use-agent -d ~/passwd.gpg | grep ftp-user | awk '{print $2":"$3}') -T $f ftp://martlubbers.net/public_html/$f
+       fi
 done
+echo "recalculating hashes"
+md5sum ./* > hashes.txt
+cd files
+md5sum ./* > hashes.txt
+cd ..