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
8 # $Id: shutdown 299 2006-10-16 14:40:47Z madduck $
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
40 Instead of invoking $EXEC directly, $ME will run a number of checks
41 to guard against accidental shutdowns/reboots.
43 Some of the checks available are:
44 - Prompt the user for the machine's if the current shell is a child
45 of an SSH connection (or --pretend-ssh) has been given on the
46 command line, if the shell is connected to an interactive
47 terminal, and the actual command to execute is does not involve
48 --help or is \`shutdown -c'.
50 Only if the user satisfies all the checks will $ME take action.
51 Specifying --molly-guard-do-nothing as argument to the command will
52 make $ME echo the command it would execute rather than actually executing
55 The actual command's help output follows:
65 (*-molly-guard-do-nothing) DO_NOTHING=1;;
68 eval $EXEC --help 2>&1
71 (*-pretend-ssh) CHECK_ARGS="${CHECK_ARGS:+$CHECK_ARGS }--arg --pretend-ssh";;
72 *) ARGS="${ARGS:+$ARGS }$arg";;
78 if [ $DO_NOTHING -eq 1 ]; then
79 echo "$ME: would run: $EXEC $ARGS"
82 eval exec $EXEC "$ARGS"
86 if [ $DO_NOTHING -eq 1 ]; then
87 echo "I: demo mode; $ME will not do anything due to --molly-guard-do-nothing."
90 # pass through certain commands
93 echo "I: executing $CMD $ARGS regardless of check results."
98 run-parts --exit-on-error $CHECK_ARGS /usr/share/molly-guard/checks.d
100 # run-parts won't return to us if there are failures, but I'm paranoid.