forked from ericmandel/js9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
js9wait
executable file
·104 lines (92 loc) · 1.75 KB
/
js9wait
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
#!/bin/sh
# set -x
# in case the user has changed the js9 script, try to figure out the right one
# is this file a link?
BFILE="${BASH_SOURCE[0]}"
LFILE="$( readlink $BFILE )"
if [ x"$LFILE" != x ]; then
XFILE="$LFILE"
else
XFILE="$BFILE"
fi
# is the containing directory a link?
BDIR="$( dirname ${XFILE} )"
LDIR="$( readlink $BDIR )"
if [ x"$LDIR" != x ]; then
XDIR="$LDIR"
else
XDIR="$BDIR"
fi
# any more links we need to know about?
DIR="$( cd "${XDIR}" >/dev/null 2>&1 && pwd )"
if [ -r ${DIR}/js9 ]; then
JS9=${DIR}/js9
else
JS9=js9
fi
error() {
echo "ERROR: $1" 1>&2
exit 1
}
# local variables
DONE=false
VERBOSE=false
TRIES=10
SLEEP=1
while [ x"$1" != x ]; do
case $1 in
-h) shift
XARGS="$XARGS -h $1"
shift;;
-id|--id) shift
XARGS="$XARGS --id $1"
shift;;
-s) shift
SLEEP=$1
shift;;
-t) shift
TRIES=$1
shift;;
-v) VERBOSE=true
shift;;
*) break;;
esac
done
# check for required args
if [ $# -lt 2 ]; then
echo "usage: $0 status filename"
exit 1
else
ID="$1"
PATHNAME="$2"
shift
fi
# wait for completion
while [ $DONE = false ]; do
# get status of specified image
GOT=`${JS9} $XARGS GetStatus "$ID" "$PATHNAME"`
case $GOT in
error)
error "processing $ID: $PATHNAME";;
none)
error "could not find: $PATHNAME";;
loading|other)
TRIES=`echo "$TRIES - 1" | bc`
if [ $TRIES -le 0 ]; then
error "timeout waiting for $ID: $PATHNAME"
fi
sleep $SLEEP
if [ x$VERBOSE = xtrue ] ; then
echo "waiting [$TRIES] ..."
fi
continue;;
complete)
if [ x$VERBOSE = xtrue ] ; then
echo "success!"
fi
DONE=true
continue;;
esac
done
# signal success
exit 0