]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ||
3 | # run-parts - concept taken from Debian | |
4 | # | |
5 | # modified for PLD Linux by Pawel Wilk <siefca@pld-linux.org> | |
6 | # | |
7 | # NOTE: | |
8 | # 1.) run-parts is now able to get arguments! | |
9 | # 2.) relative pathname of the invoked directory can be | |
10 | # obtained by reading RUNPARTS_DIR env. variable | |
11 | # 3.) absolute pathname of the invoked directory can be | |
12 | # obtained by reading RUNPARTS_ADIR env. variable | |
13 | # | |
14 | ||
15 | # keep going when something fails | |
16 | set +e | |
17 | ||
18 | if [ "$1" = "--test" ]; then | |
19 | test=yes | |
20 | shift | |
21 | fi | |
22 | ||
23 | if [ "$1" = "--" ]; then | |
24 | shift | |
25 | fi | |
26 | ||
27 | # std checks | |
28 | if [ $# -lt 1 ]; then | |
29 | echo "Usage: run-parts [-u] [--test] <dir> <args...>" | |
30 | exit 1 | |
31 | fi | |
32 | ||
33 | if [ ! -d $1 ]; then | |
34 | echo "Is not a directory: $1" | |
35 | echo "Usage: run-parts [-u] [--test] <dir> <args...>" | |
36 | exit 1 | |
37 | fi | |
38 | ||
39 | # assign passed dir name | |
40 | RUNPARTS_DIR=$1 | |
41 | ||
42 | # assign absolute dir name | |
43 | olddir=$(pwd) | |
44 | cd $RUNPARTS_DIR | |
45 | RUNPARTS_ADIR=$(pwd) | |
46 | cd $olddir | |
47 | unset olddir | |
48 | ||
49 | # export directories for our descendants | |
50 | export RUNPARTS_ADIR RUNPARTS_DIR | |
51 | ||
52 | # shift args | |
53 | shift | |
54 | ||
55 | # Ignore *~ and *, scripts | |
56 | for i in $RUNPARTS_DIR/*[!~,] ; do | |
57 | [ -d "$i" ] && continue | |
58 | # Don't run *.{rpmsave,rpmorig,rpmnew,swp} scripts | |
59 | [ "${i%.rpmsave}" != "${i}" ] && continue | |
60 | [ "${i%.rpmorig}" != "${i}" ] && continue | |
61 | [ "${i%.rpmnew}" != "${i}" ] && continue | |
62 | [ "${i%.swp}" != "${i}" ] && continue | |
63 | [ "${i%,v}" != "${i}" ] && continue | |
64 | ||
65 | if [ -x "$i" ]; then | |
66 | runprog="$i $@" | |
67 | if [ "$test" = yes ]; then | |
68 | echo "$runprog" | |
69 | continue | |
70 | fi | |
71 | $runprog 2>&1 | awk -v "progname=$i" \ | |
72 | 'progname { | |
73 | print progname ":\n" | |
74 | progname=""; | |
75 | } | |
76 | { print; }' | |
77 | fi | |
78 | done | |
79 | ||
80 | exit 0 |