Metropoli BBS
VIEWER: init MODE: TEXT (ASCII)
:
#               (C) 1989-1990 The Santa Cruz Operation, Inc.  All Rights
#               Reserved.  The user has unlimited right to use, modify
#               and incorporate this code into other products provided
#               it is used with SCO products and the user includes
#               this notice and the associated copyright notices with
#               any such application.
# This script is for installing an LLI driver using netconfig
#
# The name it is called with will cause different operation.
# e3A0 e3A1 e3A2 e3A3           == 3Com501 boards 0 - 3
# e3B0 .....     e3B3           == 3Com503 boards 0 - 3
# e3C0 .....     e3C3           == 3Com523 boards 0 - 3
# wdn0 .....     wdn3           == Western Digital boards 0 - 3
# nat0 .....     nat3           == National NE2000 boards 0 - 3
# wdt0 .....     wdt3           == Western Digital 8013 boards 0 - 3
# son0 .....     son3           == Sonic boards 0 - 3
# d22e0.....     d22e3          == D-Link DE-220 boards 0 - 3
# exos0 ....     exos3          == Excelan 205T boards 0 - 3
# tok0 tok1                     == Token Ring Adapter 0, 1
# hpi0 hpi1 hpi2 hpi3           == HP ThinLAN/EtherTwist ISA LAN Adapters 0 - 3
# hpe0 hpe1 hpe2 hpe3           == HP EtherTwist EISA Slave LAN Adapters 0 - 3
# i3B0 ....      i3B3           == Interlan ES3210 boards 0 - 3
# i6E0                          == Interlan NI6510 board 0
#
LIB=/usr/lib/lli
CONF=/etc/conf
PATH=/bin:/usr/bin:/etc/:$CONF/bin:$LIB
#
# Set possible return codes for this script
#
OK=0;   FAIL=1; RELINK=2;

BRAM="0"
ERAM="0"

#
# Prompt the user for a hex value, it must be within a given range
# Usage:
#       prompt_range "Message" default min max [step]
#
prompt_range() {
        mesg=$1
        default=$2
        range_min=$3 range_max=$4
        step="1"
        if [ $# -eq 5 ]
        then
                step=$5
        fi

        while :
        do
                echo "${mesg} (${range_min}..${range_max}) [${default}] or 'q' to quit: \c"
                read result
                case $result in
                Q|q)
                        return $FAIL
                        ;;
                "")
                        result=$default
                        ;;
                esac

                hc $result $range_min $range_max $step
                case $? in
                0) return $OK;;
                1) cleanup $FAIL;;
                2) cleanup $FAIL;;
                esac
        done
}

#
# Prompt the user to make a selection a list of values
# Usage:
#       prompt_select "Message" default "value_list"
prompt_select() {
        mesg=$1
        default=$2
        values=$3

        while :
        do
                if [ "$default" = "" ]
                then
                        echo "${mesg} (${values}) or 'q' to quit: \c"
                else
                        echo "${mesg} (${values}) [${default}] or 'q' to quit: \c"
                fi
                read result
                case $result in
                Q|q)
                        return $FAIL
                        ;;
                "")
                        result=$default
                        ;;
                esac

                for i in $values
                do
                        if [ "$i" = "$result" ]
                        then
                                return $OK
                        fi
                done
                echo "Illegal value, must be one of (${values})"
        done
}

#
# prompt the user to answer a yes no question or 'q' to quit
# Usage:
#       prompt_yn "Message" default
prompt_yn() {
        mesg=$1
        default=$2

        while :
        do
                echo "${mesg} (y/n) [${default}] or 'q' to quit: \c"
                read result

                case $result in
                q|Q) return $FAIL;;
                y|Y) result="Y"; return $OK;;
                n|N) result="N"; return $OK;;
                "") result=`echo $default | tr "yn" "YN"`; return $OK;;
                esac

                echo "Illegal value, please type 'y' 'n' or 'q'"
        done
}

#
# Fake up an mdevice and an sdevice for idcheck
#
makedevs() {
        dir=`pwd`
        rm -fr /tmp/dev$$
        mkdir /tmp/dev$$
        cd /etc/conf/cf.d
        cp mdevice /tmp/dev$$
        cd ../sdevice.d
        cat * > /tmp/dev$$/sdevice
        cd $dir
}

cleanup() {
        cd /
        rm -fr /tmp/dev$$
        rm -fr /tmp/$base
        exit $1
}

# Removes the given interrupt vector for the $clash device.
rmvector() {
        clash=$1
        vec=$2

        cd $confdir
        echo "\nRemoving interrupt vector $vec for the $clash device ..."

        [ "$vec" = "2" ] && vec=9
        major=`./configure -j $clash` && {
                # remove device but leave it required
                if [ "$major" != "0" ]
                then
                        ./configure -d -c -m $major -v $vec -Y >> conflog 2>&1 || {
                                cd $currdir
                                cleanup $FAIL
                        }
                else
                        sed -e "s/Y/N/" ../sdevice.d/$clash > /tmp/bog$$
                        mv /tmp/bog$$ ../sdevice.d/$clash
                fi
                # remove required setting if no more left
                if grep "Y" ../sdevice.d/$clash > /dev/null 2>&1
                then
                        true
                elif [ "$major" != "0" ]
                then
                        ./configure -d -c -m $major -v $vec -R -Y >> conflog 2>&1 || {
                                cd $currdir
                                cleanup $FAIL
                        }
                fi
        }
        cd $currdir
        return $OK
}

