forked from NMAAHC/nmaahcmm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restructureForVFCU
executable file
·82 lines (73 loc) · 3.56 KB
/
restructureForVFCU
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
#a script to restructure a DPX package directory for VFCU pickup and place .md5 in driectory
# load nmaahcmmfunctions into this script
SCRIPT_PATH="${0%/*}"
. "${SCRIPT_PATH}/nmaahcmmfunctions"
[[ -f "${SCRIPT_PATH}/nmaahcmmfunctions" ]] || { echo "Missing '${SCRIPT_PATH}/nmaahcmmfunctions'. Exiting." ; exit 1 ;};
_initialize_make # safe script termination process defined in nmaahcmmfunctions
DEPENDENCIES=(rsync) # list dependencies required by script
_check_dependencies "${DEPENDENCIES[@]}" # defined in nmaahcmmfunctions
### USAGE
_usage(){
echo
echo "$(basename "${0}")"
echo "This application will restructure a DPX package directory for VFCU pickup and place .md5s in a directory. It takes one or more DPX directories as arguments."
echo "Usage: $(basename ${0}) DPXdirectory1 [ DPXdirectory2 ... ]"
echo
exit
}
[[ "${#}" = 0 ]] && _usage # if the command is run with no arguments then _usage is called
# getopts loop
OPTIND=1
while getopts ":h" OPT; do
case "${OPT}" in
h) _usage ;; # if the operator runs "[scriptname] -h" then the _usage text above will display in the terminal
*) echo "Invalid option -${OPTARG}" ; _usage ;; # if the operator tries to use an option other than the ones listed above, the _usage text will display in the terminal
esac
done
shift $(( ${OPTIND} - 1 ))
## SCRIPT ACTIONS
# log script beginning
_log -b
while [ "${*}" != "" ] ; do
INPUT="${1}" # name $INPUT as the first argument sent to script
# create subdirectories for each component
AUDIO_DIR="${INPUT}/${INPUT##*/}"__Audio
DERIV_DIR="${INPUT}/${INPUT##*/}"__Derivatives
DPX_DIR="${INPUT}/${INPUT##*/}"__DPX
MD5_DIR="/Volumes/nmaahc-borndigital/06_DPX_checksums/"
if [[ -d "${INPUT}" ]] ; then
_report -g "Moving all files in directories: ${AUDIO_DIR}, ${DERIV_DIR}"
_report -g "to directory: ${DPX_DIR}"
if [[ -d "${AUDIO_DIR}" ]] ; then
mv -vi "${AUDIO_DIR}"/* "${DPX_DIR}" # move all files in the AUDIO directory to the DPX directory. -v=verbose, -i=interactive (prompts before overwriting)
rm -vri "${AUDIO_DIR}" # removes the AUDIO directory and any files left in it. -v=verbose, -r=recursive, -i=interactive (prompts before overwriting)
fi
if [[ -d "${DERIV_DIR}" ]] ; then
mv -vi "${DERIV_DIR}"/* "${DPX_DIR}" # move all files in the DERIVATIVES directory to the DPX directory
rm -vri "${DERIV_DIR}" # removes the DERIVATIVES directory and any files left within it
fi
else
_report -rt "ERROR: ${INPUT} is not a directory. Exiting..."
_log -a "Process terminated by script (no directory at requested location)."
exit 1
fi
echo
if [[ -d "${MD5_DIR}" ]] ; then
_report -g "Moving .md5 directory to ${DPX_DIR}"
rsync -avvPhi --stats "${MD5_DIR}/${INPUT##*/}"/*.md5 "${DPX_DIR}" # move .md5 directory to DPX directory to initiate DPX pickup. -a="archive," -vv=very verbose, -P=keep partially transferred files+show progress during transfer, -h=human-readable, -i=itemize changes
_report -g "Done moving .md5 directory to ${DPX_DIR}. VFCU will begin picking up your files shortly."
_report -b "Please make sure your templates have been set correctly!"
echo
cowsay "Tootles!"
else
_report -rt "ERROR: ${MD5_DIR} does not exist. Exiting..."
_log -a "Process terminated by script (no directory at requested location)."
exit 1
fi
shift
done
# log script ending
_log -e
_report -g "restructureForVFCU process complete."
exit $?