forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadomneon
executable file
·92 lines (79 loc) · 2.55 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
#!/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
}
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 ))
[ ! -d "$TMPDIR" ] && { report -wt "The temporary directory must be set and be available. Run 'mmconfig'." ; exit 1 ;};
[ ! -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"
removetmp="n"
filename=$(basename "$sourcefile")
log -b
status=$(ftp -a "$OMNEONIP" <<END_SCRIPT
binary
ls "${OMNEONPATH}/${filename}"
exit
END_SCRIPT)
if [[ ! $(echo "$status" | grep "${OMNEONPATH}") ]] ; then
report "The file named $filename is not currently on the omneon, proceeding..."
if echo "$sourcefile" | grep -q "/Volumes/[AB][0-9]\{5\}" ; then
report -dt "The file ${filename} is coming from an LTO tape. 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
report -dt "Starting to ftp $filename to the Omneon..."
ftp -a "$OMNEONIP" <<END_SCRIPT
binary
put "$uploadfile" "${OMNEONPATH}/${filename}"
exit
END_SCRIPT
upload_err="${?}"
report -dt "ftp exited with code ${upload_err}"
report -dt "${filename} is uploaded to the omneon"
[ "$upload_err" = "0" ] && [ "$removetmp" = "y" ] && rm -v "${TMPDIR}/${filename}"
else
size=$(echo "$status" | grep "$filename" | awk '{print $5}')
size_g=$(echo "scale=3; $size / 1073741824" | bc)
report -wt "$filename is already on the omneon as a $size_g gigabyte file."
fi
shift
done
log -e