# On unix, we must check the files in sdevice.d.
# Sets the variable $clash to the driver code name if there is a driver that
# has already been allocated the given vector. Uses awk.
dointclash() {
        driver=$1
        vec=$2

        [ "$vec" = "2" ] && vec=9
        cd $confdir/../sdevice.d
        clash=`cat * | awk '{ if ( $6 == intr && $2 == "Y" ) exit } \
                        END { print $1 }' intr=$vec`

        cd $currdir

        [ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
        # found a clash
        return $OK
}

checkvec() {
        driver=$1
        vector=$2
        clash=

        currdir=`pwd`

        while dointclash $driver $vector
        do
                prompt_select "Interrupt vector $vector is already in use for the $clash device.\n\n\
The alternatives available to you are:\n\n\
\t1. Continue the installation and remove vector $vector for the $clash device.\n\
\t2. Select a different interrupt vector.\n\n\
Select an option" 1 "1 2" || {
                        cleanup $FAIL
                }
                case $result in
                1)      rmvector $clash $vector || {
                                echo "Failed to remove vector $vector"
                                cleanup $FAIL
                        }
                        makedevs
                        return $OK
                        ;;
                2)      return $FAIL
                        ;;
                esac
        done
        return $OK
}

doaddrclash() {
        driver=$1
        addr1=$2
        addr2=$3

        cd $confdir
        clash=`../bin/idcheck -ar -l $addr1 -u $addr2 -i /tmp/dev$$`
        cd $currdir

        [ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
        # found a clash
        return $OK
}

# Removes the $clash device.
rmaddr() {
        clash=$1

        cd $confdir
        echo "\nRemoving the $clash device ..."

        major=`./configure -j $clash` && {
                # remove device but leave it required
                if [ "$major" != "0" ]
                then
                        ./configure -d -c -m $major -Y >> conflog 2>&1 || {
                                cd $currdir
                                cleanup $FAIL
                        }
                else
                        sed -e "s/Y/N/" ../sdevice.d/$clash > /tmp/bog$$
                        mv /tmp/bog$$ ../sdevice.d/$clash
                fi
                # remove required setting if no more left
                if grep "Y" ../sdevice.d/$clash > /dev/null 2>&1
                then
                        true
                elif [ "$major" != "0" ]
                then
                        ./configure -d -c -m $major -R -Y >> conflog 2>&1 || {
                                cd $currdir
                                cleanup $FAIL
                        }
                fi
        }
        cd $currdir
        return $OK
}

checkaddr() {
        driver=$1
        addr1=$2
        addr2=$3
        clash=

        currdir=`pwd`

        while doaddrclash $driver $addr1 $addr2
        do
                if [ "$clash" = "ad" ]
                then
                        echo "\n\nWARNING: Do not remove the $clash device \c"
                        echo "if you are using an Adaptec disk controller"
                fi
                prompt_select "Addresses $addr1-$addr2 are already in use by the $clash device.\n\n\
The alternatives available to you are:\n\n\
\t1. Continue the installation and remove the $clash device.\n\
\t2. Select a different address.\n\n\
Select an option" 1 "1 2" || {
                        cleanup $FAIL
                }
                case $result in
                1)      rmaddr $clash || {
                                echo "Failed to remove $clash device"
                                cleanup $FAIL
                        }
                        makedevs
                        return $OK
                        ;;
                2)      return $FAIL
                        ;;
                esac
        done
        return $OK
}

