All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
   3 # shutdown -- wrapper script to guard against accidental shutdowns
 
   5 # Copyright © martin f. krafft <madduck@madduck.net>
 
   6 # Released under the terms of the Artistic Licence 2.0
 
  12 SCRIPTSDIR=/etc/molly-guard/run.d
 
  18   halt|reboot|shutdown|poweroff)
 
  19     if [ ! -f $EXEC ]; then
 
  20       echo "E: $ME: not a regular file: $EXEC" >&2
 
  23     if [ ! -x $EXEC ]; then
 
  24       echo "E: $ME: not an executable: $EXEC" >&2
 
  29     echo "E: $ME: unsupported command: $CMD" >&2
 
  37         Usage: $ME [options] [-- script options]
 
  40         molly-guard's primary goal is to guard against accidental
 
  41         shutdowns/reboots. $ME will run all scripts in $SCRIPTSDIR and only
 
  42         invokes $EXEC if all scripts exited successfully.
 
  44         Specifying --molly-guard-do-nothing as argument to the command will
 
  45         make $ME echo the command it would execute rather than actually
 
  48         Options following the double hyphen will be passed unchanged to the
 
  51         Please see molly-guard(8) for more information.
 
  53         The actual command's help output follows:
 
  64     (*-molly-guard-do-nothing) DO_NOTHING=1;;
 
  67       eval $EXEC --help 2>&1
 
  72       if [ $END_OF_ARGS -eq 0 ]; then
 
  73         CMDARGS="${args:+$args }$arg"
 
  75         SCRIPTARGS="${args:+$args }--arg $arg"
 
  83   if [ $DO_NOTHING -eq 1 ]; then
 
  84     echo "$ME: would run: $EXEC $CMDARGS"
 
  87     eval exec $EXEC "$CMDARGS"
 
  91 if [ $DO_NOTHING -eq 1 ]; then
 
  92   echo "I: demo mode; $ME will not do anything due to --molly-guard-do-nothing." >&2
 
  95 # pass through certain commands
 
  96 case "$CMD $CMDARGS" in
 
  98     # allow canceling shutdowns
 
  99     echo "I: executing $CMD $CMDARGS regardless of check results." >&2
 
 104 MOLLYGUARD_CMD=$CMD; export MOLLYGUARD_CMD
 
 105 MOLLYGUARD_DO_NOTHING=$DO_NOTHING; export MOLLYGUARD_DO_NOTHING
 
 106 MOLLYGUARD_SETTINGS="/etc/molly-guard/rc"; export MOLLYGUARD_SETTINGS
 
 108 for script in $(run-parts --test $SCRIPTSDIR); do
 
 110   eval $script $SCRIPTARGS || ret=$?
 
 111   if [ $ret -ne 0 ]; then
 
 112     echo "W: aborting $CMD due to ${script##*/} exiting with code $ret." >&2