| 1 | #!/bin/bash |
| 2 | # drbl-run-parts - modified from Fedora 17's run-parts in crontabs package. License is GPLv2. |
| 3 | # The reason we do not use run-parts from Debian is people are always confused: |
| 4 | # http://drbl.org/faq/fine-print.php?path=./2_System/31_prerun_postrun_not_working.faq#31_prerun_postrun_not_working.faq |
| 5 | |
| 6 | # keep going when something fails |
| 7 | set +e |
| 8 | |
| 9 | if [ $# -lt 1 ]; then |
| 10 | echo "Usage: run-parts [--list | --test] <dir>" |
| 11 | exit 1 |
| 12 | fi |
| 13 | |
| 14 | while [ $# -gt 1 ]; do |
| 15 | case $1 in |
| 16 | --list) |
| 17 | list=1 |
| 18 | shift |
| 19 | break |
| 20 | ;; |
| 21 | --test) |
| 22 | test=1 |
| 23 | shift |
| 24 | break |
| 25 | ;; |
| 26 | --) |
| 27 | # -- end of options |
| 28 | shift |
| 29 | break |
| 30 | ;; |
| 31 | *) |
| 32 | # directory |
| 33 | break |
| 34 | ;; |
| 35 | esac |
| 36 | done |
| 37 | |
| 38 | if [ ! -d $1 ]; then |
| 39 | echo "Not a directory: $1" |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
| 43 | # Ignore *~ and *, scripts |
| 44 | for i in $(LC_ALL=C; echo ${1%/}/*[^~,]) ; do |
| 45 | [ -d $i ] && continue |
| 46 | if [ -e $i ]; then |
| 47 | if [ -x $i ]; then |
| 48 | # run executable files |
| 49 | $i |
| 50 | fi |
| 51 | fi |
| 52 | done |
| 53 | |
| 54 | exit 0 |