-
Notifications
You must be signed in to change notification settings - Fork 8
/
moveDPX
executable file
·94 lines (83 loc) · 4.26 KB
/
moveDPX
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
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
# a script to copy .md5 checksum files and the first .dpx file in a stack to a designated directory
# load nmaahcmmfunctions into this script
SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/nmaahcmmfunctions" || { echo "Missing '${SCRIPTDIR}/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
RSYNC_ERROR_COUNT=0
RSYNC_ERROR_FILES=""
## USAGE
_usage(){
echo
echo "$(basename "${0}")"
echo "This application will copy .md5 checksum files and the first .dpx file in a stack to a designated directory. It takes one or more DPX directories as arguments."
echo "The files will be sent to the directory set in nmaahcmmconfig ('directory where copies of your DPX packages will go'). This directory is currently set to: ${DPX_DESTINATION}"
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
DPX_SOURCE="${1}"
DPX_OUTPUT="${DPX_DESTINATION}/${DPX_SOURCE##*/}"
if [[ ! -d "${DPX_DESTINATION}" ]] ; then
_report -rt "${DPX_DESTINATION} does not exist. Exiting..." >&2 # tell operator if the hardcoded parent folder cannot be found - e.g. no longer exists or is moved
_log -a "Process terminated by script (no directory at requested location)."
exit 1
fi
if [[ ! -d "${DPX_OUTPUT}" ]] ; then
_report -g "Creating target folder: ${DPX_OUTPUT}"
mkdir -p "${DPX_OUTPUT}"
fi
_report -g "Moving files to target folder..."
for FILE in "${DPX_SOURCE}"/*DPX*/* ; do # for all files in a DPX subdirectory (expected to be named with the word "DPX" in it), do the following:
if [[ -f "${DPX_OUTPUT}"/*.dpx ]] ; then # if .dpx file is found in the destination folder, do:
_report -g "Verifying checksum for ${FILE##*/} ..."
rsync -avPhic "${FILE}" "${DPX_OUTPUT}" # move file securely to the target folder. -a="archive," -v=verbose, -P=keep partially transferred files+show progress during transfer, -h=human-readable, -i=itemize changes, -c=with a built-in checksum check
_check_rsync_output
else
rsync -avPhi "${FILE}" "${DPX_OUTPUT}" # move file securely to the destination folder (no checksum check)
_check_rsync_output
fi
break 1
done
for MD5 in "${DPX_SOURCE}"/*.md5 ; do
if [[ -f "${DPX_OUTPUT}"/*.md5 ]] ; then # if .md5 checksum file is found as expected, do:
_report -g "Verifying checksum for ${MD5##*/}..." # move file securely to the target folder (with built-in checksum check)
rsync -avPhic "${MD5}" "${DPX_OUTPUT}"
_check_rsync_output
else
rsync -avPhi "${MD5}" "${DPX_OUTPUT}" # move file securely to the target folder (no checksum check)
_check_rsync_output
fi
done
_report -g "Moving to next DPX directory if supplied..."
shift
done
echo
_report -g "Changing permissions to 777 on the following files in directory ${DPX_DESTINATION}:"
chmod -vR 777 "${DPX_DESTINATION}" # set permissions on the target parent directory (set above) to read-write-execute for all users. -v=verbose, -R=recursive
if [[ "${RSYNC_ERR_1}" -eq 0 ]] && [[ "${RSYNC_ERR_2}" -eq 0 ]] ; then
_report -g "All rsync processes were successful! DPX and MD5 files have been safely moved to directory ${DPX_OUTPUT}"
else
_report -rt "Some rsync processes experienced errors!"
_report -rt "The following ${RSYNC_ERROR_COUNT} file/s experienced transfer issues: ${RSYNC_ERROR_FILES}"
fi
# log script ending
_log -e
_report -g "moveDPX process complete."
exit "$?"