[Lunar-commits] <lunar-tools> run-parts: new utility (moved from cron-common)

Stefan Wold ratler at lunar-linux.org
Thu Aug 23 19:40:27 CEST 2012


commit c8634d77d2efbf7c57f3de7a8da6039ac2df29c2
Author: Stefan Wold <ratler at lunar-linux.org>
Date: Thu, 23 Aug 2012 10:40:27 -0700
URL: https://github.com/lunar-linux/lunar-tools/commit/c8634d77d2efbf7c57f3de7a8da6039ac2df29c2

run-parts: new utility (moved from cron-common)

Since other modules now also depend in run-parts it has been moved
to lunar-tools.

This run-parts has been further modified to also work with modules
like resolvconf.
---
  Makefile                                                     +5/-0     
  prog/run-parts                                               +80/-0    
  2 files changed, 85 insertions (+), 0 deletions (-)

--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,7 @@
 # i.e. 2004.9 2004.10 2004.11 ...
 VERSION = 2012.7
 
+bin_PROGS = prog/run-parts
 sbin_PROGS = prog/lids prog/luser prog/lnet prog/lservices \
 	prog/lmodules prog/clad prog/ltime
 DOCS = README COPYING
@@ -18,6 +19,10 @@ all:
 install: .PHONY
 	install -d $(DESTDIR)/sbin
 	install -m755 prog/installkernel $(DESTDIR)/sbin/
+	install -d $(DESTDIR)/usr/bin
+	for PROGRAM in ${bin_PROGS} ; do \
+	    install -m755 $${PROGRAM} $(DESTDIR)/usr/bin/ ; \
+	done
 	install -d $(DESTDIR)/usr/sbin
 	for PROGRAM in ${sbin_PROGS} ; do \
 	    install -m755 $${PROGRAM} $(DESTDIR)/usr/sbin/ ; \
--- /dev/null
+++ b/prog/run-parts
@@ -0,0 +1,80 @@
+#!/bin/bash
+# Parts ripped from fedora which has borrowed the concept from debian
+#
+# Dont stop on fail
+set +e
+
+if [ $# -lt 1 ]; then
+  echo "Usage: run-parts [--list | --test | --cron | -a <val> ... | --arg=<val> ... ] <dir>"
+  exit 1
+fi
+
+while [ $# -gt 1 ]; do
+  case $1 in 
+    -a)
+      PARAMS+=" $2"
+      shift 2
+      ;;
+    --arg*)
+      PARAMS+=" ${1/--arg=/}"
+      shift
+      ;;
+    --list)
+      list=1
+      shift
+      break
+      ;;
+    --test)
+      test=1
+      shift
+      break
+      ;;
+    --cron)
+      cron=1
+      shift
+      break
+      ;;
+    --)
+      break
+      ;;
+    *)
+      break
+      ;;
+  esac
+done
+
+if [ ! -d $1 ]; then
+  echo "Not a directory: $1"
+  exit 1
+fi
+
+for i in $(LC_ALL=C; echo ${1%/}/*[^~,]) ; do
+  [ -d $i ] && continue
+  [ "${i%.swp}" != "${i}" ] && continue
+  [ "${i%,v}" != "${i}" ] && continue
+
+  if [ -e $i ]; then
+    if [ ${list:-0} = 1 ]; then
+      echo $i
+    elif [ -x $i ]; then
+      if [ ${test:-0} = 1 ]; then
+        echo $i
+        continue
+      fi
+      
+      if [ ${cron:-0} = 1 ]; then
+        logger -i -p cron.notice -t "run-parts($1)" "starting $(basename $i)"
+        $i 2>&1 | awk -v "progname=$i" \
+                'progname {
+                    print progname ":\n"
+                    progname="";
+                 }
+                 { print; }'
+        logger -i -p cron.notice -t "run-parts($1)" "finished $(basename $i)"
+      else
+        $i $PARAMS 2>&1
+      fi
+    fi
+  fi
+done
+exit 0




More information about the Lunar-commits mailing list