#ident "@(#)/usr/local/sysadmin/PTRMGR 1.0 03/18/91" Author: Mr Reinhard Pfaffinger
# Office: 1924 CSS/SDA, Randolph AFB, Texas 78150
# Phone: AV 487-8649  Comm: (512) 652-8649
#
# This script allows the system administrator to manage the LP environment.
#

chkfortty() {
             if [ "$TERM" = "tty" ]
               then
                   echo  
             else
                 tput clear 
             fi
            }

rtn() {
       echo "\nPress <RETURN> ... \c"
       read RTN
      }

while :
 do
   chkfortty
   echo "                   <<< AT&T 3B2/600G Printer Management Menu >>>\n"
   echo "                       1. Cancel Print Requests"
   echo "                       2. Add Printer"
   echo "                       3. Change Printer Configuration" 
   echo "                       4. Delete Printer"
   echo "                       5. Enable Printer" 
   echo "                       6. Disable Printer" 
   echo "                       7. Allow Printer to Accept Requests"
   echo "                       8. Disallow Printer to Accept Requests"
   echo "                       9. Shutdown/Startup LP Service"
   echo "                      10. LP Status Sub-Menu"
   echo "                      11. Assign System Default Printer\n"
   echo "				q or Q to quit\n"
   echo "			   Enter response <RETURN> =>> \c"
   read RESP
   case "$RESP" in
      1)
        chkfortty
        echo "Printer(s) status on '`uname -n`':\n"
        lpstat -a -p
        echo "\nEnter the name of the printer whose print requests you wish to cancel."
        echo "<RETURN> =>> \c"
        read PTRNAME
        /usr/local/cancelptr $PTRNAME
        rtn
        continue
        ;;
      2)
        chkfortty
        sysadm lpmgmt/printers/add_p
        rtn
        chkfortty
        echo "Enabling printer ... \n"
        sysadm lpmgmt/printers/enable_p
        rtn
        chkfortty
        echo "Allowing printer to accept print requests ... \n"
        sysadm lpmgmt/printers/accept_p
        rtn
        chkfortty
        echo "NOTE:\n\tIf you wish to make the printer just added the system default"
        echo "\tprinter, execute option '11' from the menu.\n"
        echo "\tTo verify the printer's configuration, execute option '10' from the"
        echo "\tmenu."
        rtn
        continue
        ;;
      3)
        chkfortty
        sysadm lpmgmt/printers/change_p
        rtn
        continue
        ;;
      4)
        chkfortty
        echo "Disallowing printer to accept print requests ... \n"
        sysadm lpmgmt/printers/reject_p
        rtn
        chkfortty
        echo "Disabling printer ... \n"
        sysadm lpmgmt/printers/disable_p
        rtn
        chkfortty
        sysadm lpmgmt/printers/delete_p
        rtn
        continue
        ;;
      5)
        chkfortty
        sysadm lpmgmt/printers/enable_p
        rtn
        continue
        ;;
      6)
        chkfortty
        sysadm lpmgmt/printers/disable_p
        rtn
        continue
        ;;
      7)
        chkfortty
        sysadm lpmgmt/printers/accept_p
        rtn
        continue
        ;;
      8)
        chkfortty
        sysadm lpmgmt/printers/reject_p
        rtn
        continue
        ;;
      9)
        chkfortty
        echo "\t\tDo you wish to shutdown or startup the LP scheduler?\n"
        echo "\t\t\t\t1. Shutdown LP"
        echo "\t\t\t\t2. Startup LP\n"
        echo "\t\t\t\tq or Q to quit\n"
        echo "\t\tEnter response <RETURN> =>> \c"
        read LPS
        case "$LPS" in
             1)
               if [ "`ps -ef | fgrep lpsched | fgrep -v 'fgrep lpsched'`" != "" ]
                 then
                     chkfortty
                     /usr/lib/lpshut 
                     rtn
               else
                   echo "\n\n\t\t\t\tLP Scheduler already stopped!\c"
                   sleep 5
               fi
               ;;
             2)
               if [ "`ps -ef | fgrep lpsched | fgrep -v 'fgrep lpsched'`" = "" ]
                 then
                     chkfortty
                     /usr/lib/lpsched
                     rtn
               else
                   echo "\n\n\t\t\t\tLP Scheduler already running!\c"
                   sleep 5
               fi
               ;;
        esac
        continue
        ;;
     10)
        /usr/local/usermenu/spoolerstatus
        ;;
     11)
        chkfortty
        sysadm lpmgmt/service/default
        rtn
        continue
        ;;
    q|Q)
        exit 0
        ;;
      *)
        echo "\n\t\t\t\tInvalid response!\c"
        sleep 2
        continue
        ;;
  esac
 done
