:
#  Title        : AbgewaThu, 29-Apr-93 / 10:50 / (es,/etc/shutdown,aus,pf+)
#                 dem SCO UNIX fuer SCO Xenix.  Wird unter SCO Xenix von 
#                 /bitslib/service/shutdown.sh aus aufgerufen.
#  Created      :       ???, ??-Mar-93 / ??:?? / (mk)
#  Version      :       Thu, 29-Apr-93 / 10:49 / (mk,pf)
#
#	@(#) shutdown.sh 1.6 86/12/22 
#
#	Copyright (C) The Santa Cruz Operation, 1985.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, Microsoft Corporation
#	and AT&T, and should be treated as Confidential.
#
#
#	shutdown [time] [su]
#
#	Bring the system down gracefully and ruthlessly.
#	1.  Warn users.
#	2.  Kill off any user or daemon tasks.
#	3.  Dismount disks.
#	4.  sync and halt processor, or go single user
#
#	SIGINT		causes things to go faster by skipping a minute.
#	SIGQUIT		terminates the program.  Be careful if it has
#			already started to kill off things.
#
PATH=/bin:/usr/bin:/usr/local/bin

# If you want a default shutdown time, change the min variable
min=
su=no
single=no
args=$*

set -- `who am i`
#
# Der Test, ob Aufruf von der Console direkt und interaktiv erfolgt ist, 
# ist hier weggelassen, damit die Sache auch aus shutdown.sh heraus
# gestartet werden kann.
#

case $2 in
"")	single=yes
	tty="?"
	;;
tty*)	tty=`expr "$2" : "tty\(..\)"`
	;;
*)	echo "shutdown: must be run from a tty." >&2
	exit 1
esac

for i in $args
do
	case $i in
	[0-9]|[01][0-5]) min=$i	;;
	su)	su=yes		;;
	"")	break		;;
	*)	echo "shutdown: unknown argument $i" >&2
		echo "Usage: shutdown [time] [su]" >&2
		exit 1		;;
	esac
done

[ "$min" ] ||
	while	echo "Minutes till shutdown? (0-15): \c" >&2
		read min
	do	case $min in
		[0-9]|[01][0-5])	break	;;
		*)	echo "Please enter a number between 0 and 15" >&2
		esac
	done

trap "continue" 2
while	[ "$min" -gt 0 ]
do	left=$min
	min=`expr "$min" - 1`
	[ "$left" -le 2 ] && kill -3 1
	case $left in
	[0-5]|10|15) echo "
XENIX Shutdown in $left minutes.
Clean up and log off.\007\n" | /etc/wall
	esac
	users=`who | grep -v tty$tty`
	case $users in
	"")	echo "All users logged off now."; break	;;
	*)	echo "$users"				;;
	esac
	sleep 60
done
trap 2
kill -3 1

case $su in
yes)	echo '\nPlease wait for the startup message.\n'	;;
no)	echo '\nPlease wait for the "**  Normal System Shutdown  **" message.\n'
esac

case $single in
no)
	echo "\nXENIX will now terminate.\n" | /etc/wall
	for sig in -15 -9
	do	# skip ps header, swapper, init and all procs attached to tty
		pids=`ps -e | awk "NR > 3 && "'$2'" !~ /$tty/ { print "'$1'" }"`
		[ "$pids" ] || break
		echo kill $sig $pids
		kill $sig $pids
		sleep 5
	done
	;;
yes)
	echo "\nXENIX will now terminate.\n"
	;;
esac

[ "$pids" ] && ps -e
[ -f /etc/accton ] && /etc/accton

sync
mnt=`/etc/mount | grep -v root | sort +2r | sed "s/ on .*//"`
for i in $mnt
do
	/etc/umount $i
done

sync
[ "$mnt" ] && /etc/mount

[ "$su" = no ] && {
	sync
	/etc/haltsys
	echo "haltsys failed! going single user ....\007"
}
[ "$single" = no ] && exec kill -1 1
