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

  1. #!/bin/ksh
  2. # The following was generated from 
  3. # NLS/english/hpnp.gen
  4. #
  5. MF_HPNP=hpnp.cat
  6. #
  7. MS_HPNP=1
  8. HPNP_FIRST_MSG=1
  9. HPNP_CASS_PPORT=2
  10. HPNP_CASS_NRADR=3
  11. HPNP_CASS_CPORT=4
  12. HPNP_CASS_NCONN=5
  13. HPNP_CASS_SUCCD=6
  14. HPNP_CASS_HACCS=7
  15. HPNP_CASS_NACCS=8
  16. HPNP_CASS_USAGE=9
  17. HPNP_CHKA_CNCPI=10
  18. HPNP_HPNF_USAGE=11
  19. HPNP_HPNF_FALLW=12
  20. HPNP_HPNF_NACCF=13
  21. HPNP_HPNF_CPORT=14
  22. HPNP_HPNF_FAILD=15
  23. HPNP_HPNF_CNTED=16
  24. HPNP_HPNF_CONNT=17
  25. HPNP_HPNF_DPORT=18
  26. HPNP_HPNF_NACCS=19
  27. HPNP_HPNF_PRTNR=20
  28. HPNP_HPNF_SENDF=21
  29. HPNP_HPNF_CCLOS=22
  30. HPNP_HPNF_OFFLN=23
  31. HPNP_HPNF_USTAT=24
  32. HPNP_HPNF_STATP=25
  33. HPNP_HPNF_PAPER=26
  34. HPNP_HPNF_HUMNI=27
  35. HPNP_HPNF_RPEER=28
  36. HPNP_HTYD_TMOUT=29
  37. HPNP_HTYD_USAGE=30
  38. HPNP_HTYD_FORKF=31
  39. HPNP_LOGC_FOLOG=32
  40. HPNP_NETW_ERROR=33
  41. HPNP_NETW_UHOST=34
  42. HPNP_INST_IEXIT=35
  43. HPNP_INST_RESTO=36
  44. HPNP_INST_ERINS=37
  45. HPNP_INST_EREXE=38
  46. HPNP_INST_CONFG=39
  47. HPNP_INST_ABPSE=40
  48. HPNP_INST_ABPCE=41
  49. HPNP_INST_WRUNG=42
  50. HPNP_INST_SIGRR=43
  51. HPNP_INST_NCNFP=44
  52. HPNP_INST_INCPT=45
  53. HPNP_INST_REMOV=46
  54. HPNP_INST_RESTR=47
  55. HPNP_INST_USAGE=48
  56. HPNP_INST_NPCFG=49
  57. HPNP_INST_IORRP=50
  58. HPNP_INST_PANSW=51
  59. HPNP_CNFG_QTOMM=52
  60. HPNP_CNFG_CNCON=53
  61. HPNP_CNFG_BSUSR=54
  62. HPNP_CNFG_MENUA=55
  63. HPNP_CNFG_MENUB=56
  64. HPNP_CNFG_MENUC=57
  65. HPNP_CNFG_MENUD=58
  66. HPNP_CNFG_MENUE=59
  67. HPNP_CNFG_MENUF=60
  68. HPNP_CNFG_MENUG=61
  69. HPNP_CNFG_MENUH=62
  70. HPNP_CNFG_MENUI=63
  71. HPNP_CNFG_MENUJ=64
  72. HPNP_CNFG_MENUK=65
  73. HPNP_CNFG_MENUL=66
  74. HPNP_CNFG_ALOGA=67
  75. HPNP_CNFG_ALOGB=68
  76. HPNP_CNFG_HELPA=69
  77. HPNP_CNFG_HELPB=70
  78. HPNP_CNFG_HELPC=71
  79. HPNP_CNFG_HELPD=72
  80. HPNP_CNFG_HELPE=73
  81. HPNP_CNFG_HELPF=74
  82. HPNP_CNFG_HELPG=75
  83. HPNP_CNFG_HELPH=76
  84. HPNP_CNFG_HELPI=77
  85. HPNP_CNFG_HELPJ=78
  86. HPNP_CNFG_HELPK=79
  87. HPNP_CNFG_HELPL=80
  88. HPNP_CNFG_HELPM=81
  89. HPNP_CNFG_HELPN=82
  90. HPNP_CNFG_IVSEL=83
  91. HPNP_LAST_MSG=84
  92. #!/bin/ksh
  93.  
  94. # Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  95. #                                                                         
  96. #        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  97. #                   SANTA CRUZ OPERATION INC.                             
  98. #                                                                         
  99. #   The copyright notice above does not evidence any actual or intended   
  100. #   publication of such source code.                                      
  101.  
  102. #ident    "@(#)hpnp.sh    1.3"
  103. #        copyright    "%c%"
  104.  
  105. # (c)Copyright Hewlett-Packard Company 1991.  All Rights Reserved.
  106. # (c)Copyright 1983 Regents of the University of California
  107. # (c)Copyright 1988, 1989 by Carnegie Mellon University
  108. #
  109. #                          RESTRICTED RIGHTS LEGEND
  110. # Use, duplication, or disclosure by the U.S. Government is subject to
  111. # restrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights in
  112. # Technical Data and Computer Software clause in DFARS 252.227-7013.
  113. #
  114. #                          Hewlett-Packard Company
  115. #                          3000 Hanover Street
  116. #                          Palo Alto, CA 94304 U.S.A.
  117. #
  118. #    mkdev/hpnp - HP Network Printer Configuration
  119. #
  120.  
  121. # Define return values
  122. OK=0 FAIL=1 STOP=10 HALT=11
  123.  
  124. # Define traps
  125. set_trap()
  126. {
  127.     trap 'echo "\nInterrupted! Exiting ..."; cleanup 1 $1' 1 2 3 15
  128. }
  129.  
  130. unset_trap()
  131. {
  132.     trap '' 1 2 3 15
  133. }
  134.  
  135. # Miscellaneous functions
  136.  
  137. clear_scr()
  138. {
  139.     # check if the terminal environment is set up
  140.     [ "$TERM" ] && clear 2> /dev/null
  141. }
  142.  
  143. cleanup()
  144. {
  145.     case $2 in
  146.         inetd)      if [ -f "$HPNPDIR/inetd.cf.orig" ]
  147.                     then
  148.                 echo "Restoring $INETDCONF"
  149.                 mv -f -- "$HPNPDIR/inetd.cf.orig" "$INETDCONF"
  150.                 rm -f -- "$HPNPDIR/inetd.cf.orig"
  151.                     fi
  152.                 ;;
  153.         serivces)   if [ -f "$HPNPDIR/services.orig" ]
  154.                 then
  155.                 echo "Restoring $SERVICES"
  156.                 mv -f -- "$HPNPDIR/services.orig" "$SERVICES"
  157.                 rm -f -- "$HPNPDIR/services.orig"
  158.                 fi
  159.                 ;;
  160.     esac
  161.     unset_trap
  162.     exit $1
  163. }
  164.  
  165. getyn()
  166. {
  167.     while echo "$* (y/n) \c">&2
  168.     do
  169.         read -r yn rest
  170.         case "$yn" in
  171.             [yY]*) return $OK
  172.                   ;;
  173.             [nN]*) return $FAIL
  174.                   ;;
  175.             *)    echo "Please answer y or n" >&2
  176.                   ;;
  177.         esac
  178.     done
  179. }
  180.  
  181. prompt() {
  182.     typeset mesg=$1
  183.     while   echo "$mesg [$2]: \c" >&2
  184.     do      read -r cmd
  185.         case "$cmd" in
  186.         +x|-x)  set $cmd
  187.             ;;
  188.         Q|q)    return 1
  189.             ;;
  190.         !*)     eval `expr "$cmd" : "!\(.*\)"`
  191.             ;;
  192.         "")     # If there is an second argument use it
  193.             # as the default else loop until 'cmd' is set
  194.             [ -n "$2" ] && {
  195.                 cmd=$2
  196.                 return 0
  197.             }
  198.             : continue
  199.             ;;
  200.         *)      return 0
  201.             ;;
  202.         esac
  203.     done
  204. }
  205.  
  206. error()
  207. {
  208.     echo "\nError: $*" >&2
  209.     exit $FAIL
  210. }
  211.  
  212. install() {
  213.  
  214. clear_scr
  215.  
  216. progname=$0
  217.  
  218. if [ -f "$HPNPDIR/.installed" ]
  219. then
  220.     error $progname: Network Printing already installed.
  221. fi
  222.  
  223. # Check that root is running us
  224. typeset -i UID
  225. UID=`id -u`
  226. [ $UID -ne 0 ] && {
  227.     error $progname: You must be root to execute this script.
  228. }
  229.  
  230.  
  231. STARTUTIL=1
  232. if [ -n "$_no_prompt" ]
  233. then
  234.  
  235.     cat <<EOF
  236.  
  237. Installing the startup configuration utilities results in the following:
  238.  
  239.     o /etc/inetd.conf and /etc/services are modified to support BOOTP if
  240.       necessary.
  241.  
  242. EOF
  243.  
  244.     getyn Install the startup configuration utilities
  245.  
  246.     if [ $? -ne $OK ]
  247.     then
  248.         STARTUTIL=0
  249.     fi
  250.  
  251.     clear_scr
  252. fi
  253.  
  254. if [ $STARTUTIL -eq 1 ]
  255. then
  256.     if [ -f "$BOOTPD" ]
  257.     then
  258.         echo $BOOTPD >> "$HPNPDIR/install.files"
  259.     fi
  260.  
  261.     if [ ! -f "$BOOTPTAB" ]
  262.     then
  263.         cp -f -- "$HPNPDIR/examples/bootptab" "$BOOTPTAB"
  264.         chmod a=r "$BOOTPTAB"
  265.         chown root:sys "$BOOTPTAB"
  266.     fi
  267.     echo $BOOTPTAB >> "$HPNPDIR/install.files"
  268.  
  269.     if [ -f "$HPNPDIR/hpnpf" ]
  270.     then
  271.         echo $HPNPDIR/hpnpf >> "$HPNPDIR/install.files"
  272.     fi
  273.  
  274.     if [ -f "$HPNPDIR/hpnptyd" ]
  275.     then
  276.         echo $HPNPDIR/hpnptyd >> "$HPNPDIR/install.files"
  277.     fi
  278.  
  279.     if [ -f "$HPNPDIR/hpnpcfg" ]
  280.     then
  281.         echo $HPNPDIR/hpnpcfg >> "$HPNPDIR/install.files"
  282.     fi
  283.  
  284.     if [ -f "$HPNPDIR/sh/hpnp.model" ]
  285.     then
  286.         echo $HPNPDIR/sh/hpnp.model >> "$HPNPDIR/install.files"
  287.     fi
  288.  
  289.     grep -- '^bootps' "$INETDCONF" > /dev/null
  290.     if [ $? -ne 0 ]
  291.     then
  292.         # Remember $INETDCONF maybe a symlink
  293.         cp -fp -- "$INETDCONF" "$HPNPDIR/inetd.cf.orig"
  294.         set_trap inetd
  295.         echo "Appending bootps entry to $INETDCONF"
  296.         echo "# bootp added by hpnp" >> "$INETDCONF"
  297.         echo "$BOOTP" >> $INETDCONF
  298.         unset_trap
  299.     fi
  300.  
  301.     egrep '^bootps[[:space:]]*[[:digit:]]*/udp' "$SERVICES" > /dev/null
  302.     if [ $? -ne 0 ]
  303.     then
  304.         cp -fp -- "$SERVICES" "$HPNPDIR/services.orig"
  305.         set_trap services
  306.         echo "Appending bootps entry to $SERVICES"
  307.         echo "$BOOTPS" >> "$SERVICES"
  308.         unset_trap
  309.     fi
  310.  
  311.     egrep '^bootpc[[:space:]]*[[:digit:]]*/udp' "$SERVICES" > /dev/null
  312.     if [ $? -ne 0 ]
  313.     then
  314.         cp -fp -- "$SERVICES" "$HPNPDIR/services.orig"
  315.         set_trap services
  316.         echo "Appending bootpc entry to $SERVICES"
  317.         echo "$BOOTPC" >> "$SERVICES"
  318.         unset_trap
  319.     fi
  320.  
  321.     PID=`ps -ef -o "pid comm"  | awk '($2 == "inetd" ) { print $1; exit 0}'`
  322.     if [ -z "$PID" ]
  323.     then
  324.         echo "WARNING: No inetd process running!!"
  325.     else
  326.         kill -HUP $PID
  327.         echo "Signalled inetd to re-read $INETDCONF"
  328.     fi
  329. fi
  330.  
  331. ls -- "$HPNPDIR/examples" | while read -r NAME
  332. do
  333.     echo $HPNPDIR/examples/$NAME >> "$HPNPDIR/install.files"
  334. done
  335.  
  336. ls -- "$HPNPDIR/testfiles" | while read -r NAME
  337. do
  338.     echo $HPNPDIR/testfiles/$NAME >> "$HPNPDIR/install.files"
  339. done
  340.  
  341. sort "$HPNPDIR/install.files" | uniq > "$HPNPDIR/install.tmp"
  342. mv -f -- "$HPNPDIR/install.tmp" "$HPNPDIR/install.files"
  343.  
  344. if [ -n "$_no_prompt" ]
  345. then
  346.     clear_scr
  347.     "$HPNPDIR/hpnpcfg"
  348. else
  349.     echo "You now need to run $HPNPDIR/hpnpcfg to configure your printers"
  350. fi
  351.  
  352. if [ $STARTUTIL -eq 1 ]
  353. then
  354.     touch -- "$HPNPDIR/.installed"
  355. fi
  356.  
  357. echo "Installation complete."
  358. }
  359.  
  360. remove() {
  361.  
  362.     clear_scr
  363.     echo "Removing: \c"
  364.  
  365.     if [ -f "$MODELDIR/hpplotter" ]
  366.     then
  367.         echo "          $MODELDIR/hpplotter"
  368.         rm -f -- "$MODELDIR/hpplotter"
  369.     fi
  370.  
  371.     if [ -f "$MODELDIR/laserjetIIIsi" ]
  372.     then
  373.         echo "          $MODELDIR/laserjetIIIsi"
  374.         rm -f -- "$MODELDIR/laserjetIIIsi"
  375.     fi
  376.  
  377.     if [ -f "$MODELDIR/laserjethpnp" ]
  378.     then
  379.         echo "          $MODELDIR/laserjethpnp"
  380.         rm -f -- "$MODELDIR/laserjethpnp"
  381.     fi
  382.  
  383.     if [ -f "$HPNPDIR/inetd.cf.orig" ]
  384.     then
  385.         echo "\nRestoring the original inetd.conf file"
  386.         mv -f -- "$HPNPDIR/inetd.cf.orig" "$INETDCONF"
  387.         rm -f -- "$HPNPDIR/inetd.cf.orig"
  388.     fi
  389.  
  390.     echo "\n"
  391.  
  392.     if [ -d "/usr/spool/lp/admins/lp/interfaces/model.orig" ]
  393.     then
  394.         rm -rf -- "/usr/spool/lp/admins/lp/interfaces/model.orig"
  395.     fi
  396.  
  397.     if [ -f "$HPNPDIR/install.files" ]
  398.     then
  399.         rm -f -- "$HPNPDIR/install.files"
  400.     fi
  401.  
  402.     rm -f -- "$HPNPDIR/.installed"
  403. }
  404.  
  405. usage()
  406. {
  407.     echo "\nUsage: $0 [-i | -r] [-n]\n"
  408.     exit 2
  409. }
  410.  
  411. #
  412. # Main
  413. #
  414.  
  415. PATH="/bin:/usr/bin:/etc"        # need more???
  416. HPNPDIR="/usr/lib/hpnp"
  417. MODELDIR="/etc/lp/model"
  418. BOOTPTAB="/etc/bootptab"
  419. SERVICES="/etc/services"
  420. INETDCONF="/etc/inetd.conf"
  421. BOOTPD="/usr/sbin/in.bootpd"
  422. BOOTP="bootps    dgram    udp    wait    root    $BOOTPD    in.bootpd"
  423. BOOTPS="bootps           67/udp        bootp    #Bootstrap protocol server"
  424. BOOTPC="bootpc           68/udp            #Bootstrap protocol client"
  425.  
  426. typeset -rx HPNPDIR SERVICES BOOTPTAB INETDCONF
  427.  
  428. _no_prompt=""
  429. _install=""
  430. _remove=""
  431.  
  432. while getopts inr opt
  433. do
  434.     case $opt in
  435.  
  436.         i) _install="TRUE"
  437.            ;;
  438.  
  439.         n) _no_prompt="TRUE"
  440.            ;;
  441.  
  442.         r) _remove="TRUE"
  443.            ;;
  444.  
  445.         \?) usage
  446.             ;;
  447.  
  448.     esac
  449. done
  450.  
  451. [ "$_install" -a "$_remove" ] && {
  452.     usage
  453. }
  454.  
  455. [ -n "$_install" ] && {
  456.     install
  457.     exit $OK
  458. }
  459.  
  460. [ -n "$_remove" ] && {
  461.     remove
  462.     exit $OK
  463. }
  464.  
  465. #
  466. # Now we must be in interactive mode
  467. #
  468.  
  469. clear_scr
  470.  
  471. echo "\n\t\tHP Network Printer Configuration"
  472.  
  473. while prompt "\n\nDo you want to install or remove network printing (i/r/q)?" "q"
  474. do
  475.     [ $? -eq 1 ] && exit $FAIL
  476.  
  477.     case $cmd in
  478.  
  479.         I|i) install
  480.              exit $OK
  481.              ;;
  482.  
  483.         R|r) remove
  484.              exit $OK
  485.              ;;
  486.  
  487.         Q|q) exit $OK
  488.              ;;
  489.  
  490.         *) echo "Please answer 'i','r' or 'q'."
  491.            ;;
  492.  
  493.     esac
  494. done
  495.