Release new version 0.4.0
[grml-policyrcd.git] / policy-rc.d
1 #!/bin/sh
2 # Filename:      policy-rc.d
3 # Purpose:       interface script for invoke-rc.d (see /etc/policy-rc.d.conf)
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 ################################################################################
8
9 ## test for chroot
10 # make sure /proc/1/root can be read, if not either /proc is not mounted
11 # or it is not executed with root permissions (and "sudo invoke-rc.d $service"
12 # might fail), if so don't continue
13 if [ -d /proc/1 ] && readlink -f /proc/1/root >/dev/null 2>&1; then
14   if test "$(/usr/bin/stat -c "%d/%i" /)" != "$(/usr/bin/stat -Lc "%d/%i" /proc/1/root 2>/dev/null)" ; then
15      # notify invoke-rc.d that nothing should be done -- we are in a chroot
16      exit 101
17   fi
18 fi
19
20 # read configuration file
21 if [ -z "$POLICYRCD" ] ; then
22   if [ -r /etc/policy-rc.d.conf ] ; then
23      . /etc/policy-rc.d.conf
24   fi
25 fi
26
27 if [ -z "$POLICYRCD" ]; then
28   for file in /usr/local/sbin/policy-rc.d /etc/policy-rc.d; do
29     if [ -x "$file" ]; then
30       POLICYRCD="$file"
31       break
32     fi
33   done
34 fi
35
36 # if $POLICYRCD is set or either /usr/local/sbin/policy-rc.d
37 # or /etc/policy-rc.d are present execute them:
38 if [ -n "$POLICYRCD" ]; then
39   $POLICYRCD "$@"
40   exit $?
41 else
42   # otherwise exit with $EXITSTATUS,
43   # being '0' by default
44   if [ -n "$EXITSTATUS" ]; then
45      exit "$EXITSTATUS"
46   else
47      # or if $EXITSTATUS isn't set just allow it
48      exit 0
49   fi
50 fi
51
52 ## END OF FILE #################################################################