-
Notifications
You must be signed in to change notification settings - Fork 1
/
knot
executable file
·90 lines (81 loc) · 2.06 KB
/
knot
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
#!/bin/bash
source $PLUG_PATH/cfgs
help_msg() {
log "
knot: the tas(k-not)ifier
desc: notify next task initialization when previous task is finished
help: knot [args]
args:
-c, --create <knots> finish task and create knots
-b, --break <knots> break the knots after knots creation
-d, --delete delete all knots
-u, --usage show examples of usage
-h, --help display this help
"
}
examples() {
log "
example 1:
Use knots to schedule task1 and task2,
where task2 is dependent on task1.
Start task1 and create a knot:
$ task1 && knot -c <knot_name>
Start task2 after knot is created:
$ knot -b <knot_name> && task2
example 2:
Use knots to initiate multiple tasks:
$ task1 && knot -c k1 k2
$ knot -b k1 && task2
$ knot -b k2 && task3
example 2:
Use knots to wait for multiple tasks:
$ task1 && knot -c k1
$ task2 && knot -c k2
$ knot -b k1 k2 && task2
"
}
prereqs() {
check_dir $KNOT_DIR
knot_name="$KNOT_DIR/.knot"
}
create() {
shift;
[ "$#" -eq 0 ] && err "no knot given"
for knot in "$@"; do
knot_name="$KNOT_DIR/$knot.knot"
touch $knot_name
done
}
till() {
shift;
[ "$#" -eq 0 ] && err "no knot given"
while true; do
created=true
for knot in "$@"; do
knot_name="$KNOT_DIR/$knot.knot"
[ ! -e $knot_name ] && created=false && break
done
[ $created = true ] && break
echo "still waiting"
sleep $KNOT_TIME
done
delete $@
}
delete() {
shift;
[ "$#" -eq 0 ] && rm -rf $KNOT_DIR/*.knot
for knot in "$@"; do
knot_name="$KNOT_DIR/$knot.knot"
rm -rf $knot_name
done
}
options() {
case $1 in
-c | --create ) create $@;;
-b | --break ) till $@;;
-d | --delete ) delete;;
-u | --usage ) examples;;
* ) help_msg;;
esac
}
init $@