Skip to content

Commit ad37593

Browse files
committed
Standardized variables and functions across all mm scripts.
1 parent 9524798 commit ad37593

31 files changed

+1906
-1904
lines changed

barcodeinterpret

+40-40
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
11
#!/bin/bash
22
# interpret Interleaved 2/5 barcode 58 byte barcode values used by the ProBell tape management system
33

4-
scriptdir=$(dirname "${0}")
5-
. "${scriptdir}/mmfunctions" || { echo "Missing '${scriptdir}/mmfunctions'. Exiting." ; exit 1 ;};
4+
SCRIPTDIR=$(dirname "${0}")
5+
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
66

7-
cleanup(){
7+
_cleanup(){
88
_log -a "Process aborted"
99
exit 1
1010
}
1111

12-
trap cleanup SIGHUP SIGINT SIGTERM
12+
trap _cleanup SIGHUP SIGINT SIGTERM
1313
_log -b
1414

15-
if test $# != 1 ; then
15+
if test "${#}" != 1 ; then
1616
echo "You must supply one argument, a scanned interleaved 2/5 barcode value"; exit
1717
fi
1818

19-
barcode="${1}"
19+
BARCODE="${1}"
2020

2121
translatebyte()
2222
{
23-
val=$(echo $1 | echo $(cut -c $2-$3) + 32 | bc)
24-
if [ "$val" = 131 ] ; then
25-
echo 9 | awk '{printf("%c", $0);}'
23+
VAL=$(echo $1 | echo $(cut -c $2-$3) + 32 | bc)
24+
if [ "${VAL}" = 131 ] ; then
25+
echo 9 | awk '{printf("%c", ${0});}'
2626
else
27-
echo $val | awk '{printf("%c", $0);}'
27+
echo "${VAL}" | awk '{printf("%c", ${0});}'
2828
fi
2929
}
30-
addcolons()
30+
_addcolons()
3131
{
32-
echo $(echo $1 | cut -c 1-2):$(echo $1 | cut -c 3-4):$(echo $1 | cut -c 5-6):$(echo $1 | cut -c 7-8)
32+
echo $(echo "${1}" | cut -c 1-2):$(echo "${1}" | cut -c 3-4):$(echo "${1}" | cut -c 5-6):$(echo "${1}" | cut -c 7-8)
3333
}
3434

35-
get_ids()
35+
_get_ids()
3636
{
37-
barcode=$1
38-
c00=$(translatebyte $barcode 2 3)
39-
c01=$(translatebyte $barcode 4 5)
40-
c02=$(translatebyte $barcode 6 7)
41-
c03=$(translatebyte $barcode 8 9)
42-
c04=$(translatebyte $barcode 10 11)
43-
c05=$(translatebyte $barcode 12 13)
44-
c06=$(translatebyte $barcode 14 15)
45-
c07=$(translatebyte $barcode 16 17)
46-
c08=$(translatebyte $barcode 18 19)
47-
c09=$(translatebyte $barcode 20 21)
48-
c10=$(translatebyte $barcode 22 23)
49-
c11=$(translatebyte $barcode 24 25)
50-
c12=$(translatebyte $barcode 26 27)
51-
c13=$(translatebyte $barcode 28 29)
52-
c14=$(translatebyte $barcode 30 31)
53-
c15=$(translatebyte $barcode 32 33)
54-
c16=$(translatebyte $barcode 34 35)
55-
c17=$(translatebyte $barcode 36 37)
56-
c18=$(translatebyte $barcode 38 39)
57-
c19=$(translatebyte $barcode 40 41)
58-
echo $c00$c01$c02$c03$c04$c05$c06$c07$c08$c09$c10$c11$c12$c13$c14$c15$c16$c17$c18$c19
37+
BARCODE=$1
38+
c00=$(translatebyte "${BARCODE}" 2 3)
39+
c01=$(translatebyte "${BARCODE}" 4 5)
40+
c02=$(translatebyte "${BARCODE}" 6 7)
41+
c03=$(translatebyte "${BARCODE}" 8 9)
42+
c04=$(translatebyte "${BARCODE}" 10 11)
43+
c05=$(translatebyte "${BARCODE}" 12 13)
44+
c06=$(translatebyte "${BARCODE}" 14 15)
45+
c07=$(translatebyte "${BARCODE}" 16 17)
46+
c08=$(translatebyte "${BARCODE}" 18 19)
47+
c09=$(translatebyte "${BARCODE}" 20 21)
48+
c10=$(translatebyte "${BARCODE}" 22 23)
49+
c11=$(translatebyte "${BARCODE}" 24 25)
50+
c12=$(translatebyte "${BARCODE}" 26 27)
51+
c13=$(translatebyte "${BARCODE}" 28 29)
52+
c14=$(translatebyte "${BARCODE}" 30 31)
53+
c15=$(translatebyte "${BARCODE}" 32 33)
54+
c16=$(translatebyte "${BARCODE}" 34 35)
55+
c17=$(translatebyte "${BARCODE}" 36 37)
56+
c18=$(translatebyte "${BARCODE}" 38 39)
57+
c19=$(translatebyte "${BARCODE}" 40 41)
58+
echo "${c00$c01$c02$c03$c04$c05$c06$c07$c08$c09$c10$c11$c12$c13$c14$c15$c16$c17$c18$c19}"
5959
}
6060

61-
ids=$(get_ids $barcode)
61+
IDS=$(_get_ids "${BARCODE}")
6262

63-
materialid=$(echo $ids | cut -d ' ' -f 2)
64-
if [[ $(echo "$materialid" | tail -c +9 | head -c 1) == "H" ]] ; then
65-
materialid="${materialid}D"
63+
MATERIALID=$(echo "${IDS}" | cut -d ' ' -f 2)
64+
if [[ $(echo "${MATERIALID}" | tail -c +9 | head -c 1) == "H" ]] ; then
65+
MATERIALID="${MATERIALID}D"
6666
fi
67-
echo deviceid,$(echo $ids | cut -d ' ' -f 1),materialid,$materialid,som,$(addcolons $(echo $barcode | cut -c 42-49)),duration,$(addcolons $(echo $barcode | cut -c 50-57))
67+
echo DEVICEID,$(echo "${IDS}" | cut -d ' ' -f 1),MATERIALID,${MATERIALID},SOM,$(_addcolons $(echo "${BARCODE}" | cut -c 42-49)),duration,$(_addcolons $(echo "${BARCODE}" | cut -c 50-57))
6868
_log -e

blackatends

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
#!/bin/bash
22
# blackatends
33
# Accepts one or many video files as an input and determines how many frames of black are at the beginning and at the end
4-
scriptdir=$(dirname "${0}")
5-
. "${scriptdir}/mmfunctions" || { echo "Missing '${scriptdir}/mmfunctions'. Exiting." ; exit 1 ;};
6-
version=1.0
4+
SCRIPTDIR=$(dirname "${0}")
5+
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
6+
VERSION=1.0
77

8-
cleanup(){
8+
_cleanup(){
99
_log -a "Process aborted"
1010
exit 1
1111
}
1212

13-
trap cleanup SIGHUP SIGINT SIGTERM
13+
trap _cleanup SIGHUP SIGINT SIGTERM
1414

15-
usage(){
15+
_usage(){
1616
echo
17-
echo "$(basename "${0}") ${version}"
17+
echo "$(basename "${0}") ${VERSION}"
1818
echo "This program will report on the number of black frames at the beginning and end of a video file."
1919
echo
20-
echo "Usage: $(basename $0) file1 [ file2 ... ]"
20+
echo "Usage: $(basename ${0}) file1 [ file2 ... ]"
2121
echo
2222
echo "Options:"
2323
echo " -h display this help"
2424
echo
2525
exit
2626
}
27-
[ "$#" = 0 ] && usage
27+
[ "${#}" = 0 ] && _usage
2828

2929
# command-line options to set mediaid and original variables
3030
OPTIND=1
31-
while getopts ":h" opt; do
32-
case "$opt" in
33-
h) usage ;;
34-
\?) echo "Invalid option: -$OPTARG" ; exit 1 ;;
35-
:) echo "Option -$OPTARG requires an argument" ; exit 1 ;;
31+
while getopts ":h" OPT; do
32+
case "${OPT}" in
33+
h) _usage ;;
34+
\?) echo "Invalid option: -${OPTARG}" ; exit 1 ;;
35+
:) echo "Option -${OPTARG} requires an argument" ; exit 1 ;;
3636
esac
3737
done
3838
shift $(( ${OPTIND} - 1 ))
3939

