]>
Commit | Line | Data |
---|---|---|
8dbd5412 | 1 | #!/bin/sh |
2 | ||
3 | # run-parts - concept taken from Debian | |
4 | # | |
ffe19b59 | 5 | # modified for PLD Linux by Pawel Wilk <siefca@pld-linux.org> |
b55c6107 | 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 | # | |
8dbd5412 | 14 | |
15 | # keep going when something fails | |
16 | set +e | |
17 | ||
829777b0 AM |
18 | if [ "$1" = "-u" ]; then |
19 | workasuser=yes | |
20 | shift | |
1050f687 | 21 | fi |
829777b0 | 22 | |
b55c6107 | 23 | # std checks |
8dbd5412 | 24 | if [ $# -lt 1 ]; then |
829777b0 | 25 | echo "Usage: run-parts [-u] <dir> <args...>" |
8dbd5412 | 26 | exit 1 |
27 | fi | |
28 | ||
29 | if [ ! -d $1 ]; then | |
b55c6107 | 30 | echo "Is not a directory: $1" |
829777b0 | 31 | echo "Usage: run-parts [-u] <dir> <args...>" |
8dbd5412 | 32 | exit 1 |
33 | fi | |
34 | ||
b55c6107 | 35 | # assign passed dir name |
36 | RUNPARTS_DIR=$1 | |
37 | ||
38 | # assign absolute dir name | |
bf14fcab | 39 | olddir=$(pwd) |
b55c6107 | 40 | cd $RUNPARTS_DIR |
bf14fcab | 41 | RUNPARTS_ADIR=$(pwd) |
b55c6107 | 42 | cd $olddir |
43 | unset olddir | |
44 | ||
45 | # export directories for our descendants | |
46 | export RUNPARTS_ADIR RUNPARTS_DIR | |
47 | ||
48 | # shift args | |
49 | shift | |
50 | ||
6e2f824d | 51 | # Ignore *~ and *, scripts |
127911f1 | 52 | for i in $RUNPARTS_DIR/*[!~,] ; do |
1050f687 JR |
53 | [ -d "$i" ] && continue |
54 | # Don't run *.{rpmsave,rpmorig,rpmnew,swp} scripts | |
55 | [ "${i%.rpmsave}" != "${i}" ] && continue | |
56 | [ "${i%.rpmorig}" != "${i}" ] && continue | |
57 | [ "${i%.rpmnew}" != "${i}" ] && continue | |
58 | [ "${i%.swp}" != "${i}" ] && continue | |
59 | [ "${i%,v}" != "${i}" ] && continue | |
6e2f824d | 60 | |
1050f687 JR |
61 | if [ -x "$i" ]; then |
62 | runprog="$i $@" | |
63 | if [ "$workasuser" = "yes" ]; then | |
64 | runuser="$(/bin/ls -l "$i" | awk ' { print $3 } ' 2> /dev/null)" | |
65 | [ -z "$runuser" ] && echo "Warning: Can't find owner for [$i] file. Not running." && continue | |
66 | runprog="/bin/su $runuser -s /bin/sh -c $runprog" | |
67 | fi | |
68 | $runprog 2>&1 | awk -v "progname=$i" \ | |
69 | 'progname { | |
70 | print progname ":\n" | |
71 | progname=""; | |
72 | } | |
73 | { print; }' | |
74 | fi | |
8dbd5412 | 75 | done |
76 | ||
77 | exit 0 | |
1050f687 JR |
78 | |
79 | # This must be last line ! | |
80 | # vi:syntax=sh |