doramclash() {
        driver=$1
        addr1=$2
        addr2=$3

        cd $confdir
        clash=`../bin/idcheck -cr -l $addr1 -u $addr2 -i /tmp/dev$$`
        cd $currdir

        [ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
        # found a clash
        return $OK
}

checkram() {
        driver=$1
        addr1=$2
        addr2=$3
        clash=

        currdir=`pwd`

        while doramclash $driver $addr1 $addr2
        do
                prompt_yn "
Ram addresses $addr1-$addr2 is already in use for the $clash device.
You must choose a unique address for this device to work.
Do you wish to choose another address now?" y || cleanup $FAIL
                if [ "$result" = "Y" ]
                then
                        return $FAIL
                else
                        cleanup $FAIL
                fi
        done
        return $OK
}

# On unix, we must check the lines in mdevice file.
# Sets the variable $clash to the driver code name if there is a driver that
# has already been allocated the given channel. Uses awk.
dodmaclash() {
        driver=$1
        chan=$2
        clash=

        # -1 is never a clash
        [ "$chan" = "-1" ] && return $FAIL

        cd $confdir
        clash=`awk '{ if ( $9 == dma ) print $1 }' dma=$chan mdevice`

        [ "$clash" = "" ] && {
                cd $currdir
                return $FAIL
        }

        cat ../sdevice.d/$clash | awk '{ if ( $2 == "Y" ) exit 1 }' || return $OK

        if [ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ]
        then
                prompt_yn "
DMA channel ${chan} is already in use by the $clash device.  However, the
$clash device is not currently configured into the kernel.  Do you wish to
remove DMA channel ${chan} from the $clash device?" y || cleanup $FAIL
                if [ "$result" = "Y" ]
                then
                        sed -e "/^$clash        .*[0-9]$/{" \
                                -e 's/[0-9]$/-1/p' \
                                -e '}' mdevice > /tmp/bog$$
                        mv /tmp/bog$$ mdevice
                        cd $currdir
                        return $FAIL
                else
                        cd $currdir
                        return $OK
                fi
        fi

        # Should be release >3.2.2, clash driver not installed if we get here.
        cd $currdir
        return $FAIL
}

#
# Check if there is a clash of DMA channels
#
checkdma() {
        driver=$1
        channel=$2
        clash=

        currdir=`pwd`

        while dodmaclash $driver $channel
        do
                prompt_yn "
DMA channel ${channel} is already in use by the $clash device.
You must choose a unique channel for this device to work.
Do you wish to choose another channel now?" y || cleanup $FAIL
                if [ "$result" = "Y" ]
                then
                        return $FAIL
                else
                        cleanup $FAIL
                fi
        done
        return $OK
}

check_args() {
        name=$1
        bd=$2

        case $name in
        e3A) echo "Configuring 3Com501 board $bd";
                PREFIX="e3c";
                MAX_BD=3;
                ;;
        e3B) echo "Configuring 3Com503 board $bd";
                PREFIX="e503";
                MAX_BD=3;
                ;;
        e3C) echo "Configuring 3Com523 board $bd";
                PREFIX="emc";
                MAX_BD=3;
                ;;
        e3D) echo "Configuring 3Com507 board $bd";
                PREFIX="e3d";
                MAX_BD=3;
                ;;
        wdn) echo "Configuring Western Digital 8003/8013 board $bd";
                PREFIX="wdn";
                MAX_BD=3;
                ;;
        wdt) echo "Configuring WD8013 board $bd";
                PREFIX="wdt";
                MAX_BD=3;
                ;;
        nat) echo "Configuring National Semiconductor NE2000 board $bd";
                PREFIX="nat";
                MAX_BD=3;
                ;;
        son) echo "Configuring National Semiconductor Sonic board $bd";
                PREFIX="son";
                MAX_BD=3;
                ;;
       d22e) echo "Configuring Infotel IN-220P Ethernet board $bd";
                PREFIX="d22e";
                MAX_BD=3;
                ;;
       d51e) echo "Configuring D-Link DFE-510 Ethernet board $bd";
                PREFIX="d51e";
                MAX_BD=3;
                ;;
        tok) echo "Configuring IBM Token Ring Adapter $bd";
                PREFIX="tok";
                MAX_BD=1;
                ;;
        exos) echo "Configuring Excelan 205 Ethernet Adapter $bd";
                PREFIX="exos";
                MAX_BD=3;
                ;;
        hpi) echo "Configuring HP ISA LAN adapter $bd";
                PREFIX="hpi";
                MAX_BD=3;
                ;;
        hpe) echo "Configuring HP EISA Slave LAN adapter $bd";
                PREFIX="hpe";
                MAX_BD=3;
                ;;
        i3B) echo "Configuring Racal InterLan ES 3210 board $bd";
                PREFIX="i3B";
                MAX_BD=3;
                ;;
        i6E) echo "Configuring Racal InterLan NL 6510 board $bd";
                PREFIX="i6E";
                MAX_BD=0;
                ;;
        *) echo "ERROR: Unknown LLI driver being configured ($name$bd)";
                cleanup $FAIL;
                ;;
        esac

        if [ $bd -gt $MAX_BD ]
        then
                echo "ERROR: Only boards 0..$MAX_BD are supported by this driver";
                cleanup $FAIL
        fi
        echo
}

#
# function to produce the info for the System file for the 3C501 & 3C503
# boards
#
system_e3A() {
        bd=$1

        case $bd in
        0) IRQ=3; BIO=300;;
        1) IRQ=2; BIO=310;;
        2) IRQ=5; BIO=330;;
        3) IRQ=7; BIO=350;;
        esac

        while :
        do
                prompt_select "Enter IRQ" $IRQ "2 3 4 5 6 7" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        while :
        do
                prompt_range "Enter I/O base address" $BIO "100" "3f0" "10" || cleanup $FAIL
                bio=$result
                EIO=`ha $bio 0f`
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio

        NMINORS="1"

        # up the 2k block buffers, this driver uses more than most drivers.
        awk '/^NBLK2048/ {
                NEW=$2+8
                printf "%s\t%s\n",$1,NEW
                next
        }
        { print } ' < /etc/conf/cf.d/stune > /tmp/bog$$
        mv /tmp/bog$$ /etc/conf/cf.d/stune
}

#
# function to produce the info for the System file for the 3C501 & 3C503
# boards
#
system_e3B() {
        bd=$1

        case $bd in
        0) IRQ=3; BIO=300;;
        1) IRQ=2; BIO=310;;
        2) IRQ=5; BIO=330;;
        3) IRQ=4; BIO=350;;
        esac

        while :
        do
                prompt_select "Enter IRQ" $IRQ "2 3 4 5" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        while :
        do
                prompt_select "Enter I/O base address" $BIO "250 280 2A0 2E0 300 310 330 350" || cleanup $FAIL
                bio=$result
                EIO=`ha $bio 0f`
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio

        NMINORS="1"

        # set the thick/thin thing
        prompt_yn "Does this 503 board use thick (AUI) ethernet?" "n" || cleanup $FAIL
        thick=0
        [ "$result" = "Y" ] && thick=1

        currdir=`pwd`
        cd /etc/conf/pack.d/e3B0
        sed -e "s/fine XCVR$bd.*/fine XCVR$bd   $thick/" < space.c > /tmp/bog$$
        mv /tmp/bog$$ space.c
        cd $currdir
}

#
# function to produce the info for the System file for the NE2000
# boards
#
system_nat() {
        bd=$1

        case $bd in
        0) IRQ=3; BIO=300;;
        1) IRQ=2; BIO=320;;
        2) IRQ=5; BIO=340;;
        3) IRQ=4; BIO=360;;
        esac

        while :
        do
                prompt_select "Enter IRQ" $IRQ "2 3 4 5" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        while :
        do
                prompt_select "Enter I/O base address" $BIO "300 320 340 360" || cleanup $FAIL
                bio=$result
                EIO=`ha $bio 1f`
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio

        NMINORS="1"

}

