:
#  ------------------------------------------------------------------------
#  Title        : BITs-service shell
#  ------------------------------------------------------------------------
#                  This is an UNPUBLISHED work COPYRIGHT by
#                 "ArtCom, Atelier fuer Computergrafik GmbH"
#          Schwachhauser Heerstr. 78, D-2800 Bremen 1, West-Germany
#       It may be used, copied, or distributed only as permitted in a
#                              written license.
#  ------------------------------------------------------------------------
#  Created      :            19-Mar-89 / 10:00 / (pf)
#  Version      :       Sun, 18-Dec-94 / 07:50 / (rb,pf,root,mk+)
#  Portability  : XENIX Bourne shell
#  State        : under development
#  Purpose      : belongs to the XENIX port of BITS
#I Usage        : none, normally Login-shell for user 'service'
#I Remarks      : user 'service' must have root-rights !
#  ------------------------------------------------------------------------
#
# einige nuetzliche Bourne Shell Prozeduren
#
# PROCEDURE Yes : Prompt for yes or no answer - returns non-zero for no
Yes() {
	while	read yn
	do	case $yn in
		       [yYjJ])	return 0 	;;
		       [nN])	return 1	;;
		       *) Error 1
		       ;;
		esac
	done
}
#
# PROCEDURE Error (msgNum : CARDINAL);
Error() {
	PARAM=$1
	(echo "\007\c"; Print serverSH 2;
	 echo " : "; PrintLn serverSH ${PARAM}) >&2
	return 1
}
#
# PROCEDURE Super : BOOLEAN;  (* are we root ? else error ! *)
Super() {
    if [ -w /etc/passwd ]
    then	return 0
    else	
#> Sie muessen Superuser ('root') -Zugriffsrechte haben.
		Error 3
#> Der Benutzer 'service' sollte die userid-Nummer '0' haben !
#> Bitte pruefen Sie, ob Sie sich als service eingeloggt haben und was
#> in der /etc/passwd steht.
		MultiPrint serverSH 4 5 6
	    return 1
    fi
}
#
Interuptus() {
    PrintLn serverSH 7 #> *** Kommando abgebrochen !!! ***
}
#
GetThem() {
	#> Bisherige Einstellung pruefen...
	if [ -r /customer/.cshrc ]
	then cat << EOF | csh > /tmp/doitnow.$$
	     source /bitslib/mustermann/.cshrc
	     echo "GRDEVICE=\$GRDEVICE"
	     echo "BITSENV=\$BITSENV"
	     echo "PATH=\$PATH"
	     echo "ICONS=\$ICONS"
	     echo "LANGUAGE=\$LANGUAGE"
EOF
	     . /tmp/doitnow.$$
	     rm /tmp/doitnow.$$
	fi
	# Assume some defaults for undefined environment variables :
	[ "$GRDEVICE" ]	|| GRDEVICE=WacomII
	[ "$BITSENV" ]	|| BITSENV=/bitslib/env
	PATH=${PATH}:/bitslib/bin
	[ "$ICONS" ]	|| ICONS=/projects/icons:/bitslib/icons
	[ "$me" ]	|| me="xyz `who am i | awk '{print $2}'`"
	TERMLINE=`who am i | awk '{print $2}'`
	[ "$LANGUAGE" ]	|| LANGUAGE=deu
	[ "$BITSERR" ]  || BITSERR=bitserr.srf
	export BITSERR BITSENV GRDEVICE PATH ICONS LANGUAGE me TERMLINE
}
# ===============================================================
# Main part starts here :
# ===============================================================
#
GetThem
if [ "${LANGUAGE}" ]
then :
else LANGUAGE=deu
fi
export LANGUAGE
MSG_CAT=/bitslib/service/SERVImsg.${LANGUAGE}
. /bitslib/bin/.Messages

# ASSERT, that we are 'root' :
Super || exit 1
#
trap Interuptus 1 2 3 15
if [ -r /customer/serviceenv ]
then . /customer/serviceenv
fi
#> Verfuegbare Service-Kommandos :
#> 	0. Server starten.
#> 	1. System herunter fahren.
#> 	   
#> 	Waehlen Sie einen Menuepunkt oder 'e' fuer Ende : \c"

while 	stty sane erase \^h echoe ;
	clear ; PrintLn serverSH 8 #> --- BITs Service Menue ---
        echo; echo ; echo
	PrintLn serverSH 9
	echo ; echo ; echo
	MultiPrint serverSH 10 11 
	echo; echo
	Print serverSH 12
do	:
        # Sicherheitshalber (knnte ja abgestrzt sein) :
	/bitslib/bin/ACDemon < /dev/tty12 > /dev/tty12 2> /dev/tty12 &
        read ans
	case "$ans" in
	0*)	if [ `ps -e | grep Server` ]
		then	#> Es laeuft bereits ein Server !
			PrintLn serverSH 13
		else	GetThem
			/bitslib/bin/clearipc
			/bitslib/bin/VisKill
			rm -f /bitslib/bin/*old 2> /dev/null
			stty intr \^c
			if [ -f /customer/ASYNCSVR ]
			then	nice --6 /bitslib/bin/Server -s
			else	nice --6 /bitslib/bin/Server
			fi
			stty intr \^?
		fi
		;;
	1*)
#> Bitte pruefen Sie, ob Sie nicht irgendwelche Programme im Hintergrund
#> gestartet haben, die durch den SHUTDOWN abgebrochen werden wuerden.
#> 
#> Wollen Sie das System jetzt herunter fahren ? (j/n) 
		MultiPrint serverSH 14 15 16 17
		if Yes
		then /bitslib/service/shutdown.sh
		fi
		;;
	[eEqQ]*)   
		break
		;;
	*)	
#> Bitte waehlen Sie eine der aufgelisteten Ziffern oder 'e' zum Verlassen.
		PrintLn serverSH 18
		;;
	esac
	Print serverSH 19 #> Weiter mit <Enter> : 
	read dummy
done
