#!/bin/sh
# <pere> and do not reimplement system binaries. :)

BIN=`basename $0`

case "$BIN" in
    "hult") 
            EXE="halt"
	    ;;
    "rebuut") 
            EXE="reboot"
	    ;;
    *)
	    echo "$0: Dat jibet doch jarnich."
	    exit -1
	    ;;
esac

if [ `hostname` = wr-linux02 ] ; then
    echo "Halt oder reboot durch Nutzer auf `hostname` ist nicht gewnscht."
    exit
fi

if [ `hostname` != sputnik ] ; then
   if ps ax | grep -v grep | grep -w -q "sshd:" ; then
      echo "Es bestehen noch ssh-Verbindungen zu anderen Rechnern."
      exit
   fi

   OTHERS=`who | sed "s/[[:space:]]\+.*//" | sort | uniq | grep -v $USER`
   if [ _"$OTHERS" != _"" ] ; then 
      echo "Es sind noch andere Nutzer angemeldet: $OTHERS"
      exit
   fi
fi

sudo /sbin/${EXE}