#
# function to produce the info for the System file for the SONIC
# boards
#
system_son() {
        bd=$1

        case $bd in
        0) IRQ=9;  BIO=2000;;
        1) IRQ=10; BIO=3000;;
        2) IRQ=11; BIO=4000;;
        3) IRQ=15; BIO=5000;;
        esac

        while :
        do
                prompt_select "Enter IRQ" $IRQ "9 10 11 15" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        while :
        do
                prompt_range "Enter I/O base address" $BIO "1000" "7000" "1000 " || cleanup $FAIL
                bio=$result
                EIO=`ha $bio 1f`
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio

        NMINORS="1"

}

#
# system_d51e()
system_d51e() {
        BIO=0
        EIO=0
        IRQ=0
        NMINORS="1"
}

#
# function to produce the info for the System file for the DE-220
# boards
#
system_d22e() {

        MediaType=3

        echo ""
        echo "NOTE:"
        echo "  If the board of IN-220P is a non-plug and play card,"
        echo "  please use setup program in DOS to change I/O base address,"
        echo "  and IRQ number if conflict."
        echo ""
        echo ""
        echo "Please choose the media mode that you want....................."
        echo ""
        echo "  0. Twisted pair connection."
        echo "  1. BNC connection."
        echo "  2. AUI connection."
        echo "  3. Automatic detection between TP BNC and AUI."
        echo "  4. Use EEPROM setting."
        echo ""
        prompt_select " Enter number of media mode selection" $MediaType "0 1 2 3 4" || cleanup $FAIL
        MediaType=$result
        echo ""
        case $MediaType in
        0) MediaTypeTXT="MEDIA_UTP";
           echo " Media mode : Twisted pair. ";
           ;;
        1) MediaTypeTXT="MEDIA_BNC";
           echo " Media mode : BNC.";
           ;;
        2) MediaTypeTXT="MEDIA_AUI";
           echo " Media mode : AUI.";
           ;;
        3) MediaTypeTXT="MEDIA_AUTO";
           echo " Media mode : Automatic detection between TP BNC and AUI.";
           ;;
        4) MediaTypeTXT="MEDIA_DEFAULT";
           echo " Media mode : Use EEPROM setting";
           ;;
        esac

        ed -s /etc/conf/pack.d/d22e0/space.c << TOAST > /dev/null
/#define ND22E_MediaType_$bd/
d
i
#define ND22E_MediaType_$bd     $MediaTypeTXT
.
w
q
TOAST

        BIO=0
        EIO=0
        IRQ=0
        NMINORS="1"

}

#
# function to produce the info for the System file for the WD1013
# boards
#
system_wdt() {
        bd=$1

        ucbase="wdt"
        case $bd in
        0) IRQ=3; BIO=300; BRAM=c0000;;
        1) IRQ=4; BIO=320; BRAM=c8000;;
        2) IRQ=5; BIO=340; BRAM=d0000;;
        3) IRQ=9; BIO=360; BRAM=d8000;;
        esac

        while :
        do
                prompt_select "Enter IRQ" $IRQ "3 4 5 7 9 10 11 15" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        while :
        do
                prompt_range "Enter I/O base address" $BIO "200" "3e0" "20" || cleanup $FAIL
                bio=$result
                EIO=`ha $bio 1f`
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio

        while :
        do
                prompt_range "Enter RAM base address" $BRAM "80000" "f0c000" "2000" || cleanup $FAIL
                bram=$result
                ERAM=`ha $bram 3fff`
                checkram $name$bd $bram $ERAM && break
        done
        BRAM=$bram

        NMINORS="1"

}


#
# function to produce the information for the System file for the 3C523
#
system_e3C() {
        bd=$1

        case $bd in
        0) IRQ=3; BIO=300; BRAM=c0000;;
        1) IRQ=7; BIO=1300; BRAM=c8000;;
        2) IRQ=9; BIO=2300; BRAM=d0000;;
        3) IRQ=12; BIO=3300; BRAM=d8000;;
        esac

        while :
        do
                prompt_select "Enter IRQ" $IRQ "3 7 9 12" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        while :
        do
                prompt_range "Enter I/O base address" $BIO "300" "3300" "1000" || cleanup $FAIL
                bio=$result
                EIO=`ha $bio 8`
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio

        while :
        do
                prompt_range "Enter RAM base address" $BRAM "c0000" "d8000" "8000" || cleanup $FAIL
                bram=$result
                ERAM=`ha $bram 5fff`
                checkram $name$bd $bram $ERAM && break
        done
        BRAM=$bram

        NMINORS="1"
}

