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 # molly-guard -- 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
 
  12 ALWAYS_MOLLY=${ALWAYS_MOLLY:-"0"}
 
  13 [ -f /etc/default/${ME} ] && . /etc/default/${ME}
 
  21       eval $EXEC --help 2>&1
 
  24     (*-pretend-ssh) PRETEND_SSH=1;;
 
  28 # require an interactive terminal connected to stdin
 
  31 # we've been asked to always protect this host
 
  32 if [ ${ALWAYS_MOLLY} -eq 1 ]; then
 
  33   echo "W: $ME: ${CMD} is always molly-guarded on this server."
 
  35   # only run if we are being called over SSH, that is if the current terminal
 
  36   # was created by sshd.
 
  37   PTS=$(readlink /proc/$$/fd/0)
 
  38   if ! pgrep -f "^sshd.+${PTS#/dev/}[[:space:]]*$" >/dev/null \
 
  39     && [ -z "${SSH_CONNECTION:-}" ]; then
 
  40       if [ $PRETEND_SSH -eq 1 ]; then
 
  41         echo "I: this is not an SSH session, but --pretend-ssh was given..."
 
  46     echo "W: $ME: SSH session detected!"
 
  51 HOSTNAME="$(hostname --short)"
 
  55   echo "Good thing I asked; I won't $CMD $HOSTNAME ..."
 
  59 trap 'echo;sigh' 1 2 3 9 10 12 15
 
  61 echo -n "Please type in hostname of the machine to $CMD: "
 
  62 read HOSTNAME_USER || :
 
  64 [ "$HOSTNAME_USER" = "$HOSTNAME" ] || sigh
 
  66 trap - 1 2 3 9 10 12 15