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 prevent erroneous shutdowns via SSH
5 # Copyright © martin f. krafft <madduck@madduck.net>
6 # Released under the terms of the Artistic Licence 2.0
11 CHECKSDIR=/etc/molly-guard/checks.d
17 halt|reboot|shutdown|poweroff)
18 if [ ! -f $EXEC ]; then
19 echo "E: $ME: not a regular file: $EXEC" >&2
22 if [ ! -x $EXEC ]; then
23 echo "E: $ME: not an executable: $EXEC" >&2
28 echo "E: $ME: unsupported command: $CMD" >&2
39 Instead of invoking $EXEC directly, $ME will run a number of checks
40 to guard against accidental shutdowns/reboots.
42 Some of the checks available are:
43 - Prompt the user for the machine's if the current shell is a child
44 of an SSH connection (or --pretend-ssh) has been given on the
45 command line, if the shell is connected to an interactive
46 terminal, and the actual command to execute is does not involve
47 --help or is \`shutdown -c'.
49 $ME will always interpose the prompt if the environment variable
50 ALWAYS_MOLLY is set to '1'. This variable may be set in the file
53 - Print out a warning message with information about this host
54 before the action takes place. You can use:
55 /etc/molly-guard.<Action>.message
56 To print out a message specific to the command you're trying to
58 /etc/molly-guard.message
59 For a general warning message.
61 Only if the user satisfies all the checks will $ME take action.
62 Specifying --molly-guard-do-nothing as argument to the command will
63 make $ME echo the command it would execute rather than actually executing
66 The actual command's help output follows:
76 (*-molly-guard-do-nothing) DO_NOTHING=1;;
79 eval $EXEC --help 2>&1
82 (*-pretend-ssh) CHECK_ARGS="${CHECK_ARGS:+$CHECK_ARGS }--arg --pretend-ssh";;
83 *) ARGS="${ARGS:+$ARGS }$arg";;
89 if [ $DO_NOTHING -eq 1 ]; then
90 echo "$ME: would run: $EXEC $ARGS"
93 eval exec $EXEC "$ARGS"
97 if [ $DO_NOTHING -eq 1 ]; then
98 echo "I: demo mode; $ME will not do anything due to --molly-guard-do-nothing."
101 # pass through certain commands
104 echo "I: executing $CMD $ARGS regardless of check results."
109 run-parts --exit-on-error --arg $CMD $CHECK_ARGS /etc/molly-guard/checks.d
111 # run-parts won't return to us if there are failures, but I'm paranoid.