#! /bin/sh

# dialog(T1)

TTPROTO=DSS1
TDDIN=1
TDDI1=0
TIOADDR=150
TIRQ=5

STATE=0
BT="Welcome at the installation of the AVM ISDN-Controller T1"
BSTATE=

while [ $STATE -ne 13 ]; do

	ok=0
	case $STATE in
	0)
	        dialog	--backtitle "$BT ($STATE)" --clear \
        	        --radiolist "D-channel protocol" 11 60 2 \
				DSS1 "Euro ISDN" on \
				1TR6 "German ISDN" off 2> res
		if [ $? -eq 0 ]; then
			TTPROTO=`cat res`
			STATE=1
		else
			STATE=13
		fi
		;;
	1)
		if [ "$CARD" == "t1isa" -o "$CARD" == "t1bisa" ]; then
			dialog	--backtitle "$BT ($STATE)" --clear \
				--radiolist "I/O address" 11 30 4 \
					150 "" on 250 "" off 300 "" off \
					340 "" off 2> res
			if [ $? -eq 0 ]; then
				TIOADDR=`cat res`
				STATE=2
			else
				STATE=0
			fi
		else 	
			STATE=4
		fi
		;;
	2)	
		dialog	--backtitle "$BT ($STATE)" --clear \
			--radiolist "IRQ number" 14 30 7 \
				3 "" off 5 "" on 7 "" off 10 "" off \
				11 "" off 12 "" off 15 "" off 2> res
		if [ $? -eq 0 ]; then		
			TIRQ=`cat res`
			STATE=3
		else
			STATE=1
		fi
		;;
	3)
		dialog  --backtitle "$BT ($STATE)" --clear \
			--radiolist "Controller number" 11 30 4 \
				0 "" on 1 "" off 2 "" off 3 "" off 2> res
		if [ $? -eq 0 ]; then
			CARDNO=`cat res`
			STATE=4
		else
			STATE=2
		fi
		;;
	4)
                STRING="Your settings:\n\nD-channel protocol: $TTPROTO"
                case $TTPROTO in
                DSS1)
                        if [ $TDDI1 == 0 ]; then
                                STRING="$STRING (Point-to-multipoint)"
                        else
                                STRING="$STRING (Point-to-point)"
                        fi
                        LINE=1
                        ;;
                1TR6)
                        STRING="$STRING"
                        LINE=1
                        ;;
                esac
                if [ "$CARD" == "t1isa" -o "$CARD" == "t1bisa" ]; then
                        STRING="$STRING\nIRQ: $TIRQ, IO: $TIOADDR, Controller: $CARDNO"
                        LINE=`expr $LINE + 1`
                fi
                LINE=`expr $LINE + 14`
		dialog	--backtitle "$BT ($STATE)" --clear \
			--menu "\n$STRING\n" $LINE 60 3 \
				OK "All settings correct?" \
				Error "Correct settings" \
				Quit "Quit installation" 2> res
		if [ $? -ne 0 ]; then
			STATE=13
		else
			DUMMY=`cat res`
			case $DUMMY in
			OK)	
				ok=1
				STATE=13
				;;
			Error)	
				STATE=0
				;;
			Quit)
				STATE=13
				;;
			esac
		fi
		;;
	esac
done

clear
/bin/rm -f res

case $TTPROTO in
DSS1)	TPROTO=dss1
	TFILE=dss1
	;;
1TR6)	TPROTO=1tr6
	TFILE=1tr6
	;;
esac

if [ $ok -eq 1 ]; then
	echo -e "Last steps...\n"
else
	echo -e "\aInstallation aborted.\n"
	exit 0
fi

