-
Notifications
You must be signed in to change notification settings - Fork 27
/
uploadomneon
executable file
·139 lines (123 loc) · 4.16 KB
/
uploadomneon
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# uploadomneon
# upload to omneon
REQUIRECONFIG="Y"
VERSION="1.0"
SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
_usage(){
echo
echo "$(basename "${0}") ${VERSION}"
echo "This application will upload file(s) to a server via rsync in sequential order. Options are specified via 'mmconfig'."
echo
echo "Settings:"
echo "OMNEONIP=${OMNEONIP}"
echo "OMNEONPATH=${OMNEONPATH}"
echo "TMPDIR=${TMPDIR}"
echo "Usage: $(basename ${0}) file1 [ file2 ...]"
echo " -h ( display this help )"
echo
exit
}
[ "${#}" = 0 ] && _usage
_cleanup(){
_log -a "Process aborted"
exit 1
}
get_ftp_status(){
local FILENAME="${1}"
STATUS=$(ftp -a "${OMNEONIP}" <<END_SCRIPT
binary
ls "${UPLOADPATH}/${FILENAME}"
exit
END_SCRIPT)
SIZE=$(echo "${STATUS}" | grep "${FILENAME}" | awk '{print $5}')
}
trap _cleanup SIGHUP SIGINT SIGTERM
_log -b
# command-line options to set mediaid and original variables
OPTIND=1
while getopts ":h" OPT; do
case "${OPT}" in
h) _usage ;;
*) echo "Invalid option: -${OPTARG}" ; exit 1 ;;
:) echo "Option -${OPTARG} requires an argument" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
if [ ! "${TMPDIR}" ] ; then
_report -wt "The temporary directory must be set and be available. Run 'mmconfig'."
exit 1
fi
if [ ! -d "${TMPDIR}" ] ; then
mkdir -p "${TMPDIR}"
fi
if [ ! -n "${OMNEONIP}" ] ; then
_report -wt "The Omneon IP must be set. Run 'mmconfig'."
_writeerrorlog "uploadomneon" "The omneon IP was not set, so files could not be uploaded the omneon."
exit 1
fi
if [ ! -n "${OMNEONPATH}" ] ; then
_report -wt "The Omneon Path must be set. Run 'mmconfig'."
_writeerrorlog "uploadomneon" "The filepath to the delivery folder on the omneon was not set, so files could not be delivered."
exit 1
fi
while [ "${*}" != "" ] ; do
SOURCEFILE="${1}"
EXTENSION=$(echo "${SOURCEFILE}" |awk -F . '{print $NF}')
if [ "${EXTENSION}" == "mov" -o "${EXTENSION}" == "mxf" -o "${EXTENSION}" == "scc" ] ; then
if [ "${EXTENSION}" == "scc" ] ; then
UPLOADPATH="${OMNEONPATH}/subtitle.dir"
else
UPLOADPATH="${OMNEONPATH}"
fi
REMOVETMP="n"
FILENAME=$(basename "${SOURCEFILE}")
_log -b
get_ftp_status "${FILENAME}"
if [[ ! $(echo "${STATUS}" | grep "${UPLOADPATH}") ]] ; then
_report "The file named ${FILENAME} is not currently on the omneon, proceeding..."
if echo "${SOURCEFILE}" | grep -q "/Volumes/" ; then
_report -dt "The file ${FILENAME} is coming from an external volume. It will first move the file to ${TMPDIR} and then upload to the omneon."
"${SCRIPTDIR}/migratefiles" -o "${TMPDIR}" "${SOURCEFILE}"
#rsync -rtv --progress "${SOURCEFILE}" "${TMPDIR}"
UPLOADFILE="${TMPDIR}/${FILENAME}"
REMOVETMP="y"
else
UPLOADFILE="${SOURCEFILE}"
fi
EXTENSION=$(basename "${SOURCEFILE##*.}")
_report -dt "Starting to ftp ${FILENAME} to the Omneon..."
ftp -a "${OMNEONIP}" <<END_SCRIPT
binary
put "${UPLOADFILE}" "${UPLOADPATH}/${FILENAME}.uploading.${EXTENSION}"
rename "${UPLOADPATH}/${FILENAME}.uploading.${EXTENSION}" "${UPLOADPATH}/${FILENAME}"
exit
END_SCRIPT
UPLOAD_ERR="${?}"
get_ftp_status "${FILENAME}"
if [ "${UPLOAD_ERR}" = "0" ] ; then
_report -dt "${FILENAME} is uploaded to the omneon"
LOCALSIZE=$(ls -l "${SOURCEFILE}" | awk '{print $5}')
if [[ "${LOCALSIZE}" = "${SIZE}" ]] ; then
_report -dt "Uploaded file matches source file at ${SIZE} bytes. Looks good."
else
_report -wt "WARNING: Uploaded file is ${SIZE} bytes and local file is ${LOCALSIZE} bytes."
fi
if [ "${REMOVETMP}" = "y" ] ; then
rm -v "${TMPDIR}/${FILENAME}"
fi
else
_report -wt "ftp exited with code ${UPLOAD_ERR} for ${UPLOADFILE}"
_writeerrorlog "uploadomneon" "ftp exited with code ${UPLOAD_ERR} for ${UPLOADFILE}"
fi
else
_report -wt "${FILENAME} is already on the omneon as a ${SIZE} byte file."
fi
else
_report -wt "${SOURCEFILE} does not use a mov, mxf, or scc EXTENSION. This will NOT be uploaded."
_writeerrorlog "uploadomneon" "${SOURCEFILE} does not use a mov, mxf, or scc EXTENSION. This will NOT be uploaded."
fi
shift
done
_log -e