#
#       Copyright (C) Triones Technologies, INC. 1994-1995. All Right Reserved. 
#
#

PATH=/bin:/usr/bin:/etc
BUILD=/etc/conf/bin
CONFDIR=/etc/conf/cf.d
SDEVICE=/etc/conf/sdevice.d
PACKDIR=/etc/conf/pack.d/eide

: ${OK=0} ${FAIL=1} ${TRUE=0} ${FALSE=1}

cleanup()
{
	exit $1
}

safecopy() 
{
        trap "" 1 2 3 15
        cp $1 $2
        trap 1 2 3 15
}

setparam()
{
rep=1
while [ $rep = "1" ]
do
tmp=/${1}
suptLBA="Yes"
suptSMS="Yes"
PIOM="Auto"
DMAM="Auto"
clear
echo "\n


          Control Parameter Configuration for ${2}
          ----------------------------------------------------------
" >&2
while echo "\n\r 1) Enable/Disable LBA Support

    This configuration enables/disable Logical Block Support for IDE drives
    which support this option. The configuration report when booting will
    indicate whether this feature has been enabled on a particular drive.  By
    default, LBA Support is enabled.

  Do you want to support the LBA characteristic? (y/n): \c" >&2
do read aa rest
case $aa in
	y|Y)	break							;;
	n|N)	tmp="${tmp} !LBA"
			suptLBA=" No"
		break							;;
	*)	echo "\nWARINING:\07You must select yes or no" >&2
esac
done

while echo "\n\r 2) Enable/Disable Multple Block I/O Support 

    This configuration enables/disable Set Multiple Support. The Multiple
    Block I/O improves performance of most IDE drives. If the drive does not
    support this feature, this switch will be ignored. The configuration
    report when booting will indicate whether this feature has been enabled
    on a particular drive.   By default, Set Multiple Support is enabled.

  Do you want to support the Multi_Sectors Mode? (y/n): \c" >&2
do read aa rest
case $aa in
	y|Y)	break							;;
	n|N)	tmp="${tmp} !MS"
			suptSMS=" No"
		break							;;
	*)	echo "\nWARINING:\07You must select yes or no" >&2
esac
done

while echo "\n\r3) Override Vendor-Specified PIO Timing Mode

    By default, the driver automatically sets the highest PIO timing mode
    supported by each drive.  This configuration allows you to override the
    vendor-specified PIO timing mode with any timing mode between 0 and 5.
    This is particularly useful for support of drives which have firmware
    bugs, causing them to return incorrect PIO timing modes in the IDENTIFY
    DRIVE command.  For example, many current drives which claim to be Mode 2
    are really Mode 0 or Mode 1.

  Please specify the PIO Timing Mode(0-4 or q): \c" >&2
do read aa rest
case $aa in
	0|1|2|3|4)	tmp="${tmp} PIO=${aa}"
			PIOM="  ${aa} "
			break		;;
	q|Q)	break			;;
	*)	echo "\nWARINING:\07You must select 0-4 or no" >&2
esac
done

while echo "\n\r4) Override Vendor-Specified DMA Timing Mode

    By default, the driver automatically sets the highest DMA timing mode
    supported by each drive.  This configuration allows you to override the
    vendor-specified DMA timing mode with any timing mode between 0 and 2.
    This is particularly useful for support of drives which have firmware
    bugs, causing them to return incorrect DMA timing modes in the IDENTIFY
    DRIVE command.

  Please specify the DMA Timing Mode:

      1.  Single Word DMA mode 2
      2.  Multi-Word DMA mode 1
      3.  Multi-Word DMA mode 2
      4.  Not use DMA operation
   
  Input your select(1-4 or q): \c" >&2
do read aa rest
case $aa in
	1) tmp="$tmp DMA=SW2"
	   DMAM=" SW2"
	   break	;; 
	2) tmp="$tmp DMA=MW1"
	   DMAM=" MW1"
	   break	;; 
	3) tmp="$tmp DMA=MW2"
	   DMAM=" MW2"
	   break	;; 
	4) tmp="$tmp DMA=NO"
	   DMAM=" NO "
	   break	;;
	q|Q)	break	;;
	*)	echo "\nWARINING:\07You must select 1-4 or q" >&2
esac
done

