home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / base / root.15 / usr / lib / hpnp / cfg / option3 / option3~
Text File  |  1998-08-19  |  10KB  |  345 lines

  1. #!/bin/ksh
  2. #ident    "@(#)option3    1.2"
  3. #        copyright    "%c%"
  4. #
  5. # (c)Copyright Hewlett-Packard Company 1991.  All Rights Reserved.
  6. # (c)Copyright 1983 Regents of the University of California
  7. # (c)Copyright 1988, 1989 by Carnegie Mellon University
  8. #                          RESTRICTED RIGHTS LEGEND
  9. # Use, duplication, or disclosure by the U.S. Government is subject to
  10. # restrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights in
  11. # Technical Data and Computer Software clause in DFARS 252.227-7013.
  12. #
  13. #                          Hewlett-Packard Company
  14. #                          3000 Hanover Street
  15. #                          Palo Alto, CA 94304 U.S.A.
  16. #
  17. #  Check operation of bootp by doing a bootpquery.
  18. #
  19.  
  20. # begin UnixWare value added
  21. if [ $OS = "UnixWare" ]
  22. then
  23.     echo "\n\nBootpquery is not supported under the UnixWare."
  24.     echo "The option you have is to use is the -d option to bootpd,"
  25.     echo "running it in standalone mode from the command line."
  26.     echo "See the bootpd manual page for more information.\n"
  27.       echo "Press the return key to return to the main menu ... $NL"
  28.       read -r RESP
  29.       exit 1
  30. fi
  31.  
  32. ACTIVEHWADDR=$1
  33. HATAG=080009000000
  34.  
  35. if grep "^bootps" /etc/inetd.conf > /dev/null 2>&1
  36. then
  37.   :
  38. else
  39.   echo ""
  40.   echo "\"bootps\" service not found in /etc/inetd.conf"
  41.   echo ""
  42. # begin UnixWare value added
  43.   case $OS in
  44.      sunx)
  45.         echo "Configure inetd to support the bootps service if /usr/etc/bootpd"
  46.      ;;
  47.      hp)
  48.          echo "Configure inetd to support the bootps service if /etc/bootpd"
  49.      ;;
  50.      UnixWare|sco)
  51.          echo "Configure inetd to support the bootps service if /etc/bootpd"
  52.      ;;
  53.    esac
  54. # end UnixWare value added
  55.   echo "exists or install the HP Network Peripheral Interface software again"
  56.   echo "to acquire the BOOTP software."
  57.   echo "\nPress the return key to return to the main menu ... $NL"
  58.   read -r RESP
  59.   exit 1
  60. fi
  61.  
  62. if [ ! -f "$BOOTPQUERY" ] 
  63. then
  64.   echo "\n$BOOTPQUERY does not exist.\n"
  65.   echo "Press the return key to continue ... $NL"
  66.   read -r RESP
  67.   exit 1
  68. fi
  69.  
  70. RMHATAG=0
  71. grep -i $HATAG $BOOTPTABLE > /dev/null 2>&1
  72. if [ $? -ne 0 ]
  73. then
  74.   RMHATAG=1
  75.   #    Add a dummy entry with hw address HATAG.
  76.   echo "" >> $LOG
  77.   echo "Adding a dummy entry to $BOOTPTABLE" >> $LOG
  78.   echo "" >> $LOG
  79.   echo "echo \"a$HATAG:\\\" >> $BOOTPTABLE" >> $LOG
  80.   echo "a$HATAG:\\" >> $BOOTPTABLE
  81.   echo "echo \"    :ht=ether:\\\" >> $BOOTPTABLE" >> $LOG
  82.   echo "    :ht=ether:\\" >> $BOOTPTABLE
  83.   echo "echo \"    :ba:\\\" >> $BOOTPTABLE" >> $LOG
  84.   echo "    :ba:\\" >> $BOOTPTABLE
  85.   echo "echo \"    :ha=$HATAG\" >> $BOOTPTABLE" >> $LOG
  86.   echo "    :ha=$HATAG" >> $BOOTPTABLE
  87. fi
  88.    
  89. echo ""
  90. echo "=================================================================="
  91. echo "Testing BOOTP by looking up a predefined entry ... $NL"
  92. $BOOTPQUERY "$HATAG" -s "$HOSTNAME" > "$TMP/bootreply"  2>&1
  93. echo ""
  94. echo ""
  95. grep 'Received BOOTREPLY' "$TMP/bootreply" > /dev/null 2>&1
  96. RETCODE=$?
  97. rm $TMP/bootreply
  98. DOEXIT=0
  99. case $RETCODE in
  100.   0)
  101.     echo "BOOTP responded.  The BOOTP service is operational."
  102.     echo "=================================================================="
  103.     rmbootpentry "a$HATAG" > /dev/null
  104.     ;;
  105.   *)
  106.     echo "BOOTP did not respond."
  107.     echo ""
  108.     echo "Check that bootpd is in /etc/inetd.conf."
  109.     echo "Check that bootps and bootpc are in /etc/services."
  110.     echo "Check for error messages from bootpd in your syslog file."
  111.     echo "=================================================================="
  112.     DOEXIT=1
  113. esac
  114. if [ $RMHATAG -eq 1 ]
  115. then
  116.   rmbootpentry "a$HATAG" > /dev/null
  117. fi
  118. if [ $DOEXIT -eq 1 ]
  119. then
  120.   echo "\nPress the return key to continue ... $NL"
  121.   read -r RESP
  122.   exit 1
  123. fi
  124.  
  125. while [ 0 ]
  126. do
  127.   getbootpha  "$ACTIVEHWADDR"
  128.  
  129.   if [ $? != 0 ]
  130.   then
  131.     exit 1
  132.   fi
  133.  
  134.   HATAG="`cat -- $TMP/UHATAG`"
  135.   rm -- "$TMP/UHATAG"
  136.  
  137.   grep -i -- "$HATAG"  "$BOOTPTABLE" > /dev/null 2>&1
  138.   if [ $? -ne 0 ]
  139.   then
  140.     echo "\nThere is no entry with hardware address $HATAG in"
  141.     echo "$BOOTPTABLE on $HOSTNAME."
  142.   else
  143.     break
  144.   fi
  145. done
  146.  
  147. #
  148. # Add "ba" tag so bootpquery sees the response
  149. #
  150. echo "" >> $LOG
  151. echo "Add \"ba\" tag so bootpquery sees the response" >> $LOG
  152. echo "" >> $LOG
  153. echo cp $BOOTPTABLE  $TMP/TMPBOOTPTAB >> $LOG
  154. cp -- "$BOOTPTABLE"  "$TMP/TMPBOOTPTAB"
  155. echo sed -e 's/'$HATAG'/'$HATAG':ba/' $BOOTPTABLE \>$TMP/BOOTPTAB >> $LOG
  156. sed -e 's/'$HATAG'/'$HATAG':ba/' "$BOOTPTABLE" > "$TMP/BOOTPTAB"
  157. echo cp   $TMP/BOOTPTAB $BOOTPTABLE >> $LOG
  158. cp   -- "$TMP/BOOTPTAB" "$BOOTPTABLE"
  159. rm -f -- "$TMP/BOOTPTAB"
  160.  
  161. echo ""
  162. echo "=================================================================="
  163. $ECHO "Testing BOOTP response to hardware address $HATAG ...$NL"
  164. $BOOTPQUERY $HATAG -s $HOSTNAME > $TMP/BOOTPRSP  2>&1
  165. echo ""
  166. echo ""
  167. cat --  "$TMP/BOOTPRSP" | awk -f -- "$HPNP/cfg/bootp.awk" > "$TMP/BOOTPRSP2" 2>&1
  168. grep 'Received BOOTREPLY' "$TMP/BOOTPRSP" > /dev/null 2>&1
  169. RETCODE=$?
  170.  
  171. #
  172. # Restore table without "ba" tag.
  173. #
  174. echo "" >> $LOG
  175. echo "Restore /etc/bootptab without \"ba\" tag" >> $LOG
  176. echo "" >> $LOG
  177. echo cp $TMP/TMPBOOTPTAB $BOOTPTABLE >> $LOG
  178. cp -- "$TMP/TMPBOOTPTAB" "$BOOTPTABLE"
  179. rm -f -- "$TMP/TMPBOOTPTAB"
  180.  
  181. case $RETCODE in
  182.   0)
  183.     echo "The BOOTP daemon responded to the BOOTP request sent"
  184.     echo "by \"$HOSTNAME\" and should respond to the BOOTP request"
  185.     echo "sent by your peripheral when it is powered on."
  186.     echo "=================================================================="
  187.     ;;
  188.   *)
  189.     echo "BOOTP did not respond."
  190.     echo ""
  191.     echo "Check for error messages from bootpd in your syslog file."
  192.     echo "=================================================================="
  193.     rm -- "$TMP/BOOTPRSP"
  194.     rm -- "$TMP/BOOTPRSP2"
  195.     echo "\nPress the return key to continue ... $NL"
  196.     read -r RESP
  197.     exit 1
  198.     ;;
  199. esac
  200.  
  201. #  check if a config is defined for the bootp entry on host
  202. FNAME=`cat $TMP/BOOTPRSP2 | awk '/Configuration File:/ {print $3}'`
  203.  
  204. while [ 0 ]
  205. do
  206.   echo "\nDo you want to see the BOOTP response"
  207.   echo "to check that it is correct?  (y/n/q default=y) $NL"
  208.   read -r RESP
  209.   if [ -z "$RESP" -o "$RESP" = 'y' ]
  210.   then
  211.     if [ -n "$FNAME" ]
  212.     then
  213.       echo "\nNote: Some configuration data is in the network peripheral"
  214.       echo "      interface configuration file $TFTPDIR/$FNAME."
  215.     fi
  216.     echo ""
  217.     echo "=================================================================="
  218.     cat $TMP/BOOTPRSP2
  219.     echo "=================================================================="
  220.     break
  221.   fi
  222.   if [ "$RESP" = "q" ]
  223.   then
  224.     rm -- "$TMP/BOOTPRSP"
  225.     rm -- "$TMP/BOOTPRSP2"
  226.     exit 1
  227.   fi
  228.   if [ "$RESP" = "n" ]
  229.   then
  230.     break
  231.   fi
  232.   if [ "$RESP" = "?" ]
  233.   then
  234.     echo "\nEnter \"y\" to display the contents of the BOOTP response and"
  235.     echo "continue with the configuration test."
  236.     echo ""
  237.     echo "Enter \"n\" to continue with the configuration test."
  238.     echo ""
  239.     echo "If there is a peripheral configuration file set up, the next test"
  240.     echo "will verify that the configuration file can be retrieved with TFTP."
  241.     echo "If there is no peripheral configuration file, the configuration test"
  242.     echo "is complete."
  243.     echo ""
  244.     $QUITHELP
  245.   fi
  246. done
  247.  
  248. if [ -n "$FNAME" ]
  249. then
  250.     if [ "$RESP" != "n" ]
  251.     then
  252.       echo "\nPress the return key to continue ... $NL"
  253.       read -r RESP
  254.     fi
  255.     #
  256.     # A configuration file was specified in bootptab file - now check if 
  257.     # it can be retrieved with tftp.
  258.     #
  259.     echo ""
  260.     echo "=================================================================="
  261.     echo "Testing that $TFTPDIR/$FNAME can be retrieved "
  262.     $ECHO "with TFTP ...$NL"
  263.  
  264.     if [ ! -f "$TFTP" ] 
  265.     then
  266.       echo "\n$TFTP does not exist.\n"
  267.       echo "Press the return key to continue ... $NL"
  268.       read -r RESP
  269.       exit 1
  270.     fi
  271.  
  272.     "$TFTP" "$HOSTNAME" > "$TMP/INFO" 2>&1 <<-EOF
  273. get ${FNAME} $TMP/TFTP
  274. EOF
  275.  
  276.     echo "\n"
  277.  
  278.     # Determine if the tftp transfer was successful.  We know that the host
  279.     # is known so host unknown error will not occur.  A check is made
  280.     # to determine if the tftp was able to read the configuration file.
  281.  
  282.     cat -- "$TMP/INFO" | egrep "not found|timed out|Access violation" > /dev/null 2>&1
  283.  
  284.     if [ $? -eq 0 ]
  285.     then 
  286.       echo "The configuration file $FNAME could not be retrieved with TFTP.\n"
  287.       echo "Check for tftp entries in /etc/inetd.conf and /etc/services."
  288.       echo "Check for error messages from tftpd in your syslog file."
  289.       echo "Check the permissions on the directories and the file in the path:"
  290.       echo ""
  291.       echo "          $TFTPDIR/$FNAME"
  292.       echo ""
  293.       echo "=================================================================="
  294.       echo "\nPress the return key to continue ... $NL"
  295.       read -r RESP
  296.       exit 1
  297.     else
  298.       echo "The configuration file $TFTPDIR/$FNAME was"
  299.       echo "successfully retrieved with TFTP.  The network peripheral"
  300.       echo "should be able to retrieve this file."
  301.       echo "=================================================================="
  302.       while [ 0 ]
  303.       do
  304.         echo "\nDo you want to see the peripheral configuration file"
  305.         echo "to check that it is correct?  (y/n/q default=y) $NL"
  306.         read -r RESP
  307.         if [ -z "$RESP" -o "$RESP" = "y" ]
  308.         then
  309.           echo ""
  310.           echo "=================================================================="
  311.           cat $TMP/TFTP
  312.           echo "=================================================================="
  313.           break
  314.         fi
  315.         if [ "$RESP" = "q" ]
  316.         then
  317.       break
  318.         fi
  319.     if [ "$RESP" = "n" ]
  320.     then
  321.       break
  322.     fi
  323.         if [ "$RESP" = "?" ]
  324.         then
  325.           echo "\nEnter \"y\" to display the contents of the peripheral configuration"
  326.       echo "file.\n"
  327.           echo "Enter \"n\" or \"q\" to complete the configuration test."
  328.         fi
  329.       done
  330.  
  331.     fi
  332.     rm -f -- "$TMP/INFO" "$TMP/TFTP"
  333. fi
  334.  
  335. rm -f -- "$TMP/BOOTPRSP"
  336. rm -f -- "$TMP/BOOTPRSP2"
  337.  
  338. echo "\nThe BOOTP/TFTP Configuration test is complete.  You can now"
  339. echo "power on your peripheral if it is not already powered on."
  340. echo "\nPress the return key to continue ... $NL"
  341. read -r RESP
  342.  
  343. exit 0
  344.