-
Notifications
You must be signed in to change notification settings - Fork 27
/
finishpackage
executable file
·65 lines (59 loc) · 3.13 KB
/
finishpackage
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
#finish package takes a directory input created by restructureforCompliance and creates derivative access copies, metadata documents, and a checksum file.
SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
_initialize_make
_usage(){
echo "This application will try to determine what type of package this is and finish any processing needed to pass verifytree."
echo "Dependencies: ${DEPENDENCIES[@]}"
echo "Usage: $(basename "${0}") [ options ] fileorpackage1 [ fileorpackage2 ...]"
echo " -n (skip the broadcast output)"
}
OPTIND=1
while getopts "nh" OPT ; do
case "${OPT}" in
n) SKIP_BROADCAST="Y" ;;
h) _usage ;;
*) echo "bad option -${OPTARG}" ; _usage ;;
:) echo "Option -${OPTARG} requires an argument" ; _writeerrorlog "finishpackage" "The option selected required an argument and none was provided. The script had to exit." ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
while [ "${*}" != "" ] ; do
#look for tree.xml
PACKAGE="${1}"
shift
if [ -d "${PACKAGE}" ] ; then
OUTPUTDIR="${PACKAGE}/metadata"
_report -dt "running finishpackage on ${PACKAGE}" #the name of the package being verified
#make a new temp tree
TEMPTREE=$(_maketemp)
tree -DaNXs --du --timefmt "%Y-%m-%dT%H:%M:%SZ" -I "tree.xml|.DS_Store" "${PACKAGE}" > "${TEMPTREE}"
#if tree.xml exists, compare it to the specified xpath expressions of an AIP
#check extension of first object file
MOSTCOMMONEXTENSION="$(xmlstarlet sel -t -m "/tree/directory/directory[@name='objects']/file|/tree/directory/directory[@name='objects']/file|/tree/directory/directory[@name='objects']/directory[@name='restoration']/file" -v "substring-after(@name, '.')" -n "${TEMPTREE}" | while read j ; do echo "${j##*.}" ; done | sort | uniq -c | sort -n -r | head -n 1 | awk '{print $2}')"
MOSTCOMMONEXTENSION_LOWER="$(echo "${MOSTCOMMONEXTENSION}" | awk '{print tolower($0)}')"
AUDIO_EXTENSION_LIST="|mp3|aif|aiff|wav|m4a|"
#if there is one object file and it uses a .wav extension, then run audio-specific tests
if [[ "${AUDIO_EXTENSION_LIST}" =~ "|${MOSTCOMMONEXTENSION_LOWER}|" ]] ; then
makederiv -T audiographs "${PACKAGE}"
elif [[ "${MOSTCOMMONEXTENSION}" = "tif" ]] ; then
makepdf "${PACKAGE}"
makemetadata "${PACKAGE}"
checksumpackage "${PACKAGE}"
else
"${SCRIPTDIR}/makelossless" "${PACKAGE}"
if [[ "${SKIP_BROADCAST}" != "Y" ]] ; then
"${SCRIPTDIR}/makederiv" -T broadcast "${PACKAGE}"
fi
"${SCRIPTDIR}/makederiv" -T youtube "${PACKAGE}"
"${SCRIPTDIR}/makeframes" "${PACKAGE}"
"${SCRIPTDIR}/makefingerprint" "${PACKAGE}"
fi
"${SCRIPTDIR}/makederiv" -T waveform "${PACKAGE}"
"${SCRIPTDIR}/makederiv" -T podcast "${PACKAGE}"
"${SCRIPTDIR}/makederiv" -T mp3 "${PACKAGE}"
"${SCRIPTDIR}/makemetadata" "${PACKAGE}"
"${SCRIPTDIR}/checksumpackage" "${PACKAGE}"
fi
done