while echo "
               Your configuration for ${2} 
               ============================================

            ---------------------------------------------------
            | Support | Support |  PIO Timing  |  DMA Timing  | 
            |   LBA   |   SMS   |     Mode     |     Mode     |
            |---------|---------|--------------|--------------|
            |  ${suptLBA}    |   ${suptSMS}   |     ${PIOM}     |     ${DMAM}     |   
            ---------------------------------------------------

  Are You sure to receive the configuration? (y/n/q): \c" >&2
do read aa reset
case $aa in
	y|Y)	rep=0
		break					;;
	n|N)	break					;;
	q|Q)	tmp=
		rep=0
		break					;;
	*)	echo "\nWARINING:\07You must select yes, no or quit" >&2
esac
done
done
}

trap 'cleanup $FAIL' 1 2 3 15

clear
echo "
Copyright (C) 1994-1996, Triones Technologies, Inc.

===================== EIDE Bus Master Device Driver V3.22 =====================
"  >&2
echo "\n" >&2
echo "\n" >&2
while echo "
            -------- Display Driver Information --------
 
    This configuration will display the adapter device driver level, disk
    or CD-ROM controller status during the SCO UNIX system initialization. 

  Do you want to report the Devices Informations when booting? (y/n):  \c" >&2
do read aa rest
case $aa in
	y|Y)	SPACE=/V
		break							;;
	n|N)	SPACE=
                break							;;
	*)	echo "\nWARINING:\07You must select yes or no" >&2
esac
done

CFG00=
CFG01=
CFG10=
CFG11=

clear
echo "\n" >&2
echo "\n" >&2
while echo "
            -------- Control Parameter Configuration  ---------

    Although the driver has set the Drive/Device configuration to make the
    driver's performance optimizations. You can override the default setting
    by yourself to make a better performance for the drive.

  Do you want to set the device configuration? (y/n): \c" >&2
do read aa rest
case $aa in
	y|Y|n|N) break						;;
	*)	 echo "\nWARINING:\07You must select yes or no" >&2
esac
done
if [ $aa = "y" -o $aa = "Y" ]
then
repeat=1
while [ $repeat = "1" ]
do
while echo "\n
             Please select the device which you want to configurate
             ------------------------------------------------------ 

         1) Primary port master device
         2) Primary port slave device
         3) Secondary port master device
         4) Secondary port slave device
         5) Exit

    Please select 1-5: \c" >&2
do read aa rest
case $aa in
	1)	setparam "PM" "Primary Master" 
		CFG00=${tmp}
		break					;;
	2)	setparam "PS" "Primary Slave" 
		CFG01=${tmp}
		break					;;
	3)	setparam "SM" "Secondary Master" 
		CFG10=${tmp}
		break					;;
	4)	setparam "SS" "Secondary Slave" 
		CFG11=${tmp}
		break					;;
	5)	repeat=0
		break					;;
	*)	echo "\nWARINING:\07You must select 1-5" >&2
esac
done
done
fi
echo "char *CommandLine =\"${SPACE} ${CFG00} ${CFG01} ${CFG10} ${CFG11}\";" >tmp/space.c

mkdir ${PACKDIR} >null 2>&1
safecopy tmp/Driver.o ${PACKDIR}/Driver.o
safecopy tmp/space.c  ${PACKDIR}/space.c
safecopy tmp/System   ${SDEVICE}/eide

grep -v "eide" ${CONFDIR}/mdevice > tmp/mdevice
cat tmp/Master >> tmp/mdevice
safecopy tmp/mdevice ${CONFDIR}/mdevice

grep "eide" ${CONFDIR}/mscsi > tmp/mscsi
if [ ! -s tmp/mscsi ]
then
cat ${CONFDIR}/mscsi tmp/Mscsi > tmp/mscsi
safecopy tmp/mscsi ${CONFDIR}/mscsi
if [ ! -d save ]
then
mkdir save
safecopy ${SDEVICE}/wd   save/wd
safecopy ${SDEVICE}/Sdsk save/Sdsk
fi
fi

sed -e 's;Y;N;' < ${SDEVICE}/wd > tmp/wd
safecopy tmp/wd ${SDEVICE}/wd
sed -e 's;N;Y;' < ${SDEVICE}/Sdsk > tmp/Sdsk
safecopy tmp/Sdsk ${SDEVICE}/Sdsk

cd ${BUILD}
./idbuild
exit $OK
