
#ident  "@(#)ether:ID/Install   1.8.1.7"
#       Device Driver Install Package
#
TMP=/tmp/ether.err
PATH=/bin:/usr/bin:/etc:/etc/conf/bin
ERROR1=" Errors have been written to the file $TMP."
rm -f $TMP > /dev/null 2>&1
NAME="ACCTON Ethernet Stream Driver"
PKG="accdrv"
INT1=3
LADD1=280
HADD1=29f
LMEM1=D0000
HMEM1=D1fff
#
# Edit the sdevice file to remove the driver
# Remove temp files and exit with the status passed as argument
# Prompt for yes or no answer with message passed as argument -
# returns non-zero for no

getyn() {
        while   echo "\n$* (y/n/q) \c">&2
        do      read yn rest
                case $yn in
                        [yY]) return 0                          ;;
                        [nN]|[qQ]) return 1                     ;;
                *)      echo "Please answer y,n or q" >&2       ;;
                esac
        done
}


cleanup() {
        trap '' 1 2 3 15
        [ "$tmp" ] && rm -f $tmp*
        exit $1
}

rmsystem() {
                ed  -s /etc/conf/cf.d/sdevice << TOAST
/^$1/
d
w
q
TOAST
}

chktcp() {
        /etc/conf/bin/idcheck -p tcp > /dev/null 2>&1
        RETTP=$?
        echo ".\c"
        if [ $RETTP != 31 ]
        then
                ERROR="cannot be installed. \
        You must install the TCP/IP package before you can install this package."
                message "The ${PKG} ${ERROR}.  \
        Use installpkg to install the TCP/IP driver before attempting \
        to install the ${NAME} again."
                exit 1
        fi
}

# Re-link new kernel
relink() {
    if [ -z "$_NOPROMPT" ] ; then
        echo "\nRe-linking the kernel ... \c" >&2
    fi

    [ "$_RELINK" ] && {
        > /tmp/_relink
        return 0
    }

    [ -f unix ] && mv unix unix.old

    /etc/conf/bin/idbuild  2>&1

    if [ $? != 0 ]
    then
        echo "        The installation cannot be completed due to"
        echo "        an  error in  the  kernel  reconfiguration."
        echo "        Please try the installation again."
        echo ""
        return 1
    fi

    grep 'SCO' /etc/motd > /dev/nul
    stat=$?
    if [ "$stat" -eq "1" ]; then
       /etc/conf/bin/idmkenv
       cp /etc/conf/cf.d/unix /
    fi

    echo ""
    echo "The  new  kernel  has  been  installed  successfully," >&2
    echo "the following step is to modify TCP/IP configuration." >&2
    sleep 2
    chmod u+x /accdrv/ethtcp
    /accdrv/ethtcp
    echo "Now you can reboot the system via 'init 6' command." >&2
    return 0
}

getmaj() {
awk  '$1 ~ /ether/ {print $6}' /etc/conf/cf.d/mdevice > tmp
ed  /etc/conf/pack.d/ether0/space.c << TOAST > /dev/null
25r tmp
1
/$1
s/$1//
-
j
w
q
TOAST
rm tmp
}

cd /accdrv
chktcp
echo "\n\n\n\n\c"
echo "
        SCO System V/386 Release 3.2 2 Ethernet Device Driver
        Iteractive System i386 3.2 2 Ethernet Device Driver Installation
        Copyright (C) 1990-1992 ACCTON Corp.
        All Right Reserved
"

while   echo "Do you want to install or delete the ACCTON ethernet stream driver (i/d/q)? \c"
do      read ANSWER
        case $ANSWER in
        I|i)
                break
                ;;
        D|d)
                cd /etc/conf/pack.d
                for i in ether[0-3] ; do
                        idinstall -d -e $i
                done
                cd /etc/conf/cf.d
                rmsystem ether0
                cd /
                if [ -f /etc/tcp -o -f /etc/strcf ]; then
                   grep -v ether /etc/tcp > /tmp/tcp && cp /tmp/tcp /etc/tcp
                   grep -v ether /etc/strcf > /tmp/strcf && cp /tmp/strcf /etc/strcf
                   rm -f /tmp/tcp /tmp/strcf
                fi
                if [ -f /etc/netd.cf ]; then
                   grep -v ether /etc/netd.cf > /tmp/netd.cf && cp /tmp/netd.cf /etc/netd.cf
                   rm -f /tmp/netd.cf
                fi

                # Relink the kernel with the new driver information
                if [ -z "$_NOPROMPT" ] ; then
                    if getyn "\nDo you wish to relink the kernel now?"
                    then
                      relink
                    else
                      echo "\nChanges will not take effect until the kernel is relinked." >&2
                    fi
                else
                    relink
                fi
                cleanup 0
                ;;
        Q|q)
                cleanup 0
                ;;
        *)      echo "Please answer 'i', 'd' or 'q'."
                ;;
        esac
