#	Auto Dialer shell script for minix
#	Written by bob best (bob@dhw68k.cts.com)
#
ZDIR=/usr/lib/zterm
TTY=$1

cat	>/tmp/dial.menu <<'FOO'
		MINIX TERMINAL DIALER
		D  Dial once only
		A  Auto-redial till connect
		Q  Quit to Terminal

FOO

# this is a hack, but I couldn't fix the shell
cat	>/tmp/sed.in <<'FOO'
s/^[A-Z].. \([A-Z].*\):.*/\1/
FOO

while :
do
	clr
	cat /tmp/dial.menu
	echo -n "		Enter your choice: "
	read choice
	case $choice in
	a|A)    clr
			cat $HOME/dial.dir
			echo -n "Enter the code name of the system(s) you wish to dial: "
			read choice
			${ZDIR}/bgdial $TTY $choice &
			sleep 2
			clr
			echo "Dialing in progress - exiting terminal & returning to shell"
			exit 1
			;;
	d|D)    clr
			cat $HOME/dial.dir
			echo -n "Enter the code name of the system you wish to dial: "
			read choice
			set `grep "^${choice}	" ${HOME}/dial.dir`
			echo "dialing $choice $2 $3"
			${ZDIR}/dial $TTY $2 $3
			case $? in
				0) ${ZDIR}/bell 1
				   echo "CONNECTION ESTABLISHED TO $choice $2"
				   cp $HOME/dial.dir $HOME/dial.dirbak
				   sed  "s/^\\($choice	.*	.*	\\)\\(.*\\)\\(	.*\\)/\\1`date|sed -f /tmp/sed.in`\\3/" $HOME/dial.dirbak >$HOME/dial.dir
				   rm /tmp/dial.menu
				   rm /tmp/sed.in
				   exit 0
				   ;;
				*) echo "NO CONNECTION"
				   sleep 2
				   ;;
			esac
			;;
	q|Q)	rm /tmp/dial.menu
			rm /tmp/sed.in
			exit 0
			;;
	*)      echo "Invalid character"
			;;
	esac
done
