Metropoli BBS
VIEWER: eth MODE: TEXT (ASCII)
#
# Globals
#
LKPERM=/etc/perms/inst
PATH=/bin:/usr/bin:/etc:/etc/conf/bin
tmp=/tmp/tcp$$
pkg="TCPRT"                             # permlist package name
set="SCO TCP Runtime"                   # appears in prompts
ROOT=
CONF=${ROOT}/usr/sys/conf
DEVDIR=${ROOT}/dev
ETC=${ROOT}/etc
TCP_CONF=${ROOT}/usr/lib/tcprt
TCP_IF=${TCP_CONF}/if.conf
TCPPERM=${ETC}/perms/tcprt                      # permlist of this product
INET=${ROOT}/usr/sys/inet

# function definitions
#
# usage: safemv file1 file2
# move file1 to file2 without chance of interruption
safemv() {
        trap "" 1 2 3 15
        mv $1 $2
        trap 1 2 3 15
}

# usage: safecopy file1 file2
# copies file1 to file2 without chance of interruption
safecopy() {
        trap "" 1 2 3 15
        cp $1 $2
        trap 1 2 3 15
}

# 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
}

# print a prompt
#
p() {
        set -f
        /bin/echo $*
        set +f
        return $?
}

# Remove temp files and exit with the status passed as argument
cleanup() {
        trap '' 1 2 3 15
        [ "$tmp" ] && rm -f $tmp*
        exit $1
}

# Test to see if link kit is installed
chklinkkit() {
    until       fixperm -i -d LINK $LKPERM
    do  case $? in
        4)      echo "The Link Kit is not installed." >&2               ;;
        5)      echo "The Link Kit is only partially installed." >&2    
                echo "Attempting to install/deinstall the driver anyway." >&2
                return 0
                ;;
        *)      echo "Error testing for Link Kit. Exiting."; cleanup 1 ;;
        esac
        # Not fully installed. Do so here
        while   echo "Do you wish to install it now? (y/n) \c"
        do      read ANSWER
                case $ANSWER in
                Y|y)    custom -o -i LINK
                        break
                        ;;
                N|n)    echo "Drivers cannot be installed without the Link Kit."
                        cleanup 1
                        ;;
                *)      echo "Please answer 'y' or 'n'. \c"
                        ;;
                esac
        done
    done
}

chktcp() {
        PWD=`pwd` ; cd /
        fixperm -i -d ${pkg} ${TCPPERM} ; res=$?
        if [ $res -lt 5 ]
        then
                idcheck -p tcp ; res=$?
                if [ $res -lt 16 ] 
                then
                        echo "Drivers cannot be installed without the TCPRT package."
                        cleanup 1
                fi
        else
                echo "Drivers cannot be installed without the TCPRT package."
                cleanup 1
        fi
        cd $PWD
}

# Re-link new kernel
relink() {
    cd /etc/conf/cf.d
    if [ -z "$_NOPROMPT" ] ; then
        echo "\nRe-linking the kernel ... \c" >&2
    fi
    ./link_unix 2>&1 | tee -a kmakelog 2>&1 || {
            echo "\nError:  Kernel link failed.
Check /etc/conf/cf.d/kmakelog for details." >&2
            cleanup 1
    }
    rm -f kmakelog
    return 0
}

ethprompt() {
/bin/cat - <<   EOF



                       ETHERNET CARD SETUP

For each NIC-2000 or NIC-1000 Ethernet card there are two parameters which
you will need to supply, the Interrupt Vector Number and Base I/O Address.
They must match the board configuration.  Interrupt must be unlatched.
Be sure the interrupt vector you select does not conflict with other device
interrupt vector.

If you wish to go back and reconfigure your board or read the documentation
answer "no" to the next question.

EOF
}

#
# Edit the sdevice file to remove the driver
edrmveth() {
                ed -s $1 << TOAST > /dev/null
/^eth0/
d
a
eth0    N       32      5       1       0       0       0       0       0
.
w
q
TOAST
}


# addhex(a,b) : add two hexadecimal numbers using awk.
# a and b are ascii strings of digits and the letters a-f
# no known side-effects, but illegal characters act as 0 place holders.

addhex() {
echo "$1 $2" | nawk ' {   
        printf("%x", atoh($1) + atoh($2));
    }
    function atoh(number) {
        i = 0
        j = length(number)
        result = 0
        while ( i < j ) {
            result = result + (hexval(substr(number,j - i,1)) * (16 ^ i))
            i = i + 1
        }
        return result
    }
    function hexval(letter) {
        if (letter == "a") return 10 + 0
        if (letter == "b") return 11 + 0
        if (letter == "c") return 12 + 0
        if (letter == "d") return 13 + 0
        if (letter == "e") return 14 + 0
        if (letter == "f") return 15 + 0
        return (letter + 0)
    }'
}

# main()

cd /
tput clear

# check to see if the drivers can be installed
#

chklinkkit

#
# check to see if TCP/IP is installed
#

chktcp

#
# Add drivers via configure
#

