:
# @(#)shutdown 5.3b of Jan 28, 1988
:
#	Sequence performed to change the init stat of a machine.

#	This procedure checks to see if you are permitted and allows an
#	interactive shutdown.  The actual change of state, killing of
#	processes and such are performed by the new init state, say 0,
#	and its /etc/rc0.

#	Usage:  shutdown [ <grace-period> ]

TTY=`tty`
a=`basename ${TTY}`
if [ "$a" != "console" -a "$a" != "syscon" ]
then
	echo "$0: You must be on the console to shut the system down." 1>&2
	exit 1
fi
a=`pwd`
if [ "$a" != "/" -a "$a" != "@`uname -n`" ]
then
	echo "$0:  You must be in the / directory to run /etc/shutdown."
	exit 1
fi

#	Check the user id.
if [ -x /usr/bin/id ]
then
	eval `id  |  sed 's/[^a-z0-9=].*//'`
	if [ "${uid:=0}" -ne 0 ]
	then
	        echo "$0:  Only root can run /etc/shutdown."
		exit 2
	fi
fi

grace=60
askconfirmation=
initstate=5
while [ $# -gt 0 ]
do
	case $1 in
	[0-9]* )
		grace="$1"
		;;
	-* )
		echo "Illegal flag argument '$1'"
		exit 1
		;;
	* )
		echo "Usage:  $0  [ <grace-period> ]"
		exit 1
	esac
	shift
done

if [ -n "${askconfirmation}" -a -x /etc/ckbupscd ]
	then
	#	Check to see if backups are scheduled at this time
	BUPS=`/etc/ckbupscd`
	if [ "$BUPS" != "" ]
		then
		echo "$BUPS"
		echo "Do you wish to abort this shutdown and return to 
command level to do these backups? [y, n] \c"
		read YORN
		if [ "$YORN" = "y" -o "$YORN" = "Y" ]
			then 
			exit 1
		fi
	fi
fi

if [ -z "${TZ}"  -a  -r /etc/TIMEZONE ]
then
	. /etc/TIMEZONE
fi

echo '
Shutdown started.    \c'
date
echo

sync
cd /

trap "exit 1"  1 2 15

a="`who  |  wc -l`"
if [ ${a} -gt 1  -a  ${grace} -gt 0 ]
then
	su -n root -c /etc/wall<<-!
		PLEASE LOG OFF NOW ! ! !
		All processes will be killed in ${grace} seconds.

	!
	sleep ${grace}
fi

/etc/wall <<-!

	THE SYSTEM IS BEING BROUGHT DOWN NOW ! ! !

!

if [ ${a} -gt 1  -a  ${grace} -gt 0 ]
then
	sleep 20
fi

if [ ${askconfirmation} ]
then
     echo "Do you want to continue the shutdown procedure ? (y or n):   \c"
     read b
else
	b=y
fi
case $b in
	[yY][eE][sS] | [yY] )
		;;
	* )
		/etc/wall <<-\!
			False Alarm:  The system will not be brought down.
		!
		echo 'Shut down aborted.'
		exit 1
		;;
esac
/etc/init ${initstate}
/bin/kill -9 0
