#!/bin/sh
NM=`id -u -n`
. /etc/profile.d/setenv825.sh
echo "appmenu.sh $NM cfg $CFG825" >> /tmp/appmenu.log
if test -z "$XDG_RUNTIME_DIR"; then
  export XDG_RUNTIME_DIR=/run/user/`id -u`
  #echo "exported XDG_RUNTIME_DIR [$XDG_RUNTIME_DIR]" >> /tmp/start.log
  if ! test -d "$XDG_RUNTIME_DIR"; then
    #echo "mkdir $XDG_RUNTIME_DIR" >> /tmp/start.log
    chmod 0700 $XDG_RUNTIME_DIR
  fi
fi
. /mnt/nand/bin/setenv.sh
if [ -f /mnt/nand/bin/prestart.sh ]; then
  . /mnt/nand/bin/prestart.sh
fi
/usr/sbin/diag/setup
if [ -f /tmp/dspinfo.sh ]; then
  . /tmp/dspinfo.sh
fi
. /mnt/nand/bin/setenv.sh
if [ "$WTSVR" != "0" ] && [ "$WTSVR" != "" ]; then
	echo "starting wtsvr" >> /tmp/appmenu.log
	/usr/sbin/diag/wtsvr &
fi
while :
do
	/usr/sbin/diag/appmenu
	tmp=$?
	case $tmp in
		4) 
		/usr/sbin/card/ids ;;

		5) 
		/usr/sbin/card/batcher ;;

		6) 
		/usr/sbin/card/chkwgh ;;

		8) 
		/usr/sbin/card/hway ;;

		9) 
		/usr/sbin/card/mscale ;;

		10)
		/usr/sbin/card/vrs/vrs ;;

		11)
		/usr/sbin/card/cbw/cbw ;;


		13) sh /usr/sbin/diag/filemgr.sh ;;

		14) /usr/sbin/diag/imageview /mnt/nand/cfg/slideshow.cfg ;;

		21) sh /mnt/nand/bin/cust01.sh ;;
		22) sh /mnt/nand/bin/cust02.sh ;;
		23) sh /mnt/nand/bin/cust03.sh ;;
		24) sh /mnt/nand/bin/cust04.sh ;;
		25) sh /mnt/nand/bin/cust05.sh ;;
		26) sh /mnt/nand/bin/cust06.sh ;;
		27) sh /mnt/nand/bin/cust07.sh ;;
		28) sh /mnt/nand/bin/cust08.sh ;;
		29) sh /mnt/nand/bin/cust09.sh ;;
		30) sh /mnt/nand/bin/cust10.sh ;;
		31) sh /mnt/nand/bin/cust11.sh ;;
		32) sh /mnt/nand/bin/cust12.sh ;;
		33) sh /mnt/nand/bin/cust13.sh ;;
		34) sh /mnt/nand/bin/cust14.sh ;;
		35) sh /mnt/nand/bin/cust15.sh ;;
		36) sh /mnt/nand/bin/cust16.sh ;;
		37) sh /mnt/nand/bin/cust17.sh ;;
		38) sh /mnt/nand/bin/cust18.sh ;;

		72) /usr/sbin/diag/config ;;
#			if [ $? -eq 27 ] ; then
#				sh /usr/sbin/diag/cln_nand.sh
#				exit
#			fi ;;

		99) 
		PRVWTSVR=$WTSVR
		/usr/sbin/diag/setup
		. /mnt/nand/bin/setenv.sh
		if [ -f /tmp/dspinfo.sh ]; then
			. /tmp/dspinfo.sh
		fi
		if [ "$PRVWTSVR" != "$WTSVR" ]; then
			echo "wtsvr chg $WTSVR" >> /tmp/appmenu.log
			if [ "$WTSVR" != "0" ] && [ "$WTSVR" != "" ]; then
				/usr/sbin/diag/wtsvr &
			else
				echo "kill wtsvr" >> /tmp/appmenu.log
				kill `pidof wtsvr`
				rm /tmp/wtsvrsock
			fi
		fi ;;
	esac
	tmp=$?
	if [[ "$tmp" == "77" ]]; then
		/usr/sbin/diag/config
	fi
done