#
# function to produce the information for the System file for the 3C507
# board
#
system_e3D() {
        bd=$1

        case $bd in
        0) IRQ=3; BIO=300; BRAM=c0000;;
        1) IRQ=9; BIO=310; BRAM=d0000;;
        2) IRQ=5; BIO=320; BRAM=c8000;;
        3) IRQ=7; BIO=330; BRAM=d8000;;
        esac

        while :
        do
                prompt_select "Enter IRQ" $IRQ "3 5 7 9 10 11 12 15" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        while :
        do
                prompt_select "Enter I/O base address" $BIO "200 210 220 230 240 250 260 280 290 2a0 2b0 2c0 2d0 2e0 300 310 320 330 340 350 360 380 390 3a0 3e0" || cleanup $FAIL
                bio=$result
                EIO=`ha $bio f`
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio

        while :
        do
                prompt_select "Enter RAM base address" $BRAM "c0000 c8000 d0000 d8000 f00000 f20000 f40000 f60000 f80000" || cleanup $FAIL
                bram=$result

                case $bram in
                c[08]000|d0000) sizelist="16 32 48 64";;
                d8000)          sizelist="16 32";;
                *)              sizelist="64";;
                esac
                prompt_select "Enter RAM Size in k" 64 "$sizelist" || cleanup $FAIL
                case $result in
                16) size=3fff ;;
                32) size=7fff ;;
                48) size=bfff ;;
                64) size=ffff ;;
                esac
                ERAM=`ha $bram $size`
                checkram $name$bd $bram $ERAM && break
        done
        BRAM=$bram

        NMINORS="32"
}

#
# function to produce the information for the space.c file for the token ring
#
space_token() {

        # Set whether Netbeui is above us or not
        nbe=0
        [ "$name_above" = "nbe" ] && nbe=1

        currdir=`pwd`
        cd /etc/conf/pack.d/tok0
        sed -e "s/fine TOK$bd.*/fine TOK$bd     $nbe/" < space.c > /tmp/bog$$
        cp /tmp/bog$$ space.c
        rm -r /tmp/bog$$
        cd $currdir
}

#
# function to remove address conflicts in the sio driver
#
sio_conflict() {
        currdir=`pwd`
        cd /etc/conf/pack.d/sio
        if [ "$type" = "386GT" -a "$base" = "tok0" ]
        then
                # get rid of sio access to 0x2f0 (Global Interrupt enable) on AT
                grep "ibm COM3" space.c > /dev/null && {
                        echo "Removing ibm COM3 from link kit..."
                        [ ! -f space.c.rls ] && cp space.c space.c.rls
                        sed -e /"ibm COM3/s/^{/\/* LLI {/p" space.c > /tmp/bog$$
                        mv /tmp/bog$$ space.c > /dev/null 2>&1
                }
        fi
        grep "(sd)0x$BIO" space.c > /dev/null && {
                echo "Removing serial cards using base address 0x$BIO from link kit..."
                [ ! -f space.c.rls ] && cp space.c space.c.rls
                sed -e /"(sd)0x$BIO,/s/^{/\/* LLI {/p" space.c > /tmp/bog$$
                mv /tmp/bog$$ space.c > /dev/null 2>&1
        }
        cd $currdir
}

#
# determine release, and AT or MCA bus - set rel and type variables accordingly.
#
os_type() {
        rel=`sed -n 's/^#rel=\(.*\).$/\1/p' /etc/perms/rts`
        if [ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ]
        then
                type=`sed -n 's/^#typ=\(.*\)$/\1/p' /etc/perms/inst`
        else
                # 3.2.4 - one release supports AT, MCA, and EISA.
                uname -X | grep "BusType = MCA" >/dev/null 2>&1
                if [ $? -eq 0 ]
                then
                        type=386MC
                else
                        type=386GT
                fi
        fi
}

#
# function to produce the information for the System file for the token ring
#
# BRAM/ERAM indicate ROM address switch settings; BSHRAM/ESHRAM indicate
# shared memory settings.  We assume they're using 16K of SHRAM on the adapter.
#
system_tok() {
        bd=$1

        case $bd in
        0) IRQ=2; BIO=a20; BRAM=cc000; BSHRAM=d8000;;
        1) IRQ=3; BIO=a24; BRAM=dc000; BSHRAM=d4000;;
        esac

        while :
        do
                prompt_select "Enter IRQ" $IRQ "2 3 6 7" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        EIO=`ha $BIO 3`

        while :
        do
                prompt_range "Enter ROM base address" $BRAM "c0000" "de000" "2000" || cleanup $FAIL
                brom=$result
                ERAM=`ha $brom 1fff`
                checkram $name$bd $brom $ERAM && break
        done
        BRAM=$brom

        # Microchannel tok adapters have a configurable shared RAM address.
        if [ "$type" = "386GT" ]
        then
                ESHRAM=`ha $BSHRAM 3fff`
                doramclash $name$bd $BSHRAM $ESHRAM && {
                        echo "The RAM addresses required for $name$bd are in use by the $clash device"
                        echo "You must remove $clash before installing $name$bd"
                        cleanup $FAIL
                }
        else
                prompt_range "Enter RAM base address" $BSHRAM "c0000" "dc000" "4000" || cleanup $FAIL
                BSHRAM=$result
                ESHRAM=`ha $BSHRAM 3fff`
                doramclash $name$bd $BSHRAM $ESHRAM && {
                        echo "The RAM addresses required for $name$bd are in use by the $clash device"
                        echo "You must remove $clash before installing $name$bd"
                        cleanup $FAIL
                }
        fi

        if [ ! -x /usr/lib/token ]
        then
                mkdir /usr/lib/token
        fi

        prompt_yn "Restrict broadcasts to the local ring" "y" || cleanup $FAIL
        if [ "$result" = "Y" ]
        then
                touch /usr/lib/token/noroute$bd
        else
                rm -f /usr/lib/token/noroute$bd
        fi

        NMINORS="1"

        space_token
}

