]> git.madduck.net Git - code/molly-guard.git/blob - shutdown

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

0a6efd6011e590fea9ef6e80dc6ae0c2ce48fe37
[code/molly-guard.git] / shutdown
1 #!/bin/sh
2 #
3 # shutdown -- wrapper script to prevent erroneous shutdowns via SSH
4 #
5 # Copyright © martin f. krafft <madduck@madduck.net>
6 # Released under the terms of the Artistic Licence 2.0
7 #
8 # $Id: shutdown 299 2006-10-16 14:40:47Z madduck $
9 #
10 set -eu
11
12 CMD="${0##*/}"
13 EXEC="/sbin/$CMD"
14 case "$CMD" in
15   halt|reboot|shutdown)
16     if [ ! -x $EXEC ]; then
17       echo "E: not an executable: $EXEC" >&2
18       exit 3
19     fi
20     ;;
21   *)
22     echo "E: unsupported command: $CMD" >&2
23     exit 1
24     ;;
25 esac
26
27 if [ -n "${SSH_CONNECTION:-}" ] && test -t 0 && [ "${1:-}" != '--help' ]; then
28   echo -n "SSH session detected, type in hostname of the machine to $CMD: "
29   read HOSTNAME_USER
30
31   HOSTNAME="$(hostname)"
32
33   if [ "$HOSTNAME_USER" != "$HOSTNAME" ]; then
34     echo "Good thing I asked; I won't $CMD $HOSTNAME ..."
35     exit 2
36   fi
37 fi
38
39 exec $EXEC "$@"