-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.sh
61 lines (39 loc) · 1.23 KB
/
source.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
#! /bin/env sh
: no need bash, because of no 'export -f', because use while rather than tailcall exec.
retrier ()
(
: retrier cmd args ...
: ENV="some defines or codes generate ..." retrier cmd args ...
: ENV="make codes in func WORK; all defiles WORK has depends on" retrier WORK
: ENV='WORK () { sleep 3 ; cd $RETRIED ; }' retrier WORK
Generators ()
(
lineargs ()
{
: lineargs line1 line2 ...
for per in "$@" ;
do echo "$per" ; done &&
:;
} &&
flags ()
{
: flags ENV RETRIED ...
lineargs "$@" | xargs -i -- echo local '{}="${}"' '&&' &&
:;
} &&
"$@" &&
:;
) &&
retrying ()
{
: RETRIED=0 retrying cmd args ...
eval "$ENV" && while ! "$@" ; do RETRIED=$((RETRIED+1)) ; done &&
1>&2 echo "{ :ok, $RETRIED }" &&
:;
} &&
eval "$(Generators flags ENV RETRIED RETRIED_TIMES) :" &&
export -- ENV &&
RETRIED="${RETRIED:-${RETRIED_TIMES:-0}}" retrying "$@" &&
:;
) &&
exec retrier "$@"