home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / nics / install / postinstall < prev    next >
Text File  |  1998-08-19  |  11KB  |  407 lines

  1. #!/usr/bin/xksh
  2. #ident    "@(#)postinstall    29.2"
  3. #ident    "$Header: $"
  4.  
  5. # do not use apostrophes in middle of script (even in comments)
  6. # as parser can not grok them properly
  7.  
  8. # we need to be able to source in bcfg files.  unfortunately, pkgadd/pkginstall
  9. # runs us as a Bourne shell, and .bcfgs use arrays, so we must switch to Korn
  10. # /bin/ksh has hard links to sh in the ISL case so use winxksh
  11. [ "$RANDOM" = "$RANDOM" ] && {
  12.     exec /usr/bin/xksh $0
  13. }
  14.  
  15. # running under ksh now.  save all of stderr - just in case
  16. # since we run script multiple times (3 possible phases) add pid to name
  17. # so we do not overwrite earlier copies
  18. exec 2>/var/adm/log/nics.postinstall.err.$$
  19.  
  20. # turn on debugging information - just in case
  21. # set -x
  22.  
  23. # function to idinstall any DEPEND= drivers from the .bcfg file to
  24. # the link kit.  one of them could be $static so we must do this early
  25. # to prevent a second relink later on.
  26. do_depends()
  27. {
  28.  
  29.     # if not set then return
  30.     [ "$DEPEND" = "" ] && return 0
  31.     if [ "$NICS_TYPE" = "MDI" ]
  32.     then
  33.         LOCATION=/etc/inst/nd/mdi
  34.     else
  35.         LOCATION=/etc/inst/nics/drivers
  36.     fi
  37.  
  38. OIFS=$IFS
  39. IFS=""
  40.     echo "$DEPEND"  | while read line
  41.     do
  42.         [ "$line" = "" ] && continue
  43.         cd $LOCATION/$DEPEND
  44.         /etc/conf/bin/idinstall -P nics -d ${line} > /dev/null 2>&1
  45.         # this next line may produce an error about /dev/volprivate
  46.         # not found but the idinstall still appears to work
  47.         /etc/conf/bin/idinstall -P nics -k -a ${line}
  48.     done
  49.  
  50. IFS=$OIFS
  51.     return 0
  52. }
  53.  
  54.  
  55. # function to add $static to the odimem System file.  assumes we are in the
  56. # right directory already.
  57.  
  58. edit_odimem_system()
  59. {
  60.  
  61. ed -s System <<! >/dev/null
  62. /^odimem
  63. i
  64. \$static
  65. .
  66. w
  67. q
  68. !
  69.  
  70. }
  71.  
  72.  
  73. do_dlpimdi_mods()
  74. {
  75.  
  76.     for MOD_NAME in $DLPI_MODS
  77.     do
  78.         [ ! -f /etc/conf/mdevice.d/${MOD_NAME} ] && {
  79.             cd /etc/inst/nd/${MOD_NAME}
  80.             /etc/conf/bin/idinstall -P nics -d ${MOD_NAME} > /dev/null 2>&1
  81.             # this next line may produce an error about 
  82.             # /dev/volprivate not found but the idinstall still
  83.             # appears to work.  error only occurs when routine is
  84.             # called in the ISL pre-reboot phase
  85.             /etc/conf/bin/idinstall -P nics -k -a ${MOD_NAME}
  86.             DLPI_BLD="${DLPI_BLD} -M ${MOD_NAME}"
  87.         }
  88.     done
  89.  
  90. }
  91.  
  92.  
  93. # function to remove $depend odimem from the lsl System file
  94. edit_lsl_master()
  95. {
  96.  
  97.  
  98. ed -s Master <<! >/dev/null
  99. /^\$depend odimem
  100. d
  101. w
  102. q
  103. !
  104.  
  105. }
  106.  
  107. # function to add the NETCFG role to the TFM database
  108. # and add commands to that role
  109. postinstaddrole()
  110. {
  111.     /bin/adminrole NETCFG > /dev/null
  112.     if [ $? -ne 0 ]
  113.     then
  114.             /bin/adminrole -n NETCFG
  115.     fi
  116.     /bin/adminrole -r ndcfg NETCFG 2> /dev/null
  117.     /bin/adminrole -a ndcfg:/usr/sbin/ndcfg:owner:dacread:dacwrite:loadmod:setflevel:filesys NETCFG
  118.     /bin/adminrole -r nd NETCFG 2> /dev/null
  119.     /bin/adminrole -a nd:/etc/nd:owner:dacread:dacwrite:loadmod:setflevel:filesys NETCFG
  120.     /bin/adminrole -r mv NETCFG 2> /dev/null
  121.     /bin/adminrole -a mv:/bin/mv:owner:dacwrite NETCFG
  122.     /bin/adminrole -r rm NETCFG 2> /dev/null
  123.     /bin/adminrole -a rm:/bin/rm:owner:dacwrite NETCFG
  124.  
  125. }
  126.  
  127. # main MAIN Main
  128.  
  129. DLPI_BLD=""
  130. IDTUNE=/etc/conf/bin/idtune
  131. # DEBUG=/bin/echo
  132. DEBUG=/bin/true
  133. # Add Netcfg to SCOAdmin
  134. NCFG_DIR=/usr/lib/netcfg
  135. [ -f /usr/bin/scoadmin ] && [ -d $NCFG_DIR/netcfg.obj ] && {
  136. /usr/bin/scoadmin -p Networking -f -c $NCFG_DIR/netcfg.obj
  137. }
  138.  
  139. ODI_MODS="msm ethtsm toktsm fdditsm odisr"
  140. DLPI_MODS="dlpi dlpibase"
  141.  
  142. # 3 possible cases we need to handle:
  143. # a) isl case, pre relink/reboot - do idinstall, idtunes, etc.
  144. #    check for /etc/inst/scripts/postreboot.sh (even though we have not 
  145. #    rebooted !)
  146. #    this way kernel stune files will be set appropriately so that when we
  147. #    actually do the idinstall of the driver with ndcfg in step b) below
  148. #    we will not be changing their values, making a *second* relink unnecessary.
  149. # b) isl case, post reboot - silently add network card to system
  150. #    check for /etc/rc2.d/S02POSTINST (renamed from postreboot.sh immediately
  151. #    prior to actual reboot).   does the echo idinstall | ndcfg
  152. # c) post isl pkgadd case - ensure odimem static, no idtunes.
  153. #    if above two checks do not make it.
  154.  
  155. if [ -f /etc/inst/scripts/postreboot.sh ]
  156. then
  157.  
  158.     # *******************ISL CASE, PRE RELINK/REBOOT.   CASE A) ABOVE
  159.  
  160.     $DEBUG "ISL CASE, PRE RELINK/REBOOT" 1>&2
  161.  
  162.     . /isl/ifile
  163.     
  164.     # if no .bcfg file set, user did not select a network card at ISL time 
  165.     # nothing for us to do - return immediately
  166.     [ "$NICS_CONFIG_FILE" = "" ] && exit 0
  167.     [ "$NICS_DRIVER_NAME" = "" ] && exit 0
  168.  
  169.     if [ "$NICS_TYPE" = "" ]
  170.     then
  171.         echo "NICS_TYPE variable is not set"
  172.         exit 1
  173.     fi
  174.  
  175.     if [ "$NICS_TYPE" = "MDI" ] 
  176.     then
  177.         . /etc/inst/nd/mdi/$NICS_DRIVER_NAME/$NICS_CONFIG_FILE
  178.     elif [ "$NICS_TYPE" = "ODI" -o "$NICS_TYPE" = "DLPI" ]
  179.     then
  180.         . /etc/inst/nics/drivers/$NICS_DRIVER_NAME/${NICS_CONFIG_FILE}.bcfg
  181.     else
  182.         echo "Unknown driver type $NICS_TYPE"
  183.         exit 1
  184.     fi
  185.  
  186.  
  187.     # if .bcfg file has any IDTUNE lines, do them now
  188.     [ -n "$IDTUNE_NUM" ] && {
  189. OIFS=$IFS
  190. IFS="
  191. "
  192.         integer i=1
  193.         while (( i <= $IDTUNE_NUM ))
  194.         do
  195.             $IDTUNE -f ${IDTUNE_ARRAY[i]}
  196.             let i+=1
  197.         done
  198. IFS=$OIFS
  199.     }
  200.  
  201.     # put odimem into the link kit if it is not already there 
  202.     # (it will not be there since isl case)
  203.     [ ! -f /etc/conf/mdevice.d/odimem ] && {
  204.  
  205.         cd /etc/inst/nics/drivers/odimem
  206.  
  207.         edit_odimem_system
  208.  
  209.         # remove any previous installed version in case it exists
  210.         /etc/conf/bin/idinstall -P nics -d odimem > /dev/null 2>&1
  211.  
  212.         # add the new version from this directory.  This may produce
  213.         # an error about /dev/volprivate not found but idinstall still
  214.         # appears to work - BL14 let ndcfg do this, no ODI drivers needing odimem
  215.         # and odimem hogs RAM while in the system - N
  216.         # /etc/conf/bin/idinstall -P nics -k -a odimem
  217.  
  218.     }
  219.  
  220.     # no need to do idtune for ODIMEM_MBLK_NUMBUF/ODIMEM_NUMBUF as
  221.     # odimem Mtune file defaults to 1.  if you ever need to do this borrow
  222.     # the routine do_odimem from niccfg and insert it here.
  223.     # it is also possible that:
  224.     # ODIMEM never set in .bcfg file
  225.     # driver type is DLPI or MDI, not using odimem at all
  226.     # key off of $NICS_TYPE before you do any of this anyway
  227.  
  228.     cd /etc/inst/nics/drivers/lsl
  229.  
  230.     edit_lsl_master
  231.  
  232.     # install dlpi and dlpibase into link kit
  233.     do_dlpimdi_mods
  234.  
  235.     # if .bcfg has any DEPEND= drivers, they could be $static, so
  236.     # idinstall them too since they will be needed later on.  note that
  237.     # ndcfg is smart and will not re-idinstall a DEPEND= driver if it         # already exists in the link kit(ndcfg calls idcheck -y)
  238.     do_depends
  239.  
  240.     # tell system that we should relink kernel later on.  This
  241.     # should happen anyway after invoking this script since we have not
  242.     # done the final relink
  243.  
  244.     /etc/conf/bin/idbuild >/dev/null 2>&1
  245.  
  246.     exit 0
  247.  
  248. elif [ -f /etc/rc2.d/S02POSTINST ]
  249. then
  250.  
  251.     # *******************ISL CASE, POST RELINK/REBOOT.   CASE B) ABOVE
  252.  
  253.     $DEBUG "ISL CASE, POST RELINK/REBOOT" 1>&2
  254.  
  255.     . /isl/ifile
  256.     
  257.     # if no .bcfg file set, user did not select a network card at ISL 
  258.     # time - only install dlpi/dlpibase drivers
  259.     if [ "$NICS_CONFIG_FILE" = "" -o "$NICS_DRIVER_NAME" = "" ]
  260.     then
  261.         do_dlpimdi_mods
  262.         [ "${DLPI_BLD}" ] && /etc/conf/bin/idbuild ${DLPI_BLD} > /dev/null 2>&1
  263.         postinstaddrole
  264.         exit 0
  265.     fi
  266.     if [ "$NICS_TYPE" = "" ]
  267.     then
  268.         echo "NICS_TYPE variable is not set"
  269.         exit 1
  270.     fi
  271.  
  272.     if [ "$NICS_TYPE" = "MDI" ] 
  273.     then
  274.         . /etc/inst/nd/mdi/$NICS_DRIVER_NAME/$NICS_CONFIG_FILE
  275.         location=/etc/inst/nd/mdi/$NICS_DRIVER_NAME/$NICS_CONFIG_FILE
  276.     elif [ "$NICS_TYPE" = "ODI" -o "$NICS_TYPE" = "DLPI" ]
  277.     then
  278.         . /etc/inst/nics/drivers/$NICS_DRIVER_NAME/${NICS_CONFIG_FILE}.bcfg
  279.         location=/etc/inst/nics/drivers/$NICS_DRIVER_NAME/${NICS_CONFIG_FILE}.bcfg
  280.     else
  281.         echo "Unknown driver type $NICS_TYPE"
  282.         exit 1
  283.     fi
  284.  
  285.     # odimem already idinstalled, made static
  286.     # no need to do any idtunes for odimem here either
  287.     # any DEPEND= drivers already taken care of and in link kit.
  288.     # just need to issue the idinstall to put driver and any
  289.     # infrastructure drivers into link kit
  290.     
  291.     # get bcfg index number from path name.  ndcfg must load in all
  292.     # bcfg files in order to produce an index.  fortunately we are done
  293.     # loading .bcfg files so this index will not change in next call to
  294.     # ndcfg again below.
  295.     index=`echo bcfgpathtoindex $location | /usr/lib/netcfg/bin/ndcfg -a`
  296.  
  297.     if [ "$index" = "-1" ] 
  298.     then
  299.         # should not happen...
  300.         echo "ndcfg says unknown bcfg pathname $location"
  301.         exit 1
  302.     fi
  303.  
  304.     busstuff=""
  305.     # we cannot depend on NICS_KEY from the ifile any more as resmgr keys
  306.     # can get shuffled around from the reboot, so what was once the correct
  307.     # key is not any more.we figure out proper key by looking for the IICARD
  308.     # parameter in the resmgr which indicates this is the key we used
  309.     # for netinstall.  Note that we remove the key for netinstalls over
  310.     # ISA so it may not exist any more.
  311.     if [ "$BUS" != "ISA" ]
  312.     then
  313.         NICS_KEY=`echo iicard | /usr/lib/netcfg/bin/ndcfg -q`
  314.         # remove spaces
  315.         NICS_KEY=`echo $NICS_KEY`
  316.         if [ "$NICS_KEY" != "-1" ] 
  317.         then
  318.             busstuff="KEY=$NICS_KEY"
  319.         else
  320.             echo "ndcfg iicard ret NICS_KEY -1"
  321.             exit 1
  322.         fi
  323.     else
  324.         [ -n "$NICS_IO" ] && busstuff="$busstuff IOADDR=$NICS_IO"
  325.         [ -n "$NICS_RAM" ] && busstuff="$busstuff MEMADDR=$NICS_RAM"
  326.         [ -n "$NICS_IRQ" ] && busstuff="$busstuff IRQ=$NICS_IRQ"
  327.         [ -n "$NICS_DMA" ] && busstuff="$busstuff DMAC=$NICS_DMA"
  328.     fi
  329.  
  330.     # now do custom parameters
  331.     custom=""
  332.     if [ "$NICS_CUSTOM_NUM" != "" ] 
  333.     then
  334.         integer i=1
  335.  
  336.         while (( i <= $NICS_CUSTOM_NUM ))
  337.         do
  338.             # because bcfg might use __STRING__ freetext enclose
  339.             # custom parameters with braces just in case.
  340.             # CABLETYPE=1
  341.             custom="$custom ${NICS_CUST_PNAME[i]}={${NICS_CUST_VAL[i]}}"
  342.             # CABLETYPE_=Aui
  343.             custom="$custom ${NICS_CUST_PNAME[i]}_={${NICS_CUSTOM[i]}}"
  344.             let i+=1
  345.         done
  346.     fi
  347.     # now construct necessary idinstall line to pipe to ndcfg.  Note
  348.     # we do not support OLDIOADDR=xxx-yyy here and assume that the card
  349.     # is present at the I/O address the user supplies.
  350.     # likewise, we also do not support BINDCPU/UNIT/IPL/ITYPE here.
  351.     # Unfortunately, ndcfg must re-load all of its bcfgs again here...
  352.     # send stdout to stderr which is sent to /tmp/nics.postinstall.err
  353.  
  354.     # since we run script up to 3 times, add pid to log name output to save
  355.     # earlier copies
  356.     echo "IDINSTALL $index $NICS_TOPOLOGY 0 1 $busstuff $custom __CHARM=0" | /usr/lib/netcfg/bin/ndcfg -v -b -l /var/adm/log/ndcfg.log.$$ -j 1>&2
  357.  
  358.     # no need to run idbuild here, case A) above did the work and nothing
  359.     # will have changed to necessitate a kernel relink.
  360.     
  361.     # add NETCFG role and commands to TFM database
  362.     postinstaddrole
  363.  
  364.     exit 0
  365. else
  366.     # *******************NORMAL PKGADD CASE              CASE C) ABOVE
  367.  
  368.     $DEBUG "NORMAL PKGADD CASE" 1>&2
  369.  
  370.     # put odimem into the link kit if it is not already there
  371.     [ ! -f /etc/conf/mdevice.d/odimem ] && {
  372.  
  373.         cd /etc/inst/nics/drivers/odimem
  374.  
  375.         edit_odimem_system
  376.  
  377.         # remove any previous installed version in case it exists
  378.         /etc/conf/bin/idinstall -P nics -d odimem > /dev/null 2>&1
  379.  
  380.         # add the new version from this directory
  381.         # BL14 let ndcfg do this, no ODI drivers remaining needing odimem
  382.         # and odimem hogs RAM while in the system - N
  383.         # /etc/conf/bin/idinstall -P nics -k -a odimem
  384.  
  385.         # and tell kernel to rebuild later on
  386.         /etc/conf/bin/idbuild
  387.  
  388.     }
  389.  
  390.     cd /etc/inst/nics/drivers/lsl
  391.  
  392.     edit_lsl_master
  393.  
  394.     # install dlpi and dlpibase into link kit and ensure usable now.
  395.     do_dlpimdi_mods
  396.  
  397.     [ "${DLPI_BLD}" ] && /etc/conf/bin/idbuild ${DLPI_BLD} > /dev/null 2>&1
  398.  
  399.     # add NETCFG role and commands to TFM database
  400.     postinstaddrole
  401.     exit 0
  402. fi
  403.  
  404. # not reached...
  405. exit 1
  406.