-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathuploadomneon
executable file
·89 lines (78 loc) · 2.51 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
#!/bin/bash
# uploadomneon
# upload to omneon
scriptdir=`dirname "$0"`
. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;};
cleanup(){
log -a "Process aborted"
exit 1
}
trap cleanup SIGHUP SIGINT SIGTERM
log -b
usage(){
echo
echo "$(basename $0) ${version}"
echo "This script may be run interactively by running it with no arguments or may be used with the following options."
echo "Usage: $(basename $0) [ -f sourcefile ] [ -i omneon_ip ] [ -n omneon_path ] [ -t tmp_dir]"
echo " -f sourcefile"
echo " -i omneonip"
echo " -n omneonpath"
echo " -t tmpdir"
exit
}
# command-line options to set mediaid and original variables
OPTIND=1
while getopts ":hm:f:t:ip" opt; do
case "$opt" in
h) usage ;;
f) input="$OPTARG" ; once="y" ;;
i) OMNEONIP="$OPTARG" ;;
n) OMNEONPATH="$OPTARG" ;;
t) TMPDIR="$OPTARG" ;;
\?) echo "Invalid option: -$OPTARG" ; exit 1 ;;
:) echo "Option -$OPTARG requires an argument" ; exit 1 ;;
esac
done
[ ! -d "$TMPDIR" ] && echo "The temporary directory must be set. Use [ -t /path/to/temporary/directory ]." && exit 1
[ ! -d "$OMNEONIP"] && echo "The Omneon IP must be set." && exit 1
[ ! -d "$OMNEONPATH"] && echo "The Omneon Path must be set." && exit 1
shift $(( ${OPTIND} - 1 ))
[ "$#" = 0 -a ! "$input" ] && { ask_input ; once="y" ;};
while [ "$*" != "" -o "$once" = "y" ] ; do
once="n"
[ "$#" != 0 ] && sourcefile="$1"
removetmp="n"
filename=`basename "$sourcefile"`
log -b
status=`ftp -a "$OMNEONIP" <<END_SCRIPT
binary
ls "${OMNEONPATH}/${filename}"
exit
END_SCRIPT`
if [ "$status" = "Name not found." ] ; 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
report -wt "ftp exited with code ${?}"
report -dt "${filename} is uploaded to the omneon"
[ "$?" = "0" ] && [ "$removetmp" = "y" ] && rm "${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