]> git.pld-linux.org Git - projects/rc-scripts.git/blob - run-parts
- 0.4.1.20
[projects/rc-scripts.git] / run-parts
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" = "-u" ]; then
19         workasuser=yes
20         shift
21 fi
22
23 # std checks
24 if [ $# -lt 1 ]; then
25         echo "Usage: run-parts [-u] <dir> <args...>"
26         exit 1
27 fi
28
29 if [ ! -d $1 ]; then
30         echo "Is not a directory: $1"
31         echo "Usage: run-parts [-u] <dir> <args...>"
32         exit 1
33 fi
34
35 # assign passed dir name
36 RUNPARTS_DIR=$1
37
38 # assign absolute dir name
39 olddir=$(pwd)
40 cd $RUNPARTS_DIR
41 RUNPARTS_ADIR=$(pwd)
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
51 # Ignore *~ and *, scripts
52 for i in $RUNPARTS_DIR/*[!~,] ; do
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
60
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
75 done
76
77 exit 0
78
79 # This must be last line !
80 # vi:syntax=sh
This page took 0.038279 seconds and 3 git commands to generate.