Skip to content

Instantly share code, notes, and snippets.

@vdavez
Last active February 22, 2017 12:31
Show Gist options
  • Save vdavez/e32d334286634a094e3dcfdb7647fa8b to your computer and use it in GitHub Desktop.
Save vdavez/e32d334286634a094e3dcfdb7647fa8b to your computer and use it in GitHub Desktop.
BMR scripts
#!/bin/bash
# Usage: ./checksums.sh [BMR_number]
# Example: ./checksums.sh BMR_0182
# Initialize the checksums array...
checksums=()
# Loop through the BMR files
IFS=$'\n';for file in $(find $1 -name '*.jpg' -or -name '*.png'); do
if [[ -f "$file" && ! -L "$file" ]]; then
# Get the hash.
shasum=$(shasum -b $file)
hash=${shasum%% *}
# Check to see if it's in the checksum list
match=0;
for i in "${checksums[@]}"; do
# If in checksum list, say "MATCH!" and skip
if [ "$i" == "$hash" ] ; then
echo "MATCH! Found $hash and therefore skipping upload to s3"
match=1
fi;
done;
# If it was not in the checksum list, do whatever we *planned* to do
# with file. In this case, load to S3...
if [ "$match" -eq 0 ]; then
checksums+=("$hash")
# S3 code to go here..
fi;
fi;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment