# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.
#ident	"$Header: firmware 1.2 89/10/10 $@(#)sadmin:admin/menu/machinemgmt/firmware	2.3"
#menu# stop all running programs then enter firmware mode
#help# 
#help#	This procedure will stop all running programs, close any open files,
#help#	write out information to disk (such as directory information), and
#help#	then enter the firmware mode.  From firmware mode one can run machine
#help#	diagnostics and other special functions not available from UNIX.

trap 'exit 0' 1 2  15
flags="-qq -k$$"

cd /
wholist=`who`
if [ `echo "${wholist}"  |  wc -l` -gt 1 ]
then
	echo "Users currently logged in:\\n${wholist}"
fi

if  checkyn ${flags} -f -H'
	An express to firmware brings the system down as fast as possible and
	enter firmware mode.  It is not a very friendly thing to do on a system
	which several users are using.
	Entering  q  will quit this procedure.' \
	'Once started, this procedure CANNOT BE STOPPED.
Do you want to go to firmware "express"?'
then
	grace=0
else
	grace=`checkre ${flags} -D60 -fe -H'
	There are 1 or 2 warning messages (depending on whether there is more
	than one user on the system) before the system is shut down.  The delay
	you specify here is used between the messages and between the last
	message and the beginning of the shut down to firmware.
	Entering  q  will quit this procedure.' \
'Enter the number of seconds to allow
between the warning messages (default 60): [?, q]' \
		'^[0-9]\{1,\}$' 'Must be all digits.' \
		'^.\{1,4\}$' 'No more than 4 digits.  That is good for over 2.7 hours.'`
fi

trap '' 1 2 3  15
#	-i5 assumes that init state 5 goes to firmware.
setpgrp /etc/shutdown -y -g${grace} -i5  ||  exit 1
#	A trick to keep the shell from announcing the death of a process and
#	yet keep the command from returning.
sleep 1200&
trap 'kill -9 0 2>/dev/null' 15
wait
