home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Network / LinkSYS / lne2000.exe / SCOUNIX / REMOVE < prev    next >
Text File  |  1995-08-09  |  9KB  |  314 lines

  1. :
  2. #               (C) 1989-1990 The Santa Cruz Operation, Inc.  All Rights
  3. #               Reserved.  The user has unlimited right to use, modify
  4. #               and incorporate this code into other products provided
  5. #               it is used with SCO products and the user includes
  6. #               this notice and the associated copyright notices with
  7. #               any such application.
  8. # This is a script for removing an LLI driver using netconfig
  9. #
  10. # The name it is called with will cause different operation.
  11. # e3A0 e3A1 e3A2 e3A3           == 3Com501 boards 0 - 3
  12. # e3B0 .....     e3B3           == 3Com503 boards 0 - 3
  13. # e3C0 .....     e3C3           == 3Com523 boards 0 - 3
  14. # wdn0 .....     wdn3           == Western Digital boards 0 - 3
  15. # d22e0.....     d22e3          == D-Link DE-220 boards 0 - 3
  16. # tok0 tok1                     == Token Ring Adapter 0, 1
  17. LIB=/usr/lib/lli
  18. CONF=/etc/conf
  19. PATH=/bin:/usr/bin:/etc/:$CONF/bin:$LIB
  20. #
  21. # Set possible return codes for this script
  22. #
  23. OK=0;   FAIL=1; RELINK=2; DRIVERINUSE=3;
  24.  
  25. #
  26. # prompt the user to answer a yes no question or 'q' to quit
  27. # Usage:
  28. #       prompt_yn "Message" default
  29. prompt_yn() {
  30.         mesg=$1
  31.         default=$2
  32.  
  33.         while :
  34.         do
  35.                 echo "${mesg} (y/n) [${default}] : \c"
  36.                 read result
  37.  
  38.                 case $result in
  39.                 y|Y) result="Y"; return $OK;;
  40.                 n|N) result="N"; return $OK;;
  41.                 "") result=`echo $default | tr "yn" "YN"`; return $OK;;
  42.                 esac
  43.  
  44.                 echo "Illegal value, please type 'y' 'n' or 'q'"
  45.         done
  46. }
  47.  
  48. #
  49. # Fake up an mdevice and an sdevice for idcheck
  50. #
  51. makedevs() {
  52.         rm -fr /tmp/dev$$
  53.         mkdir /tmp/dev$$
  54.         cd /etc/conf/cf.d
  55.         cp mdevice /tmp/dev$$
  56.         cd ../sdevice.d
  57.         cat * > /tmp/dev$$/sdevice
  58. }
  59.  
  60. # cleanup removes stuff and exits - if $1 = $DRIVERINUSE, exits value is $2
  61. cleanup() {
  62.         tmp=$1
  63.  
  64.         if [ $tmp -ne $DRIVERINUSE ]
  65.         then
  66.                 # disallow configuring greater than board zero
  67.                 netconfigdir=/usr/lib/netconfig
  68.                 nextbd=`expr $bd + 1`
  69.                 rm ${netconfigdir}/info/${drv}${nextbd} > /dev/null 2>&1
  70.                 rm ${netconfigdir}/init/${drv}${nextbd} > /dev/null 2>&1
  71.                 rm ${netconfigdir}/remove/${drv}${nextbd} > /dev/null 2>&1
  72.         else
  73.                 tmp=$2
  74.         fi
  75.         cd /
  76.         rm -fr /tmp/dev$$
  77.         rm -fr /tmp/$base
  78.         exit $tmp
  79. }
  80.  
  81. system_e3A() {
  82.         # decrement the 2k block buffers for cleanliness
  83.         awk '/^NBLK2048/ {
  84.                 OLD=$2-8
  85.                 printf "%s\t%s\n",$1,OLD
  86.                 next
  87.         }
  88.         { print } ' < /etc/conf/cf.d/stune > /tmp/bog$$
  89.         mv /tmp/bog$$ /etc/conf/cf.d/stune
  90. }
  91.  
  92. #
  93. # function to remove address conflicts in the sio driver
  94. #
  95. sio_conflict() {
  96.         currdir=`pwd`
  97.         cd /etc/conf/pack.d/sio
  98.         if [ "$BIO" != "0" ]
  99.         then
  100.                 grep "/* LLI {.*$BIO" space.c > /dev/null && {
  101.                         echo "Restoring serial cards using base address 0x$BIO into link kit..."
  102.                         sed -e /"LLI.*$BIO,/s/^\/\* LLI //" space.c >/tmp/bog$$
  103.                         if [ "$base" = "tok0" ]
  104.                         then
  105.                                 sed -e /"ibm COM3/s/^\/\* LLI //" /tmp/bog$$ >/tmp/foo$$
  106.                                 mv /tmp/foo$$ /tmp/bog$$
  107.                         fi
  108.                         mv /tmp/bog$$ space.c
  109.                 }
  110.         fi
  111.         cd $currdir
  112. }
  113.  
  114. #
  115. # function to produce the information for the System file for the token ring
  116. #
  117. # if tcp is installed we remove the board from /etc/tcp and /etc/strcf
  118. #
  119. cleantcp() {
  120.         driver=$1
  121.  
  122.         [ -f /etc/tcp ] && {
  123.                 sed "/$driver/d" /etc/tcp > /tmp/bog$$
  124.                 cp /tmp/bog$$ /etc/tcp
  125.         }
  126.         [ -f /etc/strcf ] && {
  127.                 sed "/$driver/d" /etc/strcf > /tmp/bog$$
  128.                 cp /tmp/bog$$ /etc/strcf
  129.         }
  130.         rm -f /tmp/bog$$
  131. }
  132.  
  133. # restorevector check for sio (vecs 3-4) and pa drivers (vec 7)
  134. # if these are being released by lli then let us restore them to sio or pa
  135. restorevector() {
  136.         currdir=`pwd`
  137.         cd /etc/conf/cf.d
  138.  
  139.         intvector=$1
  140.         test="0"
  141.         [ "$intvector" = "3" ] && test="1"
  142.         [ "$intvector" = "4" ] && test="1"
  143.         if [ "$test" = "1" ]
  144.         then
  145.                 prompt_yn "Restore vector $intvector to sio driver" y
  146.                 [ "$result" = "Y" ] && {
  147.                         echo "Restoring vector $intvector to sio driver"
  148.                         siomajor=`./configure -j sio`
  149.                         ./configure -m $siomajor -c -v $intvector -a -Y
  150.                         return $OK
  151.                 }
  152.         fi
  153.         test="0"
  154.         [ "$intvector" = "7" ] && test="1"
  155.         if [ "$test" = "1" ]
  156.         then
  157.                 prompt_yn "Restore vector $intvector to pa driver" y
  158.                 [ "$result" = "Y" ] && {
  159.                         echo "Restoring vector $intvector to pa driver"
  160.                         pamajor=`./configure -j pa`
  161.                         ./configure -m $pamajor -c -v $intvector -a -Y
  162.                         return $OK
  163.                 }
  164.         fi
  165.         return $OK
  166. }
  167.  
  168. # main()
  169. #
  170.  
  171. #
  172. # get the name of the init script being run, since one script
  173. # is used for multiple drivers; get the number at the end of the
  174. # script's name
  175. #
  176. if [ $# -gt 1 ]
  177. then
  178.         name_below=$1; if_below=$2
  179.         name_above=$3; if_above=$4
  180. fi
  181.  
  182. base=`basename $0`
  183.  
  184. drv=`echo $base | sed -e 's/[0-9]*$//`
  185. bd=`expr $base : '.*\(.\)'`
  186. case $drv in
  187. e3A) PREFIX="e3c";;
  188. e3B) PREFIX="e503";;
  189. e3C) PREFIX="emc";;
  190. e3D) PREFIX="e3d";;
  191. wdn) PREFIX="wdn";;
  192. wdt) PREFIX="wdt";;
  193. son) PREFIX="son";;
  194. d22e) PREFIX="d22e";;
  195. d51e) PREFIX="d51e";;
  196. nat) PREFIX="nat";;
  197. tok) PREFIX="tok";;
  198. exos) PREFIX="exos";;
  199. hpi) PREFIX="hpi";;
  200. hpe) PREFIX="hpe";;
  201. i3B) PREFIX="i3B";;
  202. i6E) PREFIX="i6E";;
  203. *) echo "ERROR: Unknown LLI driver being configured ($name$bd)";
  204.         cleanup $FAIL;
  205.         ;;
  206. esac
  207.  
  208. echo "NODE=/etc/conf/node.d/$base" >/tmp/$base.src
  209. chmod 777 /tmp/$base.src
  210.  
  211. #
  212. # check to see if the driver is already in the kernel link-kit so we can
  213. # either add it or update it later on
  214. #
  215. makedevs
  216. idcheck -p $base
  217. if [ $? -gt 16 ]
  218. then
  219.         installed="TRUE"
  220. else
  221.         installed="FALSE"
  222. fi
  223.  
  224. if [ "$installed" = "FALSE" ]
  225. then
  226.         cleanup $OK
  227. fi
  228.  
  229. #
  230. # Check and Manage our internal chains file.
  231. #
  232. # if our board (base) is not in the chain then we always remove the board
  233. # if our board is in the chain then we check for the chain and remove it.
  234. # if after our chain is removed from the chains file the board is still there
  235. #    then we do not remove it.
  236. #
  237. chains=/usr/lib/lli/chains
  238. chain=$base:$name_above
  239. if grep $base: $chains > /dev/null 2>& 1
  240. then
  241.         grep $chain $chains > /dev/null 2>& 1 || {
  242.                 cleanup $OK
  243.         }
  244.         # remove our chain
  245.         awk '{
  246.                 if ($1 == CHAIN && found != 1) {
  247.                         found = 1
  248.                         next
  249.                 }
  250.                 print $0
  251.         }' CHAIN=$chain < $chains > /tmp/bog$$
  252.         cp /tmp/bog$$ $chains
  253.         rm -f /tmp/bog$$
  254.         # Check if it is there in another chain
  255.         grep $base: $chains > /dev/null 2>& 1 && {
  256.                 cleanup $DRIVERINUSE $OK
  257.         }
  258. else
  259.         cleanup $OK
  260. fi
  261.  
  262. echo "Removing $base..."
  263.  
  264. # Check if we are board zero that no other boards of this type are configured
  265. [ "$bd" -eq "0" ] && {
  266.         grep ${drv}[1-3] $chains > /dev/null 2>& 1 && {
  267.                 echo "Warning, You are removing board 0 before other boards"
  268.                 echo "You must remove the other $drv boards next"
  269.                 echo "or your link-kit will be left in an invalid state"
  270.         }
  271. }
  272.  
  273. #
  274. # Do board dependent processing
  275. #
  276. case $drv in
  277.         e3A)    system_e3A $bd;;
  278. esac
  279.  
  280. #if [ $bd -gt 0 ]
  281. #then
  282. #       idinstall -d -e $base
  283. #       cleanup $RELINK
  284. #fi
  285.  
  286. # get the interrupt vector for the board that we are removing
  287. cd /etc/conf/sdevice.d
  288. ivec=`awk '{ if ( $1 != "*" ) print $6 }' < $base`
  289. BIO=`awk '{ if ( $1 != "*" ) print $7 }' < $base`
  290.  
  291. cd /tmp; rm -rf $base
  292.  
  293. mkdir $base; cd $base
  294.  
  295. echo "${base}\tN\t1\t5\t1\t9\t0\t0\t0\t0" >System
  296. if [ $bd -gt 0 ]
  297. then
  298.         echo "$base     -       iScH    $PREFIX$bd      0       0       1       256     -1" >./Master
  299. else
  300.         cp $LIB/${drv}/Master ./Master
  301. fi
  302. idinstall -u -e -s -m $base
  303.  
  304. # restore sio space.c file
  305. sio_conflict
  306.  
  307. cleantcp $base
  308. restorevector $ivec
  309. # Check to see if driver for next board is configured
  310. grep ${drv}`expr ${bd} + 1`: $chains > /dev/null 2>& 1 && {
  311.         cleanup $DRIVERINUSE $RELINK
  312. }
  313. cleanup $RELINK
  314.