while   echo "Do you wish to install or delete the eth driver (i/d/q) ? \c"
do      read ANSWER
        case $ANSWER in
        I|i)    
                break
                ;;
        D|d)    
                cd /etc/conf/pack.d
                for i in eth[1-3] ; do
                        idinstall -d -e $i
                done
                cd /etc/conf/sdevice.d
                edrmveth eth0
                cd /
                grep -v eth /etc/tcp > /tmp/tcp && cp /tmp/tcp /etc/tcp
                grep -v eth /etc/strcf > /tmp/strcf && cp /tmp/strcf /etc/strcf
                rm -f /tmp/tcp /tmp/strcf

                # 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 "\nYour changes will not take effect until the kernel is relinked." >&2
                        cleanup 0
                    fi
                else
                    relink
                fi

                cleanup 0
                ;;
        Q|q)
                cleanup 0
                ;;
        *)      echo "Please answer 'i', 'd' or 'q'."
                ;;
        esac
done
#
# Deal with the "eth" driver
#
ethprompt

getyn "Do you want to continue?"
if [ $? = "1" ]
then
        p "You can rerun mkdev at a later time"
        exit 0
fi

count=0
TRANS=""
BASEADDRS=""
BASELEVELS=""
DEFAULTVECT=5
DEFAULTIOADDR=300
while   expr $count \< 1 >/dev/null
do


        while   p "Board${count}: Interrupt vector number [ default: ${DEFAULTVECT} ]: \c"
        do      read vect
                case "$vect" in
                [1][5])
                        DEFAULTVECT=5;
                        break; 
                        ;;
                [1][2])
                        DEFAULTVECT=5;
                        break; 
                        ;;
                [1][0-1])
                        DEFAULTVECT=5;
                        break; 
                        ;;
                [9])
                        DEFAULTVECT=5;
                        break; 
                        ;;
                [5])
                        DEFAULTVECT=9;
                        break; 
                        ;;
                [4])
                        DEFAULTVECT=5;
                        break; 
                        ;;
                [3])
                        DEFAULTVECT=5;
                        break; 
                        ;;
                "")
                        vect=$DEFAULTVECT;
                        DEFAULTVECT=5;
                        break;
                        ;;
                *)
                        p "Vector number must be 3,4,5,9,10,11,12 or 15"
                        ;;
                esac
        done


        while   p "Board${count}: IO base address (in hexadecimal) [ default: ${DEFAULTIOADDR} ]: \c"
        do      read ioaddr
                case "$ioaddr" in
                "")
                        ioaddr=$DEFAULTIOADDR
                        DEFAULTIOADDR=300
                        break;
                        ;;

                [3][0][0])        
                        break;
                        ;;

                [3][2][0])        
                        break;
                        ;;

                [3][4][0])        
                        break;
                        ;;

                [3][6][0])        
                        break;
                        ;;

                *) p "Address must be 3 hexadecimal digits number: 300, 320, 340, 360"
                        ;;
                esac
        done


        BASEADDRS="${BASEADDRS} ${ioaddr}"
        BASELEVELS="${BASELEVELS} ${vect}"
        count=`expr $count + 1`

#        if getyn "\nDo you have another NIC-2000 or NIC-1000 board?"
#        then
#                :
#        else
#                break
#        fi
done

echo ""

cd /tmp

cnt=0
set `echo $BASELEVELS ` 
for addr in $BASEADDRS
do
        endaddr=`addhex $addr 1f`
        mkdir eth$cnt ; cd eth$cnt
        # Create System Node, copy Space.c and Driver.o (for eth0) 
        echo "eth$cnt    Y      32       5       1       $1       $addr     $endaddr     0       0" > ./System
        echo "clone     eth$cnt         c       eth$cnt" > ./Node

	cp /ethtemp/Space.c  /tmp/eth0/Space.c
	cp /ethtemp/Driver.o  /tmp/eth0/Driver.o

        # Driver.o and Master (for eth1 and above)
        if [ $cnt -gt 0 ] ; then
                echo "eth$cnt   Ioc     iScH    eth$cnt        0       0       1       32       -1" > ./Master

                cp /usr/lib/tcprt/ID/dummy/Driver.o ./Driver.o
                idcheck -p eth$cnt ; res=$?
                if [ $res -lt 16 ] ; then
                        if [ ! -d /etc/conf/pack.d/eth$cnt ] ; then
                                mkdir /etc/conf/pack.d/eth$cnt
                        fi
                        idinstall -a -m -s -n -o -e eth$cnt
                else
                        idinstall -u -m -s -n -o -e eth$cnt
                fi
        else
                echo "eth0    Ioc   iScH    eth0    0       0       1       32       -1" > ./Master

                idcheck -p eth0 ; res=$?
                if [ $res -lt 16 ] ; then
                        if [ ! -d /etc/conf/pack.d/eth0 ] ; then
                                mkdir /etc/conf/pack.d/eth0
                        fi
                        idinstall -a -m -s -n -o -p -e eth0
                else
                        idinstall -u -m -s -n -o -p -e eth0

                fi

        fi

                vi /etc/conf/cf.d/mdevice << TOAST > /dev/null
/eth$cnt/
5w"cyw
:e! /etc/conf/pack.d/eth0/space.c 
/ethermajor$cnt/
wdw"cP
:wq
TOAST
   
        cd .. ; rm -rf eth$cnt
        shift
        cnt=`expr $cnt + 1` 
done
                                             
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

# install if requested
#
echo ""
echo "To complete installation run mkdev tcpeth" >&2
echo "and reboot the system via init 6\n" >&2

[ RETURN TO DIRECTORY ]