home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Internet 2000 December / MICD_2000_12_NR1.iso / Dreamnet / drivery / Trendware / Te-16pct.exe / SCOUNIX / 4.X / INIT (.txt) < prev    next >
Microsoft Windows Help File Content  |  1996-08-05  |  20KB  |  539 lines

  1. #               (C) 1989-1990 The Santa Cruz Operation, Inc.  All Rights
  2. #               Reserved.  The user has unlimited right to use, modify
  3. #               and incorporate this code into other products provided
  4. #               it is used with SCO products and the user includes
  5. #               this notice and the associated copyright notices with
  6. #               any such application.
  7. LIB=/usr/lib/lli
  8. CONF=/etc/conf
  9. PATH=/bin:/usr/bin:/etc/:$CONF/bin:$LIB
  10. # Set possible return codes for this script
  11. OK=0;   FAIL=1; RELINK=2;
  12. BRAM="0"
  13. ERAM="0"
  14. # Prompt the user for a hex value, it must be within a given range
  15. # Usage:
  16. #       prompt_range "Message" default min max [step]
  17. prompt_range() {
  18.         mesg=$1
  19.         default=$2
  20.         range_min=$3 range_max=$4
  21.         step="1"
  22.         if [ $# -eq 5 ]
  23.         then
  24.                 step=$5
  25.         fi
  26.         while :
  27.         do
  28.                 echo "${mesg} (${range_min}..${range_max}) [${default}] or 'q' to quit: \c"
  29.                 read result
  30.                 case $result in
  31.                 Q|q)
  32.                         return $FAIL
  33.                         ;;
  34.                 "")
  35.                         result=$default
  36.                         ;;
  37.                 esac
  38.                 hc $result $range_min $range_max $step
  39.                 case $? in
  40.                 0) return $OK;;
  41.                 1) cleanup $FAIL;;
  42.                 2) cleanup $FAIL;;
  43.                 esac
  44.         done
  45. # print a prompt
  46. p() {
  47.         set -f
  48.         /bin/echo $*
  49.         set +f
  50.         return $?
  51. # Prompt the user to make a selection a list of values
  52. # Usage:
  53. #       prompt_select "Message" default "value_list"
  54. prompt_select() {
  55.         mesg=$1
  56.         default=$2
  57.         values=$3
  58.         while :
  59.         do
  60.                 if [ "$default" = "" ]
  61.                 then
  62.                         echo "${mesg} (${values}) or 'q' to quit: \c"
  63.                 else
  64.                         echo "${mesg} (${values}) [${default}] or 'q' to quit: \c"
  65.                 fi
  66.                 read result
  67.                 case $result in
  68.                 Q|q)
  69.                         return $FAIL
  70.                         ;;
  71.                 "")
  72.                         result=$default
  73.                         ;;
  74.                 esac
  75.                 for i in $values
  76.                 do
  77.                         if [ "$i" = "$result" ]
  78.                         then
  79.                                 return $OK
  80.                         fi
  81.                 done
  82.                 echo "Illegal value, must be one of (${values})"
  83.         done
  84. # prompt the user to answer a yes no question or 'q' to quit
  85. # Usage:
  86. #       prompt_yn "Message" default
  87. prompt_yn() {
  88.         mesg=$1
  89.         default=$2
  90.         while :
  91.         do
  92.                 echo "${mesg} (y/n) [${default}] or 'q' to quit: \c"
  93.                 read result
  94.                 case $result in
  95.                 q|Q) return $FAIL;;
  96.                 y|Y) result="Y"; return $OK;;
  97.                 n|N) result="N"; return $OK;;
  98.                 "") result=`echo $default | tr "yn" "YN"`; return $OK;;
  99.                 esac
  100.                 echo "Illegal value, please type 'y' 'n' or 'q'"
  101.         done
  102. # Fake up an mdevice and an sdevice for idcheck
  103. makedevs() {
  104.         dir=`pwd`
  105.         rm -fr /tmp/dev$$
  106.         mkdir /tmp/dev$$
  107.         cd /etc/conf/cf.d
  108.         cp mdevice /tmp/dev$$
  109.         cd ../sdevice.d
  110.         cat * > /tmp/dev$$/sdevice
  111.         cd $dir
  112. cleanup() {
  113.         cd /
  114.         rm -fr /tmp/dev$$
  115.         rm -fr /tmp/$base
  116.         exit $1
  117. # Removes the given interrupt vector for the $clash device.
  118. rmvector() {
  119.         clash=$1
  120.         vec=$2
  121.         cd $confdir
  122.         echo "\nRemoving interrupt vector $vec for the $clash device ..."
  123.         [ "$vec" = "2" ] && vec=9
  124.         major=`./configure -j $clash` && {
  125.                 # remove device but leave it required
  126.                 if [ "$major" != "0" ]
  127.                 then
  128.                         ./configure -d -c -m $major -v $vec -Y >> conflog 2>&1 || {
  129.                                 cd $currdir
  130.                                 cleanup $FAIL
  131.                         }
  132.                 else
  133.                         sed -e "s/Y/N/" ../sdevice.d/$clash > /tmp/bog$$
  134.                         mv /tmp/bog$$ ../sdevice.d/$clash
  135.                 fi
  136.                 # remove required setting if no more left
  137.                 if grep "Y" ../sdevice.d/$clash > /dev/null 2>&1
  138.                 then
  139.                         true
  140.                 elif [ "$major" != "0" ]
  141.                 then
  142.                         ./configure -d -c -m $major -v $vec -R -Y >> conflog 2>&1 || {
  143.                                 cd $currdir
  144.                                 cleanup $FAIL
  145.                         }
  146.                 fi
  147.         }
  148.         cd $currdir
  149.         return $OK
  150. # On unix, we must check the files in sdevice.d.
  151. # Sets the variable $clash to the driver code name if there is a driver that
  152. # has already been allocated the given vector. Uses awk.
  153. dointclash() {
  154.         driver=$1
  155.         vec=$2
  156.         [ "$vec" = "2" ] && vec=9
  157.         cd $confdir/../sdevice.d
  158.         clash=`cat * | awk '{ if ( $6 == intr && $2 == "Y" ) exit } \
  159.                         END { print $1 }' intr=$vec`
  160.         cd $currdir
  161.         [ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
  162.         # found a clash
  163.         return $OK
  164. checkvec() {
  165.         driver=$1
  166.         vector=$2
  167.         clash=
  168.         currdir=`pwd`
  169.         while dointclash $driver $vector
  170.         do
  171.                 prompt_select "Interrupt vector $vector is already in use for the $clash device.\n\n\
  172. The alternatives available to you are:\n\n\
  173. \t1. Continue the installation and remove vector $vector for the $clash device.\n\
  174. \t2. Select a different interrupt vector.\n\n\
  175. Select an option" 1 "1 2" || {
  176.                         cleanup $FAIL
  177.                 }
  178.                 case $result in
  179.                 1)      rmvector $clash $vector || {
  180.                                 echo "Failed to remove vector $vector"
  181.                                 cleanup $FAIL
  182.                         }
  183.                         makedevs
  184.                         return $OK
  185.                         ;;
  186.                 2)      return $FAIL
  187.                         ;;
  188.                 esac
  189.         done
  190.         return $OK
  191. doaddrclash() {
  192.         driver=$1
  193.         addr1=$2
  194.         addr2=$3
  195.         cd $confdir
  196.         clash=`../bin/idcheck -ar -l $addr1 -u $addr2 -i /tmp/dev$$`
  197.         cd $currdir
  198.         [ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
  199.         # found a clash
  200.         return $OK
  201. # Removes the $clash device.
  202. rmaddr() {
  203.         clash=$1
  204.         cd $confdir
  205.         echo "\nRemoving the $clash device ..."
  206.         major=`./configure -j $clash` && {
  207.                 # remove device but leave it required
  208.                 if [ "$major" != "0" ]
  209.                 then
  210.                         ./configure -d -c -m $major -Y >> conflog 2>&1 || {
  211.                                 cd $currdir
  212.                                 cleanup $FAIL
  213.                         }
  214.                 else
  215.                         sed -e "s/Y/N/" ../sdevice.d/$clash > /tmp/bog$$
  216.                         mv /tmp/bog$$ ../sdevice.d/$clash
  217.                 fi
  218.                 # remove required setting if no more left
  219.                 if grep "Y" ../sdevice.d/$clash > /dev/null 2>&1
  220.                 then
  221.                         true
  222.                 elif [ "$major" != "0" ]
  223.                 then
  224.                         ./configure -d -c -m $major -R -Y >> conflog 2>&1 || {
  225.                                 cd $currdir
  226.                                 cleanup $FAIL
  227.                         }
  228.                 fi
  229.         }
  230.         cd $currdir
  231.         return $OK
  232. checkaddr() {
  233.         driver=$1
  234.         addr1=$2
  235.         addr2=$3
  236.         clash=
  237.         currdir=`pwd`
  238.         while doaddrclash $driver $addr1 $addr2
  239.         do
  240.                 if [ "$clash" = "ad" ]
  241.                 then
  242.                         echo "\n\nWARNING: Do not remove the $clash device \c"
  243.                         echo "if you are using an Adaptec disk controller"
  244.                 fi
  245.                 prompt_select "Addresses $addr1-$addr2 are already in use by the $clash device.\n\n\
  246. The alternatives available to you are:\n\n\
  247. \t1. Continue the installation and remove the $clash device.\n\
  248. \t2. Select a different address.\n\n\
  249. Select an option" 1 "1 2" || {
  250.                         cleanup $FAIL
  251.                 }
  252.                 case $result in
  253.                 1)      rmaddr $clash || {
  254.                                 echo "Failed to remove $clash device"
  255.                                 cleanup $FAIL
  256.                         }
  257.                         makedevs
  258.                         return $OK
  259.                         ;;
  260.                 2)      return $FAIL
  261.                         ;;
  262.                 esac
  263.         done
  264.         return $OK
  265. doramclash() {
  266.         driver=$1
  267.         addr1=$2
  268.         addr2=$3
  269.         cd $confdir
  270.         clash=`../bin/idcheck -cr -l $addr1 -u $addr2 -i /tmp/dev$$`
  271.         cd $currdir
  272.         [ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
  273.         # found a clash
  274.         return $OK
  275. checkram() {
  276.         driver=$1
  277.         addr1=$2
  278.         addr2=$3
  279.         clash=
  280.         currdir=`pwd`
  281.         while doramclash $driver $addr1 $addr2
  282.         do
  283.                 prompt_yn "
  284. Ram addresses $addr1-$addr2 is already in use for the $clash device.
  285. You must choose a unique address for this device to work.
  286. Do you wish to choose another address now?" y || cleanup $FAIL
  287.                 if [ "$result" = "Y" ]
  288.                 then
  289.                         return $FAIL
  290.                 else
  291.                         cleanup $FAIL
  292.                 fi
  293.         done
  294.         return $OK
  295. # On unix, we must check the lines in mdevice file.
  296. # Sets the variable $clash to the driver code name if there is a driver that
  297. # has already been allocated the given channel. Uses awk.
  298. dodmaclash() {
  299.         driver=$1
  300.         chan=$2
  301.         clash=
  302.         # -1 is never a clash
  303.         [ "$chan" = "-1" ] && return $FAIL
  304.         cd $confdir
  305.         clash=`awk '{ if ( $9 == dma ) print $1 }' dma=$chan mdevice`
  306.         [ "$clash" = "" ] && {
  307.                 cd $currdir
  308.                 return $FAIL
  309.         }
  310.         cat ../sdevice.d/$clash | awk '{ if ( $2 == "Y" ) exit 1 }' || return $OK
  311.         if [ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ]
  312.         then
  313.                 prompt_yn "
  314. DMA channel ${chan} is already in use by the $clash device.  However, the
  315. $clash device is not currently configured into the kernel.  Do you wish to
  316. remove DMA channel ${chan} from the $clash device?" y || cleanup $FAIL
  317.                 if [ "$result" = "Y" ]
  318.                 then
  319.                         sed -e "/^$clash        .*[0-9]$/{" \
  320.                                 -e 's/[0-9]$/-1/p' \
  321.                                 -e '}' mdevice > /tmp/bog$$
  322.                         mv /tmp/bog$$ mdevice
  323.                         cd $currdir
  324.                         return $FAIL
  325.                 else
  326.                         cd $currdir
  327.                         return $OK
  328.                 fi
  329.         fi
  330.         # Should be release >3.2.2, clash driver not installed if we get here.
  331.         cd $currdir
  332.         return $FAIL
  333. # Check if there is a clash of DMA channels
  334. checkdma() {
  335.         driver=$1
  336.         channel=$2
  337.         clash=
  338.         currdir=`pwd`
  339.         while dodmaclash $driver $channel
  340.         do
  341.                 prompt_yn "
  342. DMA channel ${channel} is already in use by the $clash device.
  343. You must choose a unique channel for this device to work.
  344. Do you wish to choose another channel now?" y || cleanup $FAIL
  345.                 if [ "$result" = "Y" ]
  346.                 then
  347.                         return $FAIL
  348.                 else
  349.                         cleanup $FAIL
  350.                 fi
  351.         done
  352.         return $OK
  353. check_args() {
  354.         name=$1
  355.         bd=$2
  356.         case $name in
  357.         r0e) echo "Configuring PnP ethernet adapter board $bd";
  358.                 PREFIX="r0e";
  359.                 MAX_BD=3;
  360.                 ;;
  361.         *) echo "ERROR: Unknown LLI driver being configured ($name$bd)";
  362.                 cleanup $FAIL;
  363.                 ;;
  364.         esac
  365.         if [ $bd -gt $MAX_BD ]
  366.         then
  367.                 echo "ERROR: Only boards 0..$MAX_BD are supported by this driver";
  368.                 cleanup $FAIL
  369.         fi
  370.         echo
  371. # function to produce the info for the System file for the PnP
  372. # boards
  373. system_r0e() {
  374. bd=$1
  375. IRQ=0;
  376. DMA=-1;
  377. BIO=0;
  378. EIO=0;
  379. BUS=0;
  380. DMACHAN=-1
  381. NMINORS="1"
  382. echo "Detect PnP ethernet adapter automatically."
  383. # function to remove address conflicts in the sio driver
  384. sio_conflict() {
  385.         currdir=`pwd`
  386.         cd /etc/conf/pack.d/sio
  387.         if [ "$type" = "386GT" -a "$base" = "tok0" ]
  388.         then
  389.                 # get rid of sio access to 0x2f0 (Global Interrupt enable) on AT
  390.                 grep "ibm COM3" space.c > /dev/null && {
  391.                         echo "Removing ibm COM3 from link kit..."
  392.                         [ ! -f space.c.rls ] && cp space.c space.c.rls
  393.                         sed -e /"ibm COM3/s/^{/\/* LLI {/p" space.c > /tmp/bog$$
  394.                         mv /tmp/bog$$ space.c > /dev/null 2>&1
  395.                 }
  396.         fi
  397.         grep "(sd)0x$BIO" space.c > /dev/null && {
  398.                 echo "Removing serial cards using base address 0x$BIO from link kit..."
  399.                 [ ! -f space.c.rls ] && cp space.c space.c.rls
  400.                 sed -e /"(sd)0x$BIO,/s/^{/\/* LLI {/p" space.c > /tmp/bog$$
  401.                 mv /tmp/bog$$ space.c > /dev/null 2>&1
  402.         }
  403.         cd $currdir
  404. # determine release, and AT or MCA bus - set rel and type variables accordingly.
  405. os_type() {
  406.         rel=`sed -n 's/^#rel=\(.*\).$/\1/p' /etc/perms/rts`
  407.         if [ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ]
  408.         then
  409.                 type=`sed -n 's/^#typ=\(.*\)$/\1/p' /etc/perms/inst`
  410.         else
  411.                 # 3.2.4 - one release supports AT, MCA, and EISA.
  412.                 uname -X | grep "BusType = MCA" >/dev/null 2>&1
  413.                 if [ $? -eq 0 ]
  414.                 then
  415.                         type=386MC
  416.                 else
  417.                         type=386GT
  418.                 fi
  419.         fi
  420. create_scripts()
  421.         if [ $bd -ne $MAX_BD ]
  422.         then
  423.                 currdir=`pwd`
  424.                 netconfigdir=/usr/lib/netconfig
  425.                 cd $netconfigdir/info
  426.                 newboard=`expr $bd + 1`
  427.                 newfile=${drv}${newboard}
  428.                 cp ${drv}0 $newfile
  429.                 sed -e '/^NAME=.*'"[^0]"'/s/0\"/'$newboard'\"/p' $newfile > /tmp/bog$$
  430.                 sed -e '/^DESCRIPTION=.*'"[^0]"'/s/0\"/'$newboard'\"/p' /tmp/bog$$ > $newfile
  431.                 rm -r /tmp/bog$$
  432.                 chown bin $newfile
  433.                 chgrp bin $newfile
  434.                 chmod 750 $newfile
  435.                 cd $netconfigdir/init
  436.                 ln $base ${drv}`expr $bd + 1` > /dev/null 2>&1
  437.                 cd $netconfigdir/remove
  438.                 ln $base ${drv}`expr $bd + 1` > /dev/null 2>&1
  439.                 cd $currdir
  440.         fi
  441. # main()
  442. # get the name of the init script being run, since one script
  443. # is used for multiple drivers; get the number at the end of the
  444. # script's name
  445. if [ $# -gt 1 ]
  446.         name_below=$1; if_below=$2
  447.         name_above=$3; if_above=$4
  448.         configure=$5
  449. base=`basename $0`
  450. drv=`echo $base | sed -e 's/[0-9]*$//`
  451. bd=`expr $base : '.*\(.\)'`
  452. chains=/usr/lib/lli/chains
  453. chain=$base:$name_above
  454. confdir=/etc/conf/cf.d
  455. makedevs
  456. check_args $drv $bd
  457. # Check and manage our internal chains file.
  458. # This file allows coexistent mkdev and netconfig calls.
  459. # chain already installed
  460. grep $chain $chains > /dev/null 2>& 1 && {
  461.         echo $chain >> $chains
  462.         cleanup $OK
  463. # this board already installed
  464. grep $base: $chains > /dev/null 2>& 1 && {
  465.         echo $base already configured.
  466.         echo $chain >> $chains
  467.         [ "$drv" = "tok" -a "$name_above" = "nbe" ] && {
  468.                 space_token
  469.         }
  470.         echo "NODE=/etc/conf/node.d/$base" >/tmp/$base.src
  471.         chmod 777 /tmp/$base.src
  472.         cleanup $OK
  473. # Now check that if we are not board zero that board zero is installed
  474. [ "$bd" -ne "0" ] && {
  475.         grep ${drv}0 $chains > /dev/null 2>& 1 || {
  476.                 echo "${drv}0 not configured, you must configure it first"
  477.                 cleanup $FAIL
  478.         }
  479. # check to see if the driver is already in the kernel link-kit so we can
  480. # either add it or update it later on
  481. idcheck -p $base -i /tmp/dev$$
  482. if [ $? -gt 16 ]
  483.         installed="TRUE"
  484.         installed="FALSE"
  485. if [ "$bd" = "0" ]
  486.         echo "Installing the $drv driver into the link kit"
  487.         cd /usr/lib/lli/$drv
  488.         if [ "$installed" = "TRUE" ]
  489.         then
  490.                 idinstall -u -e -k $base
  491.         else
  492.                 idinstall -a -e -k $base
  493.         fi
  494.         makedevs
  495.         idcheck -p ${drv}0 -i /tmp/dev$$
  496.         if [ $? -le 16 ]
  497.         then
  498.                 echo "${drv}0 must be configured before attempting to configure $drv"
  499.                 cleanup 1
  500.         fi
  501. # create the temporary directory for installing the driver
  502. cd /tmp; rm -rf $base
  503. mkdir $base; cd $base
  504. DMACHAN="-1"
  505. # set rel, type variables.
  506. os_type
  507. # Do special board dependent processing
  508. system_$drv $bd
  509. if [ "$IRQ" = "2" ]
  510.         IRQ=9
  511. echo "$base\tY\t4\t5\t0\t0\t0\t0\t0\t0" >./System
  512. # All the drivers support more than one board.  In fact all the code to
  513. # support all the boards is in the Driver.o for the board for the 1st board
  514. # (eg the e3A0 driver acually contains enough code for the e3A1, e3A2 & e3A3
  515. # boards).  As we need a Driver.o to be associated with 2nd, 3rd or 4th board
  516. # we install a dummy Driver.o, and a Master and Node which will actually cause
  517. # calls into the base driver.
  518. if [ $bd -gt 0 ]
  519.         echo "$base     -       iScH    $PREFIX$bd      0       0       1       256     $DMACHAN" >./Master
  520.         echo "clone     $base   c       $base" >./Node
  521.         if [ "$installed" = "TRUE" ]
  522.         then
  523.                 idinstall -u -m -s -n -e -k $base
  524.         else
  525.                 cp $LIB/Driver.o .
  526.                 idinstall -a -e -k $base
  527.         fi
  528.         echo "$base     I       iScH    $PREFIX 0       0       1       256     $DMACHAN" >./Master
  529.         idinstall -u -m -s -e -k $base
  530. # we successfully installed this driver, add it to the chains file
  531. echo $chain >> $chains
  532. # create next set of info, init, and remove files
  533. create_scripts
  534. # delete any potential BASE I/O address conflicts with the sio driver
  535. [ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ] && sio_conflict
  536. echo "NODE=/etc/conf/node.d/$base" >/tmp/$base.src
  537. chmod 777 /tmp/$base.src
  538. cleanup $RELINK
  539.