4040
while [ "${*}" != "" ] ; do
4141
_log -b
42-
[ "$#" != 0 ] && sourcefile="${1}"
43-
black_at_ends "$sourcefile"
42+
[ "${#}" != 0 ] && SOURCEFILE="${1}"
43+
_black_at_ends "${SOURCEFILE}"
4444
_log -e
4545
shift
4646
done

checksum2filemaker

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# 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.
3-
version=1.0
3+
VERSION=1.0
44

55
SCRIPTDIR=$(dirname "${0}")
66
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
@@ -10,23 +10,23 @@ SCRIPTDIR=$(dirname "${0}")
1010
[ -z "${FILEMAKER_XML_URL}" ] && { echo "The filemaker xml path must be set. Run mmconfig to set FILEMAKER_XML_URL." ; exit 1 ;};
1111

1212
while [ "${*}" != "" ] ; do
13-
input="${1}"
14-
if [[ ! -f "${input}/metadata/checksum.md5" ]] ; then
15-
report -dt "${input} does not have a checksum.md5 file, skipping for $(basename "$input")"
13+
INPUT="${1}"
14+
if [[ ! -f "${INPUT}/metadata/checksum.md5" ]] ; then
15+
_report -dt "${INPUT} does not have a checksum.md5 file, skipping for $(basename "${INPUT}")"
1616
shift
1717
continue
1818
fi
19-
OLDIFS=$IFS
19+
OLDIFS="${IFS}"
2020
IFS=$'\n'
21-
echo "Uploading checksum data for $(basename "$input"). Please wait…"
22-
for hash in $(cat "${input}/metadata/checksum.md5"); do
23-
if [[ "$hash" ]] ; then
24-
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}"\""
25-
hashcmd="curl -s -S -G $hashinsert \"http://${FILEMAKER_XML_URL}?-db=${FILEMAKER_DB}&-lay=checksums&-new\" 1>/dev/null"
26-
eval "$hashcmd"
21+
echo "Uploading checksum data for $(basename "${INPUT}"). Please wait…"
22+
for HASH in $(cat "${INPUT}/metadata/checksum.md5"); do
23+
if [[ "$HASH" ]] ; then
24+
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}"\""
25+
HASHCMD="curl -s -S -G ${HASHINSERT} \"http://${FILEMAKER_XML_URL}?-db=${FILEMAKER_DB}&-lay=checksums&-new\" 1>/dev/null"
26+
eval "${HASHCMD}"
2727
fi
2828
done
29-
IFS=$OLDIFS
29+
IFS="${OLDIFS}"
3030
echo "Done uploading metadata for $(basename "${1}")."
3131
shift
3232
done

0 commit comments

Comments
 (0)