Rework policy-rc.d handling.
[grml-policyrcd.git] / policy-rc.d
similarity index 50%
rename from grml-policy-rc.d
rename to policy-rc.d
index 9e4340f..3964dc5 100755 (executable)
@@ -1,10 +1,9 @@
 #!/bin/sh
-# Filename:      grml-policy-rc.d
+# Filename:      policy-rc.d
 # Purpose:       interface script for invoke-rc.d (see /etc/policy-rc.d.conf)
 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
 # License:       This file is licensed under the GPL v2.
-# Latest change: Mit Okt 18 20:43:22 UTC 2006 [mika]
 ################################################################################
 
 # test for chroot
@@ -14,15 +13,35 @@ if test "$(/usr/bin/stat -c "%d/%i" /)" != "$(/usr/bin/stat -Lc "%d/%i" /proc/1/
 fi
 
 # read configuration file
-if [ -r /etc/policy-rc.d.conf ] ; then
-   . /etc/policy-rc.d.conf
+if [ -z "$POLICYRCD" ] ; then
+  if [ -r /etc/policy-rc.d.conf ] ; then
+     . /etc/policy-rc.d.conf
+  fi
 fi
 
-if [ -n "$EXITSTATUS" ]; then
-   exit "$EXITSTATUS"
+if [ -z "$POLICYRCD" ]; then
+  for file in /usr/local/sbin/policy-rc.d /etc/policy-rc.d; do
+    if [ -x "$file" ]; then
+      POLICYRCD="$file"
+      break
+    fi
+  done
+fi
+
+# if $POLICYRCD is set or either /usr/local/sbin/policy-rc.d
+# or /etc/policy-rc.d are present execute them:
+if [ -n "$POLICYRCD" ]; then
+  $POLICYRCD "$@"
+  exit $?
 else
-   # allow it
-   exit 0
+  # otherwise exit with $EXITSTATUS,
+  # being '0' by default
+  if [ -n "$EXITSTATUS" ]; then
+     exit "$EXITSTATUS"
+  else
+     # or if $EXITSTATUS isn't set just allow it
+     exit 0
+  fi
 fi
 
 ## END OF FILE #################################################################