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
38 (*--molly-guard-do-nothing*)
39 ARGS0="${ARGS%%--molly-guard-do-nothing*}"
40 ARGS1="${ARGS##*--molly-guard-do-nothing}"
41 echo "$ME: would run: $EXEC ${ARGS0# } ${ARGS1# }"
43 *) eval exec $EXEC "$ARGS";;
47 # require an interactive terminal connected to stdin
48 test -t 0 || do_real_cmd
50 # only run if we are being called over SSH, that is if the current terminal
51 # was created by sshd.
52 PTS=$(readlink /proc/$$/fd/0)
53 pgrep -f "^sshd.+${PTS#/dev/}[[:space:]]*$" >/dev/null || do_real_cmd
55 # pass through help commands
57 (shutdown\ *-c*) do_real_cmd;;
58 (shutdown\ *-h*) do_real_cmd;;
59 (*--help*) do_real_cmd;;
63 HOSTNAME="$(hostname)"
67 echo "Good thing I asked; I won't $CMD $HOSTNAME ..."
71 trap 'echo;sigh' 1 2 3 9 10 12 15
73 echo "$ME: SSH session detected!"
74 echo -n "Please type in hostname of the machine to $CMD: "
75 read HOSTNAME_USER || :
77 [ "$HOSTNAME_USER" = "$HOSTNAME" ] || sigh
79 trap - 1 2 3 9 10 12 15