-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_process.sh
executable file
·100 lines (87 loc) · 2.79 KB
/
start_process.sh
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
#!/bin/sh
usage() { echo "USAGE: sh $0 [OPTIONS]
OPTIONS:
-h display help
-b <resultfile> benchmark mode: write timestamp ID to the given file once the process exits
-e <path/to/binary> execute the given binary -- default: rusty-nail/target/release/rusty-nail
-i <path/to/image> original image file path
-o <outfilename> write start and end timestamps and the output of all commands to the given file
-p <outdir> write output file to the given directory
-t <path/to/thumbnail> write thumbnail to the given file path
-x <width> width of thumbnail -- defaults to 150
-y <height> height of thumbnail -- defaults to match width
-c crop the image to exactly fill the given thumbnail dimensions
" 1>&2; exit 1; }
BENCHFILE=
BIN="rusty-nail/target/release/rusty-nail"
OUTFILE=
OUTDIR=
IMAGE=
THUMBNAIL=
WIDTH=150
HEIGHT=
CROP=
while getopts ":hb:e:i:o:p:t:x:y:c" OPT; do
case "$OPT" in
h)
usage
;;
b)
BENCHFILE="$OPTARG"
;;
e)
BIN="$OPTARG"
;;
i)
IMAGE="$OPTARG"
;;
o)
OUTFILE="$OPTARG"
;;
p)
OUTDIR="$OPTARG"
;;
t)
THUMBNAIL="$OPTARG"
;;
x)
WIDTH="$OPTARG"
;;
y)
HEIGHT="$OPTARG"
;;
c)
CROP="-c"
;;
*)
echo "ERROR: unknown option: $OPT"
usage
;;
esac
done
shift $((OPTIND - 1)) # isolate remaining args
[ -f "$BIN" ] || { echo "ERROR: binary does not exist: $BIN"; exit 1; }
[ -n "$IMAGE" ] || { echo "ERROR: missing required argument: -i <path/to/image>"; usage; }
[ -f "$IMAGE" ] || { echo "ERROR: image file does not exist: $IMAGE"; exit 1; }
[ -n "$HEIGHT" ] || HEIGHT="$WIDTH"
TS="$(date +%s%N)" # get current time in nanoseconds -- good enough for unique timestamp
NAME="process-$TS"
[ -n "$OUTFILE" ] || OUTFILE="$NAME.output"
[ -n "$THUMBNAIL" ] || THUMBNAIL="$NAME.png"
[ -n "$OUTDIR" ] && mkdir -p "$OUTDIR" || OUTDIR="."
OUTFILE="$OUTDIR/$OUTFILE"
THUMBNAIL="$OUTDIR/$THUMBNAIL"
##### BEGIN RUNNING PROCESS #####
echo "$(date +%s%N) Process initiated" >> "$OUTFILE"
/usr/bin/time -o "$OUTFILE" --append --portability "$BIN" -i "$IMAGE" -t "$THUMBNAIL" -x "$WIDTH" -y "$HEIGHT" $CROP >> "$OUTFILE"
ECODE=$?
END_TS="$(date +%s%N)"
if [ $ECODE -eq 0 ]; then
echo "$END_TS Process exited successfully" >> "$OUTFILE"
[ -n "$BENCHFILE" ] && echo "$TS" >> "$BENCHFILE"
true
else
echo "$END_TS Process exited with error code $ECODE" >> "$OUTFILE"
#[ -n "$BENCHFILE" ] && echo "$TS" >> "$BENCHFILE"
true
fi