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

  1. #!/bin/ksh
  2. #ident    "@(#)option6    1.3"
  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. # CHANGE HISTORY:
  18. #
  19. # 15-05-97   Paul Cunningham        ul97-13201 and ul97-13202
  20. #            Changed so that if the "printer type" and "context type" questions
  21. #            are defaulted, the correct default values are used instead of
  22. #            leaving them blank.
  23. #
  24.  
  25. INTFDIR="/usr/spool/lp/admins/lp/interfaces"
  26. PRINTERTYPE="unknown"
  27. CONTEXTTYPE="simple"
  28.  
  29. SPOOLNAME="$1"
  30. PERIPHNAME="$1"
  31.  
  32. if [ ! -f "$HPNP/hpnpf" ]
  33. then
  34.   echo "\nThe spooler software must not have been installed since"
  35.   echo "$HPNP/hpnpf does not exist.  Install the NPI"
  36.   echo "spooler software before configuring the spooler."
  37.   echo "\nPress the return key to return to the main menu ... $NL"
  38.   read -r RESP
  39.   exit 1
  40. fi
  41.  
  42. #
  43. # Only use the first label if we have a domain name
  44. #
  45. SPOOLNAME=`echo $SPOOLNAME | awk -F. '{print $1}'`
  46.  
  47. getspoolname  "option6hp" "$SPOOLNAME" ""
  48. if [ $? -ne 0 ]
  49. then 
  50.   exit 1
  51. fi
  52.  
  53. SPOOLNAME=`cat -- $TMP/SPOOLNM`
  54. rm -- "$TMP/SPOOLNM"
  55.  
  56. #
  57. # The peripheral name may not be the same as the name known by 
  58. # the spooler.
  59. #
  60. if [ -z "$PERIPHNAME" ]
  61. then
  62.     PERIPHNAME="$SPOOLNAME"
  63. fi
  64.  
  65. getname "option6hp" "$PERIPHNAME"
  66. if [ $? -ne 0 ]
  67. then
  68.   exit 1
  69. fi
  70. PERIPHNAME=`cat -- $TMP/NAME`
  71. rm -f -- "$TMP/NAME"
  72.  
  73. if [ ! -d "$INTFDIR/model.orig" ]
  74. then
  75.    echo "Creating directory $INTFDIR to hold the original model script" >> $LOG
  76.    echo "" >> $LOG
  77.    echo mkdir $INTFDIR/model.orig >> $LOG
  78.    mkdir -- "$INTFDIR/model.orig"
  79.    echo chown lp:lp $INTFDIR/model.orig >> $LOG
  80.    chown lp:lp "$INTFDIR/model.orig"
  81.    echo chmod ug=rwx,o=rx $INTFDIR/model.orig >> $LOG
  82.    chmod ug=rwx,o=rx "$INTFDIR/model.orig"
  83.    echo "" >> $LOG
  84. fi
  85.  
  86. #  Check if this peripheral is already set up in spooler.  If so give message
  87. #  and exit.
  88.  
  89. if [ -f "$INTFDIR/$SPOOLNAME" -a -f "$INTFDIR/model.orig/$SPOOLNAME" ]
  90. then
  91.   grep 'HP-UX Network Peripheral Model Script' "$INTFDIR/$SPOOLNAME" > /dev/null 2>&1
  92.   if [ $? -eq 0 ]
  93.   then
  94.     echo "\nNetwork printer $SPOOLNAME is already part of spooler system."
  95.     echo "Press the return key to continue ... $NL"
  96.     read -r RESP
  97.     exit 1
  98.   fi
  99. fi
  100.  
  101. if [ -f "$INTFDIR/$SPOOLNAME" ]
  102. then
  103.   grep 'HP-UX Network Peripheral Model Script' $INTFDIR/$SPOOLNAME > /dev/null 2>&1
  104.   if [ $? -ne 0 ]
  105.   then
  106.     # The peripheral is part of spooler system.  The model file however is not
  107.     # the HP-UX Network Peripheral Model Script so convert it to a network
  108.     # peripheral.  Move the existing model file to the model.orig subdirectory 
  109.     # and add network script to interface directory.
  110.  
  111.     echo "" >> $LOG
  112.     echo "Converting $SPOOLNAME from a direct connect to a network printer" >> $LOG
  113.     echo "" | tee -a -- $LOG
  114.  
  115.     echo mv -f $INTFDIR/$SPOOLNAME $INTFDIR/model.orig/$SPOOLNAME | tee -a -- $LOG
  116.     mv -f -- "$INTFDIR/$SPOOLNAME" "$INTFDIR/model.orig/$SPOOLNAME"
  117.  
  118.     if [ "$PERIPHNAME" != "$SPOOLNAME" ]
  119.     then
  120.       echo sed -e "s/^PERIPH=/PERIPH=$PERIPHNAME/" $HPNP/hpnp.model \> $INTFDIR/$SPOOLNAME | tee -a -- $LOG
  121.       sed -e "s/^PERIPH=/PERIPH=$PERIPHNAME/" "$HPNP/hpnp.model" > "$INTFDIR/$SPOOLNAME"
  122.     else
  123.       echo cp -fp $HPNP/hpnp.model $INTFDIR/$SPOOLNAME | tee -a -- $LOG
  124.       cp -fp -- "$HPNP/hpnp.model" "$INTFDIR/$SPOOLNAME"
  125.     fi
  126.     echo "" | tee -a -- $LOG
  127.     echo "Converted $SPOOLNAME from a direct connect to a network printer."
  128.     echo "Press the return key to continue ... $NL"
  129.     read -r RESP
  130.     exit 1
  131.   fi
  132. fi
  133.  
  134. typeset -u UPPERCASE
  135. while [ 0 ]
  136. do
  137.     echo "\nEnter printer type: (default=$PRINTERTYPE) $NL"  
  138.     read -r USERINPUT
  139.     UPPERCASE="$USERINPUT"
  140.     if [ -z "$UPPERCASE" ]
  141.     then
  142.       # Set default printer type
  143.       USERINPUT="$PRINTERTYPE"
  144.       break
  145.     fi
  146.     if [ "$UPPERCASE" = "Q" ]
  147.     then
  148.         exit 1
  149.     fi
  150.     if [ "$UPPERCASE" = "?" ]
  151.     then
  152.         echo "\nThis is the type name as in the terminfo database.\n"
  153.         $QUITHELP
  154.         continue
  155.     fi
  156.  
  157.     # Check if in terminfo
  158.     /usr/bin/infocmp "$USERINPUT" 2>&1 1>/dev/null
  159.     if [ $? -ne 0 ]
  160.     then
  161.         echo "\nThe printer type \"$USERINPUT\" is not in the terminfo"
  162.         echo "database."
  163.         echo "Please check your spelling and try again."
  164.         echo "\nPress the return key to continue ... $NL"
  165.         read -r RESP
  166.         continue
  167.     fi
  168.     break
  169. done
  170. PRINTERTYPE="$USERINPUT"
  171.  
  172. while [ 0 ]
  173. do
  174.     echo "\nEnter context-type for printer (default=$CONTEXTTYPE) $NL"
  175.     read -r USERINPUT
  176.     UPPERCASE="$USERINPUT"
  177.     if [ -z "$UPPERCASE" ]
  178.     then
  179.       # Set default context type
  180.       USERINPUT="$CONTEXTTYPE"
  181.       break
  182.     fi
  183.     if [ "$UPPERCASE" = "Q" ]
  184.     then
  185.         exit 1
  186.     fi
  187.     if [ "$UPPERCASE" = "?" ]
  188.     then
  189.         echo "\nThe context-type is the type the printer can handle"
  190.         echo "print requests for directly.  That is to say, the type"
  191.         echo "that is sent to the printer after any filter has been"
  192.         echo "performed.\n"
  193.         $QUITHELP
  194.         continue
  195.     fi
  196.  
  197.     if [ "$UPPERCASE" == "PCL" ]
  198.     then
  199.         USERINPUT="pcl"
  200.         break
  201.     fi
  202.     if [ "$UPPERCASE" == "PS" ]
  203.     then
  204.         USERINPUT="PS"
  205.         break
  206.     fi
  207.     if [ "$UPPERCASE" == "SIMPLE" ]
  208.     then
  209.         USERINPUT="simple"
  210.         break
  211.     fi
  212.  
  213.     echo "\nContext-type must be; \"PCL\", \"PS\" or \"simple\""
  214. done
  215.  
  216. CONTEXTTYPE="$USERINPUT"
  217.  
  218. CLASS=""
  219. CLASSOPT=""
  220. getspoolname "option6hp" "" "class"
  221. RETCODE=$?
  222. if [ $RETCODE -eq 1 ]
  223. then 
  224.   exit 1
  225. fi
  226. if [ $RETCODE -eq 0 ]
  227. then 
  228.   CLASS=`cat -- $TMP/SPOOLNM`
  229.   CLASSOPT="-c $CLASS"
  230.   rm -- "$TMP/SPOOLNM"
  231. fi
  232.  
  233. while [ 0 ]
  234. do
  235.   echo "\nWill this be the default printer? (y/n/q default=n) $NL"
  236.   read -r DEFAULT
  237.   if [ "$DEFAULT" = "n" -o -z "$DEFAULT" ]
  238.   then
  239.     break
  240.   fi
  241.   if [ "$DEFAULT" = "y" ] 
  242.   then
  243.     break
  244.   fi
  245.   if [ "$DEFAULT" = "q" ]
  246.   then
  247.      exit 1
  248.   fi
  249.   if [ "$DEFAULT" = "?" ]
  250.   then
  251.     echo "\nEnter \"y\" to make the printer be the default destination."
  252.     echo "\nEnter \"n\" to add the printer as the non-default destination."
  253.     echo "\nEnter \"q\" or to return to the main menu."
  254.   fi
  255. done
  256.  
  257. echo "\nReady to shut down the spooling system, configure the new destination,"
  258. echo "and start the spooling system again.  When the spooling system is shut"
  259. echo "down all printing will stop.  Any print requests that are currently"
  260. echo "printing will be reprinted in their entirety when the spooling system"
  261. echo "is restarted."
  262.  
  263. while [ 0 ]
  264. do
  265.   echo "\nOK to continue? (y/n/q default=y) $NL"
  266.   read -r OK
  267.   if [ -z "$OK" -o "$OK" = "y" ]
  268.   then
  269.     break
  270.   fi
  271.   if [ "$OK" = "n" -o "$OK" = "q" ]
  272.   then
  273.     exit 1
  274.   fi
  275.   if [ "$OK" = "?" ]
  276.   then
  277.     echo "\nEnter \"y\" to add the spooler destination."
  278.     echo "\nEnter \"q\" or \"n\" to return to the main menu."
  279.   fi
  280. done
  281.  
  282. echo "" | tee -a -- $LOG
  283. echo "Adding $SPOOLNAME to spooler" >> $LOG
  284. echo "" >> $LOG
  285.  
  286. STARTLP=0
  287. echo /usr/sbin/lpshut | tee -a -- $LOG
  288. /usr/sbin/lpshut
  289. if [ $? -eq 0 ]
  290. then
  291.   STARTLP=1
  292. fi
  293.  
  294. echo /usr/sbin/lpadmin -p $SPOOLNAME -v /dev/null -f "allow:all" -u "allow:all" -I $CONTEXTTYPE -T $PRINTERTYPE $CLASSOPT | tee -a -- $LOG
  295. /usr/sbin/lpadmin -p $SPOOLNAME -v /dev/null -f "allow:all" -u "allow:all" -I "$CONTEXTTYPE" -T "$PRINTERTYPE" $CLASSOPT | tee -a -- $LOG
  296.  
  297. if [ "$DEFAULT" = "y" ]
  298. then
  299.     echo /usr/sbin/lpadmin -d $SPOOLNAME | tee -a -- $LOG
  300.     /usr/sbin/lpadmin -d $SPOOLNAME 
  301. fi
  302.  
  303. echo mv $INTFDIR/$SPOOLNAME $INTFDIR/model.orig/$SPOOLNAME | tee -a -- $LOG
  304. mv -f -- "$INTFDIR/$SPOOLNAME" "$INTFDIR/model.orig/$SPOOLNAME"
  305.  
  306. if [ "$PERIPHNAME" != "$SPOOLNAME" ]
  307. then
  308.   echo sed -e "s/^PERIPH=/PERIPH=$PERIPHNAME/" $HPNP/hpnp.model \> $INTFDIR/$SPOOLNAME | tee -a -- $LOG
  309.   sed -e "s/^PERIPH=/PERIPH=$PERIPHNAME/" "$HPNP/hpnp.model" > "$INTFDIR/$SPOOLNAME"
  310.     chmod u=rwx,go=rx "$INTFDIR/$SPOOLNAME"
  311.     chown lp:lp "$INTFDIR/$SPOOLNAME"
  312. else
  313.   echo cp -p $HPNP/hpnp.model $INTFDIR/$SPOOLNAME | tee -a -- $LOG
  314.   cp -p -- "$HPNP/hpnp.model" "$INTFDIR/$SPOOLNAME"
  315. fi
  316.  
  317. if [ $STARTLP -eq 1 ]
  318. then
  319.   echo /usr/lib/lp/lpsched | tee -a -- $LOG
  320.   /usr/lib/lp/lpsched
  321. else
  322.   echo scheduler was not restarted | tee -a -- $LOG
  323. fi
  324.  
  325. echo /usr/sbin/accept $SPOOLNAME | tee -a -- $LOG
  326. /usr/sbin/accept "$SPOOLNAME"
  327.  
  328. if [ -n "$CLASS" ]
  329. then
  330.   echo /usr/sbin/accept $CLASS | tee -a -- $LOG
  331.   /usr/sbin/accept "$CLASS"
  332. fi
  333.  
  334. echo /usr/bin/enable $SPOOLNAME | tee -a -- $LOG
  335. /usr/bin/enable "$SPOOLNAME"
  336. echo "" >> $LOG
  337.  
  338. echo "\nThe spooler destination $SPOOLNAME has been added to the spooler."
  339. echo "Press the return key to continue ... $NL"
  340. read -r RESP
  341. exit 0
  342.  
  343.