done

RELEASE=`uname -v`

count=0
while   expr $count \< 3 >/dev/null
do
RETVCHK=0
clear="\033[2J"
home="\033[1;1H"

        while true
        do
                echo $clear
                echo $home
                VNUM=""
                echo ""
                echo ""
                echo ""
                echo ""
                echo "                  \033[4mNetwork Driver Installation\033[0m"
                echo ""
                echo ""
                echo "       Which network driver do you want to install?"
                echo ""
                echo "                1. ACCTON EtherPair/EtherCoax-NE"
                echo ""
                echo "                2. ACCTON EtherCombo-32"
                echo ""
                echo "            Please select any number: \c"
                read    VNUM
                echo "\033[18;1H\033[0J"

                case ${VNUM} in
                        1) echo "";
                           echo "             \033[7mACCTON EtherPair/EtherCoax-NE was selected.\033[0m";
			   LMEM1=0;
			   HMEM1=0;
                           cp /accdrv/newd.o /accdrv/Driver.o;
                           cp /accdrv/space.c /accdrv/Space.c;
                           ln ioaddrne ioaddr;
                           break ;;
                        2) echo "";
                           echo "             \033[7mACCTON EtherCombo-32 was selected.\033[0m";
			   LADD1=0;
			   HADD1=0;
		           LMEM1=0;
			   HMEM1=0;			
                           cp /accdrv/en1200.o /accdrv/Driver.o;
                           cp /accdrv/space.c /accdrv/Space.c;
                           break ;;
                        *) ;;
                esac
        done

        echo "clone     ether$count               c       ether$count" > ./Node
        # sysconf prompts for parameters and creates
        # the System file
        /etc/conf/bin/idcheck -p ether$count > /dev/null 2>&1
        RETTP=$?

        echo ".\c"
        while [ $RETTP != 31 ]
        do
                echo ".\c"
                ################
                # find out if interrupts 2, 3, 4, 5 ,7 and 9 are available and then
                # prompt the user to select one
                VECTMSG=""
                for VECT in 2 3 4 5 7 10 11 15
                do
                        /etc/conf/bin/idcheck -v $VECT >/dev/null 2>&1
                        RETVCHK=$?
                        if [ "$RETVCHK" = 0 ]
                        then
                                VECTMSG="${VECTMSG}\n\tIRQ ${VECT}"
                                VECTLIST="${VECTLIST} ${VECT}"
                        fi
                done

                if [ "$VECTLIST" != "" ]
                then
                        while true
                        do
                                VANSWER=""
                                message -d "Available interrupt(s) for the first ${NAME}: \
        ${VECTMSG}\n\nType the interrupt number and strike the ENTER key or\n\
        type Q to cancel installation."
                                read VANSWER
                                if [ "x$VANSWER" != xQ -a "x$VANSWER" != xq ]
                                then
                                        for i in $VECTLIST
                                        do
                                                if [ "x$VANSWER" = "x$i" ]
                                                then
                                                        INT1="$VANSWER"
                                                        break 2
                                                fi
                                        done
                                else
                                        exit 1
                                fi
                                message -d "Invalid Answer"
                        done

                fi
                #####################
                if [ "$VNUM" = 4 ]
                then
                    LADD1=3000
                    HADD1=301f
                    break
                fi

                echo 'I/O address can be set to the following values:'
                csplit -fGarbage -s ioaddr 2
                cat Garbage01
                rm -f Garbage*
                set `echo \`cat ioaddr\``
                while [ $# != 0 ]
                do
                        LADD1=$1
                        HADD1=$2
                        message -d "Default i/o address ranges are $LADD1 to $HADD1.\
                 Type i/o address or strike ENTER to accept the default."
                        read VANSWER
                        if [ "x$VANSWER" != "x" ]
                        then
                                while true
                                do
                                        ADDCHK=`grep $VANSWER ioaddr`
                                        if [ "x$ADDCHK" != "x" ]
                                        then
                                                set `echo $ADDCHK`
                                                LADD1=$1
                                                HADD1=$2
                                                break  2
                                        else
                                                message -d "I/O address $VANSWER\
        is invalid. Please try another address or strike ENTER for a list of valid \
        addresses."
                                                read VANSWER
                                                if [ "x$VANSWER" = "x" ]
                                                then
                                                        cat ioaddr
                                                        message -d "Please type \
        i/o address."
                                                        read VANSWER
                                                fi
                                        fi
                                done
                        else
                                break
                        fi
                done

         if [ "$VNUM" = 2 ]
         then
                echo '.\c'
                echo 'Memory address can be set to the following values:'
                csplit -fGarbage -s address 2
                cat Garbage01
                rm -f Garbage*
                set `echo \`cat address\``
                while [ $# != 0 ]
                do
                        LMEM1=$1
                        HMEM1=$2
                        message -d "Default memory address ranges are $LMEM1 to $HMEM1,\
        Type the memory address number or strike ENTER to accept the default."
                        read VANSWER
                        if [ "x$VANSWER" != "x" ]
                        then
                                while true
                                do
                                        ADDCHK=`grep $VANSWER address`
                                        if [ "x$ADDCHK" != "x" ]
                                        then
                                                set `echo $ADDCHK`
                                                LMEM1=$1
                                                HMEM1=$2
                                                break  2
                                        else
                                                message -d "Memory address $VANSWER\
         is invalid. Please try another address or strike ENTER for a list of valid \
        addresses."
                                                read VANSWER
                                                if [ "x$VANSWER" = "x" ]
                                                then
                                                        cat address
                                                        message -d "Please type \
        memory address number."
                                                        read VANSWER
                                                fi
                                        fi
                                done
                        else
                                break
                        fi
                done
            break
         else
            LMEM1=00000
            HMEM1=00000
            break
         fi
        done

        if [ "$VNUM" = 2 ]
        then
            echo "You  are  installing  the  ${NAME}"
            echo "using hardware interrupt number ${INT1}, and i/o addresses ${LADD1}"
            echo "through ${HADD1}.  And  memory addresses ${LMEM1} through ${HMEM1}."
            echo "Be sure  that  these  values are  not in use  by another"
            echo "add-on board."

        elif [ "$VNUM" = 4 ]
        then
            echo "You are installing the ${NAME}"
            echo "using hardware interrupt number ${INT1}"

        else
            echo "You   are  installing  the   ${NAME}"
            echo "using hardware interrupt number  ${INT1}, and i/o addresses ${LADD1}"
            echo "through ${HADD1}.  Be sure  that these  values  are  not in use"
            echo "by another add-on board."
        fi
        message "The ${NAME} Configuration Ok !!"

        #################
        # Make sure to switch interrupt 2 to 9 so that idbuild will not fail.
        if [ "$INT1" = 2 ]
        then
                INT1=9
        fi

        echo ".\c"
        cp /accdrv/accsys /accdrv/System
        sed -e "s/LADD1/${LADD1}/" -e "s/HADD1/${HADD1}/" -e "s/INT1/${INT1}/" < /accdrv/System > Sys.$$
        cat Sys.$$ > /accdrv/System
        rm -f Sys.$$

        echo ".\c"
        sed -e "s/LMEM1/${LMEM1}/" -e "s/HMEM1/${HMEM1}/" < /accdrv/System > Sys.$$
        cat Sys.$$ > /accdrv/System
        rm -f Sys.$$

        echo ".\c"

        sed -e "s/ether/ether$count/" < /accdrv/System > Sys.$$
        cat Sys.$$ > /accdrv/System
        rm -f Sys.$$
        # Driver.o and Master (for ether1 and above)
         if [ $count -gt 0 ] ; then
                echo "clone     ether$count     c       ether$count" > ./Node
                echo "ether$count -       iScH    ether$count   0       0       1       256     -1" > ./Master
                idcheck -p ether$count ; res=$?
                if [ $res -lt 16 ] ; then
                        if [ ! -d /etc/conf/pack.d/ether$count ] ; then
                                mkdir /etc/conf/pack.d/ether$count
                        fi
                        idinstall -a -m -s -n -o -p -e ether$count
                else
                        idinstall -u -m -s -n -o -p -e ether$count
                fi
        else
                echo "ether0      I       iScH    ether     0       0       1       256     -1" > ./Master
                if [ ! -d /etc/conf/pack.d/ether$count ] ; then
                     mkdir /etc/conf/pack.d/ether$count
                fi
                idinstall -a -m -s -n -o -p -e ether$count
        fi
        getmaj ETHER_CMAJOR_$count
        count=`expr $count + 1`
        break
done

echo ""

cd /

# Relink the kernel with the new driver information
if [ -z "$_NOPROMPT" ] ; then
    if getyn "\nDo you wish to relink the kernel now?"
    then
        relink
    else
        echo "\n$set will not work until the kernel is relinked." >&2
        cleanup 0
    fi
else
    relink
fi