#
# function to produce the information for the System file for the Excelan
#
system_exos() {
        bd=$1

        case $bd in
        0) IRQ=2; BIO=310; BRAM=d0000;;
        1) IRQ=3; BIO=300; BRAM=d4000;;
        2) IRQ=5; BIO=320; BRAM=d8000;;
        3) IRQ=7; BIO=330; BRAM=dc000;;
        esac

        while :
        do
                prompt_select "Enter IRQ" $IRQ "2 3 4 5 6 7" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        while :
        do
                prompt_range "Enter I/O base address" $BIO "300" "330" "10" || cleanup $FAIL
                bio=$result
                EIO=`ha $bio 7`
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio

        while :
        do
                prompt_range "Enter RAM base address" $BRAM "a0000" "f0000" "4000" || cleanup $FAIL
                bram=$result
                ERAM=`ha $bram 3fff`
                checkram $name$bd $bram $ERAM && break
        done
        BRAM=$bram

        NMINORS="32"
}

#
# function to produce the information for the System file for the western
# digital board
#
system_wdn() {
        bd=$1

        case $bd in
        0) IRQ=3; BIO=240; BRAM=d0000;;
        1) IRQ=2; BIO=380; BRAM=d2000;;
        2) IRQ=5; BIO=260; BRAM=d4000;;
        3) IRQ=7; BIO=340; BRAM=d6000;;
        esac

        if [ "$type" = "386MC" ]
        then
                prompt_yn "\nAre you installing an Elite series (WD8013EP/A, WD8013WP/A, or\nWD8013EW/A) Western Digital card?" "n" || cleanup $FAIL
                if [ "$result" = "Y" ]
                then
                        elite="Y"
                        case $bd in
                        0) IRQ=3; BIO=800; BRAM=d0000;;
                        1) IRQ=4; BIO=1800; BRAM=d2000;;
                        2) IRQ=10; BIO=2800; BRAM=d4000;;
                        3) IRQ=15; BIO=3800; BRAM=d6000;;
                        esac
                fi
        fi

        while :
        do
                if [ "$type" = "386MC" -a "$elite" = "Y" ]
                then
                        # WD8013EP/A allows IRQ 14, WD8013WP/A allows IRQ 15
                        prompt_select "Enter IRQ" $IRQ "3 4 10 14 15" || cleanup $FAIL
                else
                        prompt_select "Enter IRQ" $IRQ "2 3 4 5 7 10 11 15" || cleanup $FAIL
                fi
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        while :
        do
                if [ "$type" = "386MC" -a "$elite" = "Y" ]
                then
                        prompt_range "Enter I/O base address" $BIO "800" "f800" "1000" || cleanup $FAIL
                else
                        prompt_range "Enter I/O base address" $BIO "200" "3e0" "20" || cleanup $FAIL
                fi
                bio=$result
                EIO=`ha $bio 1f`
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio

        while :
        do
                if [ "$type" = "386MC" -a "$elite" = "Y" ]
                then
                        prompt_range "Enter RAM base address" $BRAM "c0000" "fde000" "2000" || cleanup $FAIL
                else
                        prompt_range "Enter RAM base address" $BRAM "80000" "f0c000" "2000" || cleanup $FAIL
                fi
                bram=$result
                if [ "$type" = "386GT" -o "$elite" = "Y" ]
                then
                        prompt_select "Enter RAM Size in k" 8 "8 16" || cleanup $FAIL
                        case $result in
                                8)  size=1fff ;;
                                16) size=3fff ;;
                        esac
                else
                        size=3fff
                fi
                ERAM=`ha $bram $size`
                checkram $name$bd $bram $ERAM || continue
                hc $bram 100000 f0c000 2000 > /dev/null 2>& 1 && {
                        echo "Warning: this address may not be valid if your network adapter"
                        echo "is not a Western Digital 16-Bit Elite adapter"
                        echo "Shared memory addresses above 1 Meg are supported by 16-bit Elite adapters only."
                }
                break
        done
        BRAM=$bram

        NMINORS="32"

        [ "$rel" = "3.2.1" -o "$rel" = "3.2.0" ] && {
                if [ "$type" = "386GT" ]
                then
                        grep "int arch =" /etc/conf/pack.d/wdn0/space.c >/dev/null 2>&1 || {
                        echo "int arch = 1;" >> /etc/conf/pack.d/wdn0/space.c
                        }
                elif [ "$type" = "386MC" ]
                then
                        grep "int arch =" /etc/conf/pack.d/wdn0/space.c >/dev/null 2>&1 || {
                        echo "int arch = 2;" >> /etc/conf/pack.d/wdn0/space.c
                        }
                fi
        }
}


#
# function to produce info for the System file for HP EISA Slave LAN adapters
#
system_hpe() {
        bd=$1

        case ${bd} in
        0) IRQ=5 ; DMA=3;;
        1) IRQ=7 ; DMA=2;;
        2) IRQ=10; DMA=6;;
        3) IRQ=11; DMA=5;;
        esac

        while :
        do
                prompt_select "Enter DMA channel" $DMA "1 2 3 5 6" || cleanup $FAIL
                dma=$result
                checkdma $name$bd $dma && break
        done
        DMACHAN=$dma

        while :
        do
                prompt_select "Enter IRQ" $IRQ "3 4 5 7 10 11 12" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        while :
        do
                prompt_select "Enter slot number" "" "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" || cleanup $FAIL
                SLOT=$result
                case $result in
                 0) bio=0C00; EIO=0CFF;;
                 1) bio=1C00; EIO=1CFF;;
                 2) bio=2C00; EIO=2CFF;;
                 3) bio=3C00; EIO=3CFF;;
                 4) bio=4C00; EIO=4CFF;;
                 5) bio=5C00; EIO=5CFF;;
                 6) bio=6C00; EIO=6CFF;;
                 7) bio=7C00; EIO=7CFF;;
                 8) bio=8C00; EIO=8CFF;;
                 9) bio=9C00; EIO=9CFF;;
                10) bio=AC00; EIO=ACFF;;
                11) bio=BC00; EIO=BCFF;;
                12) bio=CC00; EIO=CCFF;;
                13) bio=DC00; EIO=DCFF;;
                14) bio=EC00; EIO=ECFF;;
                15) bio=FC00; EIO=DCFF;;
                *) cleanup $FAIL
                esac
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio

