forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecksum2filemaker
executable file
·32 lines (29 loc) · 1.53 KB
/
checksum2filemaker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# This script presumes that you've setup a filemaker database with Filemaker Server using a table called 'checksums' with fields according to the DFXML format.
version=1.0
SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
# check environment
[ -z "${FILEMAKER_DB}" ] && { echo "The filemaker database must be set. Run mmconfig to set FILEMAKER_DB." ; exit 1 ;};
[ -z "${FILEMAKER_XML_URL}" ] && { echo "The filemaker xml path must be set. Run mmconfig to set FILEMAKER_XML_URL." ; exit 1 ;};
while [ "${*}" != "" ] ; do
input="${1}"
if [[ ! -f "${input}/metadata/checksum.md5" ]] ; then
report -dt "${input} does not have a checksum.md5 file, skipping for $(basename "$input")"
shift
continue
fi
OLDIFS=$IFS
IFS=$'\n'
echo "Uploading checksum data for $(basename "$input"). Please wait…"
for hash in $(cat "${input}/metadata/checksum.md5"); do
if [[ "$hash" ]] ; then
hashinsert=$(echo "$hash" | awk '{ printf " --data-urlencode \"hashdigest=" $1 "\" --data-urlencode \"filename=" $NF "\" --data-urlencode \"hashdigest_type=MD5\"" }')" --data-urlencode \"source=$input\" --data-urlencode \"uniq="checksum.md5.${input}.${hash}.${1}"\""
hashcmd="curl -s -S -G $hashinsert \"http://${FILEMAKER_XML_URL}?-db=${FILEMAKER_DB}&-lay=checksums&-new\" 1>/dev/null"
eval "$hashcmd"
fi
done
IFS=$OLDIFS
echo "Done uploading metadata for $(basename "${1}")."
shift
done