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
13 SCRIPTSDIR="${0%/*}/run.d"
19 halt|reboot|shutdown|poweroff)
20 if [ ! -f $EXEC ]; then
21 echo "E: $ME: not a regular file: $EXEC" >&2
24 if [ ! -x $EXEC ]; then
25 echo "E: $ME: not an executable: $EXEC" >&2
30 echo "E: $ME: unsupported command: $CMD" >&2
38 Usage: $ME [options] [-- script options]
41 molly-guard's primary goal is to guard against accidental
42 shutdowns/reboots. $ME will run all scripts in $SCRIPTSDIR and only
43 invokes $EXEC if all scripts exited successfully.
45 Specifying --molly-guard-do-nothing as argument to the command will
46 make $ME echo the command it would execute rather than actually
49 Options following the double hyphen will be passed unchanged to the
52 Please see molly-guard(8) for more information.
54 The actual command's help output follows:
65 (*-molly-guard-do-nothing) DO_NOTHING=1;;
68 eval $EXEC --help 2>&1
73 if [ $END_OF_ARGS -eq 0 ]; then
74 CMDARGS="${args:+$args }$arg"
76 SCRIPTARGS="${args:+$args }--arg $arg"
84 if [ $DO_NOTHING -eq 1 ]; then
85 echo "$ME: would run: $EXEC $CMDARGS"
88 eval exec $EXEC "$CMDARGS"
92 if [ $DO_NOTHING -eq 1 ]; then
93 echo "I: demo mode; $ME will not do anything due to --molly-guard-do-nothing." >&2
96 # pass through certain commands
97 case "$CMD $CMDARGS" in
99 # allow canceling shutdowns
100 echo "I: executing $CMD $CMDARGS regardless of check results." >&2
105 MOLLYGUARD_CMD=$CMD; export MOLLYGUARD_CMD
106 MOLLYGUARD_DO_NOTHING=$DO_NOTHING; export MOLLYGUARD_DO_NOTHING
107 MOLLYGUARD_SETTINGS="/etc/default/$ME"; export MOLLYGUARD_SETTINGS
109 for script in $(run-parts --test $SCRIPTSDIR); do
111 eval $script $SCRIPTARGS || ret=$?
112 if [ $ret -ne 0 ]; then
113 echo "W: aborting $CMD due to ${script##*/} exiting with code $ret." >&2