-
Notifications
You must be signed in to change notification settings - Fork 3
/
pipeman
executable file
·68 lines (56 loc) · 1.26 KB
/
pipeman
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
#!/bin/sh
die() {
echo $@ >&2
logger -i -t pipeman "error: $@"
exit 1
}
while test -n "$1" ; do
case $1 in
-k|--kill)
KILL=y
;;
*)
SDIR=$1
test -d "$SDIR" || die "'$SDIR' is not a dir"
;;
esac
shift
done
FNAME=pipelets.update
test -n "$FNAME" || die "FNAME should be non-empty"
# Will generate function call for every input line
awesomize() {
local sname=`basename "$1"`
echo "Will use '$sname' as callback key for $1" >&2
while read l ; do
echo "$FNAME ( \"$sname\" , \"$l\" )" | awesome-client
done
}
cleanup() {
for pidfile in `ls -1 $HOME/.pipeman:$DISPLAY.*.ppid` ; do
pkill -P `cat $pidfile` 2>/dev/null
rm $pidfile
done
}
check_pid() {
local pidfile="$HOME/.pipeman:$DISPLAY.pid"
test -f "$pidfile" && kill `cat $pidfile`
echo $$ > "$pidfile"
}
check_prog() {
which "$1" >/dev/null 2>&1 || die "Please install $1"
}
check_prog pkill
check_prog awesome-client
cleanup
test "$KILL" = "y" && { exit 0; }
trap cleanup "EXIT"
for s in `find "$SDIR" -type f -and -executable` ; do
echo "Starting $s"
{ $s | awesomize "$s" ; } &
pid=$!
echo $pid > $HOME/.pipeman:$DISPLAY.`basename $s`.ppid
pids="$pids $pid"
done
test -z "$pids" && die "Nothing to wait for"
wait $pids