-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinitscripts_dep.sh
executable file
·59 lines (58 loc) · 1.33 KB
/
initscripts_dep.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
## init.d functions
# you can add other directories (space-separated) in here
readonly INIT_D_DIR='/etc/init.d'
# show a function from initscript/s (and/or glob/s eg 's*')
ifunc(){
local d f r s=$1 fn="^[[:blank:]]*$1"'\(\)' br='[[:blank:]]*\{'
shift
for d in $INIT_D_DIR; do
for g; do
for f in "$d/"$g; do
[ -f "$f" ] || continue
r=$(sed -En "/$fn($br)?/,/^}/{/^}/q;/$fn$br/n;/$fn/{N;n;};p}" "$f")
[ "$r" ] && printf '%s\n%s\n' "$f: $s" "$r"
done
done
done
}
# convenience wrappers for the common funcs
idepend(){
ifunc depend "$@"
}
istart(){
ifunc start "$@"
}
istop(){
ifunc stop "$@"
}
ireload(){
ifunc reload "$@"
}
icheckconfig(){
ifunc checkconfig "$@"
}
# show the functions defined by an initscript/glob, or all if no args
ishow(){
local d f
for d in $INIT_D_DIR; do
if [ "$*" ]; then
for f; do
[ "$f" ] && _ishow "$d/$f"
done
else _ishow "$d/*"
fi
done
}
_ishow(){
grep -H '^[[:blank:]]*[[:alpha:]_][[:alnum:]_]*()' "$1" | {
curr=
while IFS=' :' read -r fname func _; do
[ "$curr" = "$fname" ] || {
[ "$curr" ] && echo "${curr##*/}:$f"
curr=$fname f=
}
f+=" ${func%%'()'*}"
done
[ "$curr" ] && echo "${curr##*/}:$f"
}
}