summaryrefslogtreecommitdiff
path: root/tweaks/usr/local/sbin/policy-rc.d
blob: b89a676742e0fda4e13d5b244bbd384f75830e20 (plain)
  1. #!/bin/sh
  2. $Id: policy-rc.d,v 1.3 2006/04/22 16:04:55 jonas Exp $
  3. #
  4. # Copyright © 2006 Jonas Smedegaard <dr@jones.dk>
  5. # Description: Suppress system V scripts if invoked within a chroot.
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License as
  9. # published by the Free Software Foundation; either version 2, or (at
  10. # your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # General Public License for more details.
  16. # Policy-rc.d is mentioned in manpage invoke-rc.d(8) and documented at
  17. # http://people.debian.org/~hmh/invokerc.d-policyrc.d-specification.txt
  18. set -e
  19. PRG=`basename $0`
  20. TEMP=`getopt -s sh --long list,quiet -n "$PRG" -- "$@"`
  21. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  22. eval set -- "$TEMP"
  23. quiet=""
  24. list=""
  25. while true ; do
  26. case "$1" in
  27. --quiet) quiet="1" ; shift ;;
  28. --list) list="1" ; shift ;;
  29. --) shift ; break ;;
  30. *) echo "Internal error!" ; exit 1 ;;
  31. esac
  32. done
  33. initscript="$1"
  34. actions="$2"
  35. runlevel="$3"
  36. if [ "$list" ]; then
  37. cat <<EOF
  38. The following policies are known to this policy daemon:
  39. default: All actions are allowed.
  40. chroot: If invoked from within a chroot environment,
  41. no actions are allowed, else all are allowed.
  42. This policy daemon care not about actions, so all standard actions
  43. (start, [force-]stop, restart, [force-]reload and status), and any
  44. additionally implemented ones, are supported.
  45. EOF
  46. exit 0
  47. fi
  48. if [ ! -r /proc/1/root ]; then
  49. if ! [ "$quiet" ]; then
  50. echo >&2 "Chroot environment detected, suppressing sysV script."
  51. fi
  52. exit 101
  53. fi
  54. exit 0