BRAM="0"
ERAM="0"
NMINORS="1"
}

#
# function to produce the info for the System file for the HP ISA LAN adapters
#
system_hpi() {
        bd=$1

        case ${bd} in
        0) IRQ=2  ; BIO=300;;
        1) IRQ=3  ; BIO=240;;
        2) IRQ=5  ; BIO=280;;
        3) IRQ=7  ; BIO=2C0;;
        esac

        while :
        do
                echo "IRQs 10 and 11 are only valid for 16-bit adapters."
                prompt_select "Enter IRQ" $IRQ "2 3 4 5 7 10 11" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq
        while :
        do
                prompt_select "Enter I/O base address" $BIO "200 240 280 2C0 300 320 340" || cleanup $FAIL
                bio=$result
                case $result in
                200) EIO=21F ;;
                240) EIO=25F ;;
                280) EIO=29F ;;
                2C0) EIO=2DF ;;
                300) EIO=31F ;;
                320) EIO=33F ;;
                340) EIO=35F ;;
                *) cleanup $FAIL
                esac
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio
        BRAM="0"
        ERAM="0"
        NMINORS="1"
}

#
# Edits the major number into the space.c file for Racal InterLan drivers
#
space_inn() {

        spacef=${CONF:-/etc/conf}/pack.d/${drv}0/space.c
        currdir=`pwd`
        if [ "$installed" = "TRUE" ]
        then
                cd $CONF/cf.d
                maj=`./configure -j $base`
                if [ $? -ne 0 -o "$maj" = "" ]
                then
                        maj=`./configure -j NEXTMAJOR`
                fi
                cd $currdir
        else                    # get the next major number
                cd $CONF/cf.d
                maj=`./configure -j NEXTMAJOR`
                cd $currdir
        fi
                str="${ucbase}major${bd}"
        sed "s/$str/$maj/" $spacef >/tmp/bog$$
        cp /tmp/bog$$ $spacef
        rm -f /tmp/bog$$
}

#
# function to produce the information for the System file for the Racal InterLan
# ES-3210 board.
#
system_i3B() {
        ucbase="I3B"
        bd=$1
        spacef=${CONF:-/etc/conf}/pack.d/${drv}0/space.c

        # BIO represents EISA slot number here
        case $bd in
        0) IRQ=9; BIO=1; BRAM=d0000; DMA=NONE;;
        1) IRQ=10; BIO=2; BRAM=d4000; DMA=NONE;;
        2) IRQ=11; BIO=4; BRAM=d8000; DMA=NONE;;
        3) IRQ=12; BIO=5; BRAM=dc000; DMA=NONE;;
        esac

        while :
        do
                prompt_select "Enter IRQ" $IRQ "3 4 5 6 7 9 10 11 12 14 15" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        while :
        do
                prompt_range "Enter slot number" $BIO "1" "15" "1" || cleanup $FAIL
                bio=`expr $result * 1000`
                EIO=`ha $bio fff`
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio

        while :
        do
                prompt_range "Enter RAM base address" $BRAM "c0000" "3fffc000" "4000" || cleanup $FAIL
                bram=$result
                ERAM=`ha $bram 3fff`
                checkram $name$bd $bram $ERAM || continue
                break
        done
        BRAM=$bram

        while :
        do
                prompt_select "Enter DMA" $DMA "NONE 0 1 2 3 5 6 7" || cleanup $FAIL
                if [ "$result" = "NONE" ]
                then
                        dma=-1
                else
                        dma=$result
                fi
                checkdma $name$bd $dma && break
        done
        DMACHAN=$dma
#
# Setup space.c.
# Get the media type (thick or thin and edit it into space.c
#
        prompt_yn "Does this ES-3210 board use thick (AUI) ethernet?" "n" || cleanup $FAIL
        if [ "$result" = "Y" ]
        then
                netyp="THIK"
        else
                netyp="THIN"
        fi
        if [ $bd -eq 0 ]
        then
                str="THIKTHIN"
        else
                str="THIKTHIN${bd}"
        fi
        a=`grep -n "^#define[   ]${str}[        ]" $spacef`
        b=`expr "$a" : '.*G1_\(....\)'`
        if [ "$b" != "$netyp" ]
        then
                c=`expr "$a" : '\(.*:\)' | sed 's/://'`
                sed "${c}s/G1_$b/G1_$netyp/" $spacef >/tmp/bog$$
                cp /tmp/bog$$ $spacef
                rm /tmp/bog$$
        fi
        space_inn               # Edit major number it into space.c
        NMINORS="1"
}

#
# function to produce the information for the System file for the Racal InterLan
# NI-6510 board.
#
system_i6E() {
        ucbase="I6E"
        bd=$1
        spacef=${CONF:-/etc/conf}/pack.d/${drv}0/space.c
        BRAM=0

        case $bd in
        0) IRQ=9; BIO=360; DMA=3;;
        1) IRQ=12; BIO=340; DMA=5;;
        esac

        while :
        do
                prompt_select "Enter IRQ" $IRQ "5 9 12 15" || cleanup $FAIL
                irq=$result
                checkvec $name$bd $irq && break
        done
        IRQ=$irq

        while :
        do
                prompt_range "Enter I/O base address" $BIO "300" "360" "20" || cleanup $FAIL
                bio=$result
                EIO=`ha $bio f`
                checkaddr $name$bd $bio $EIO && break
        done
        BIO=$bio

        while :
        do
                prompt_select "Enter DMA" $DMA "0 3 5 6" || cleanup $FAIL
                dma=$result
                checkdma $name$bd $dma && break
        done
        DMACHAN=$dma
        space_inn               # Edit major number it into space.c
        NMINORS="1"
}

