#! /bin/sh
#
#   kon2start.sh -- カウントダウンしつつ、どのモードに移行するか選択
#
#	0.0: May   5, 2009 by Dai ISHIJIMA (as countdown.sh)
#	0.1: Apr. 11, 2011 for wpout11
#	0.2: Oct. 11, 2013 (use /dev/ttyv0, wpout13)
#

export LOGFIL="${LOGFIL:-/tmp/wpoutlog.txt}"

echo ''
echo ''
echo "# select console mode"
echo "    0: Start wipe-out on KON2 (Kanji on console) [default]"
echo "    1: Start wipe-out on KON2 fixed for some Laptops"
echo "    2: Start interactive shell, stay in Native console (non Japanese)"
prompt="# Just press ENTER to select default mode"

count=9

while [ $count -gt 0 ]; do
	echo -e "\r$prompt[$count] \c"
	if read -t 1 keyin 1>/dev/null 2>&1 ; then
		count=0
	fi
	count=$(( $count - 1 ))
done

case x"$count" in
	x0)
		echo -e "\r$prompt[0] 0"
		keyin=0		
		;;
esac


echo -n "kon2start with keyin = $keyin, " >> $LOGFIL
date >> $LOGFIL

case x"$keyin" in
	x0)
		export KON2MODE=default
		/usr/local/bin/kon -e /wipeout/startup.sh < /dev/ttyv0
		;;
	x2)
		/bin/sh -i
		;;
	*)
		export KON2MODE=FIXed
		/usr/local/bin/kon2fixed FIX -e /wipeout/startup.sh < /dev/ttyv0
		;;

esac

exit 0

# EOF

