forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadomneon
executable file
·117 lines (102 loc) · 3.37 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
#!/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 "${OMNEONPATH}/${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 ))
[ ! "$TMPDIR" ] && { report -wt "The temporary directory must be set and be available. Run 'mmconfig'." ; exit 1 ;};
[ ! -d "$TMPDIR" ] && mkdir -p "$TMPDIR"
[ ! -n "$OMNEONIP" ] && { report -wt "The Omneon IP must be set. Run 'mmconfig'." ; exit 1 ;};
[ ! -n "$OMNEONPATH" ] && { report -wt "The Omneon Path must be set. Run 'mmconfig'." ; exit 1 ;};
while [ "${*}" != "" ] ; do
sourcefile="${1}"
extension=$(echo "$sourcefile" |awk -F . '{print $NF}')
if [ "$extension" == "mov" -o "$extension" == "mxf" ] ; then
removetmp="n"
filename=$(basename "$sourcefile")
_log -b
get_ftp_status "${filename}"
if [[ ! $(echo "$status" | grep "${OMNEONPATH}") ]] ; 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."
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}" "${OMNEONPATH}/${filename}.uploading.${extension}"
rename "${OMNEONPATH}/${filename}.uploading.${extension}" "${OMNEONPATH}/${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"
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 or mxf extension. This will NOT be uploaded."
fi
shift
done
_log -e