#!/bin/bash 

if [ $(/usr/bin/whoami) != root ] ; then
  if [ -n "$SUDO_USER" ] ; then
    echo Already running under sudo
    exit 1
  fi
  /usr/bin/sudo -u root /usr/local/bin/down
else
  case "$(/usr/bin/tty)" in
    /dev/tty[1-9] | /dev/vc/[1-9] )
      ;;
    * )
      echo Not allowed to call DOWN
      exit 1
      ;;
  esac
  echo SHUTDOWN command initiated
  /sbin/shutdown -h -t 6 now
fi
