-
Notifications
You must be signed in to change notification settings - Fork 2
/
runner-bean.sh
executable file
·110 lines (85 loc) · 1.56 KB
/
runner-bean.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
101
102
103
104
105
#!/usr/local/bin/bash
# Long time ago since last use. It used to be useful.
set -euo pipefail
args=$@
input=
output=
tmpstore=
cleanup=false
destdir=
function rmit {
if [[ $? == 0 ]]; then
echo [happy] $@
else
errcode=$?
echo [grumpy] $@
fi
if test -d $tmpstore; then
if $cleanup; then
rm -rf $tmpstore
fi
fi
true
}
trap rmit SIGTERM EXIT
while getopts :d:t:i:o:h opt
do
case "$opt" in
i)
input=$OPTARG
;;
d)
destdir=$OPTARG
;;
o)
output=$OPTARG
;;
t)
tmpstore=$OPTARG
;;
h)
cat <<EOU
-t <dname> use dname as tmp working directory (create if necessary)
-i <fnames> copy files to tmp directory
-o <fnames> copy files from tmp directory to current directory
-d <dname> copy files in -o to this directory rather than current directory
EOU
exit
;;
:)
error="Flag $OPTARG needs argument"
false
;;
?)
error="Flag $OPTARG unknown"
false
;;
esac
done
shift $(($OPTIND-1))
## create temp directory,
## and all files required.
##
if [[ x$tmpstore == x ]]; then
tmpstore=/tmp/$USER.$host.$$
cleanup=true
fi
mkdir -p $tmpstore
for f in $input; do
cp $f $tmpstore
echo done copying file $f
done
curwd=$(pwd)
if [[ x$destdir == x ]]; then
destdir=$curwd
fi
cd $tmpstore
"$@"
for f in $output; do
if [[ -e $f ]]; then
cp $f $destdir
echo $done retrieving file $f
else
echo "file $f not created as expected" 2>&1
fi
done