create_scripts()
{
        if [ $bd -ne $MAX_BD ]
        then
                currdir=`pwd`
                netconfigdir=/usr/lib/netconfig
                cd $netconfigdir/info
                newboard=`expr $bd + 1`
                newfile=${drv}${newboard}
                cp ${drv}0 $newfile
                sed -e '/^NAME=.*'"[^0]"'/s/0\"/'$newboard'\"/p' $newfile > /tmp/bog$$
                sed -e '/^DESCRIPTION=.*'"[^0]"'/s/0\"/'$newboard'\"/p' /tmp/bog$$ > $newfile
                rm -r /tmp/bog$$
                chown bin $newfile
                chgrp bin $newfile
                chmod 750 $newfile

                cd $netconfigdir/init
                ln $base ${drv}`expr $bd + 1` > /dev/null 2>&1

                cd $netconfigdir/remove
                ln $base ${drv}`expr $bd + 1` > /dev/null 2>&1
                cd $currdir
        fi
}

# main()
#

#
# get the name of the init script being run, since one script
# is used for multiple drivers; get the number at the end of the
# script's name
#

if [ $# -gt 1 ]
then
        name_below=$1; if_below=$2
        name_above=$3; if_above=$4
        configure=$5
fi

base=`basename $0`
drv=`echo $base | sed -e 's/[0-9]*$//`
bd=`expr $base : '.*\(.\)'`
chains=/usr/lib/lli/chains
chain=$base:$name_above
confdir=/etc/conf/cf.d

makedevs
check_args $drv $bd

#
# Check and manage our internal chains file.
# This file allows coexistent mkdev and netconfig calls.
#
# chain already installed
grep $chain $chains > /dev/null 2>& 1 && {
        echo $chain >> $chains
        cleanup $OK
}
# this board already installed
grep $base: $chains > /dev/null 2>& 1 && {
        echo $base already configured.
        echo $chain >> $chains
        [ "$drv" = "tok" -a "$name_above" = "nbe" ] && {
                space_token
        }
        echo "NODE=/etc/conf/node.d/$base" >/tmp/$base.src
        chmod 777 /tmp/$base.src
        cleanup $OK
}
#
# Now check that if we are not board zero that board zero is installed
#
[ "$bd" -ne "0" ] && {
        grep ${drv}0 $chains > /dev/null 2>& 1 || {
                echo "${drv}0 not configured, you must configure it first"
                cleanup $FAIL
        }
}

#
# check to see if the driver is already in the kernel link-kit so we can
# either add it or update it later on
#
idcheck -p $base -i /tmp/dev$$
if [ $? -gt 16 ]
then
        installed="TRUE"
else
        installed="FALSE"
fi

if [ "$bd" = "0" ]
then
        echo "Installing the $drv driver into the link kit"
        cd /usr/lib/lli/$drv
        if [ "$installed" = "TRUE" ]
        then
                idinstall -u -e -k $base
        else
                idinstall -a -e -k $base
        fi
        makedevs
else
        idcheck -p ${drv}0 -i /tmp/dev$$
        if [ $? -le 16 ]
        then
                echo "${drv}0 must be configured before attempting to configure $drv"
                cleanup 1
        fi
fi

#
# create the temporary directory for installing the driver
#
cd /tmp; rm -rf $base
mkdir $base; cd $base

DMACHAN="-1"

#
# set rel, type variables.
#
os_type

#
# Do special board dependent processing
#
system_$drv $bd

echo
if [ "$IRQ" = "2" ]
then
        IRQ=9
fi

echo "$base\tY\t$NMINORS\t0\t0\t$IRQ\t$BIO\t$EIO\t$BRAM\t$ERAM" >./System

#
# All the drivers support more than one board.  In fact all the code to
# support all the boards is in the Driver.o for the board for the 1st board
# (eg the e3A0 driver acually contains enough code for the e3A1, e3A2 & e3A3
# boards).  As we need a Driver.o to be associated with 2nd, 3rd or 4th board
# we install a dummy Driver.o, and a Master and Node which will actually cause
# calls into the base driver.
#
if [ $bd -gt 0 ]
then
        echo "$base     -       iScH    $PREFIX$bd      0       0       1       256     $DMACHAN" >./Master
        echo "clone     $base   c       $base" >./Node

        if [ "$installed" = "TRUE" ]
        then
                idinstall -u -m -s -n -e -k $base
        else
                cp $LIB/Driver.o .
                idinstall -a -e -k $base
        fi
else
        echo "$base     I       iScH    $PREFIX 0       0       1       256     $DMACHAN" >./Master
        idinstall -u -m -s -e -k $base
fi
# we successfully installed this driver, add it to the chains file
echo $chain >> $chains

# create next set of info, init, and remove files
create_scripts

# delete any potential BASE I/O address conflicts with the sio driver
[ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ] && sio_conflict

echo "NODE=/etc/conf/node.d/$base" >/tmp/$base.src
chmod 777 /tmp/$base.src

cleanup $RELINK

[ RETURN TO DIRECTORY ]