#!/bin/sh FILE_NAME="psinstall" CAT_NAME="ps" PROD_TYPE="Print Server" # ----------------------------------------------------------------------------- # # Printer installation / uninstallation script for UNIX environments # # (C) Copyright 1998-, Axis Communications AB, LUND, SWEDEN # # ----------------------------------------------------------------------------- REVISION="2.0.3 Jan 7 2000" # --- Make sure that the programs needed are in these paths PATH=${PATH}:/bin/ PATH=${PATH}:/usr/bin/:/usr/sbin/:/usr/bsd/:/usr/ucb:/usr/lib/:/usr/local/bin PATH=${PATH}:/usr/etc:/etc:/etc/sbin FILE_NAME=`basename $0` # Make changes here if you want to change any of the default values # PROSHOME is where filters are put, both pros and ftp DEF_PROSHOME=/usr/local/lib/$CAT_NAME DEF_PROSHOME_AIX=/usr/lpd/$CAT_NAME DEF_PRINTCAP=/etc/printcap DEF_MODELDIR=/usr/lib/lp/model DEF_HP_LPDMODELDIR="/etc/lp/interface/netlp.asx" DEF_SPOOLDIR_EVAL='echo /var/spool/lpd/${PRINTER}' DEF_PROSDEV_EVAL='echo /dev/${PRINTER}' DEF_LOGFILE_EVAL='echo $SPOOLDIR/log' DEF_PROSLOG_EVAL='echo $PROSHOME/prosd-${PRINTER}.log' DEF_FTP_FILE_EVAL='echo ftp_${PRINTER}' DEF_PROSB_FILE_EVAL='echo pros_${PRINTER}' DEF_AIX_COLONDIR=/usr/lpd/pio/predef/ AIX_LOG_FILE=1 AIX_LOG_MAIL=2 DEF_AIX_LOG_MODE=$AIX_LOG_MAIL clear=clear mknod=mknod cut=cut tee=tee ftp=ftp HOSTNAME= test -f /bin/uname && HOSTNAME=`/bin/uname -n` test -f /usr/bin/hostname && HOSTNAME=`/usr/bin/hostname` test -f /bin/hostname && HOSTNAME=`/bin/hostname` test -f /usr/bin/uname && HOSTNAME=`/usr/bin/uname -n` # ============================================================================ # Common Code # ============================================================================ recursive= trace= debug= suggest_name=NO advanced=NO while test -n "$1"; do case $1 in -recursive) recursive=YES ;; -trace) trace='-trace' ;; -debug) debug='-debug' ;; -suggest_name) suggest_name=YES ;; -advanced) advanced=YES ;; -h|-help) cat </dev/null test $? = 0 && test -f /bin/ksh && run_shell=/bin/ksh if test -n "${trace}"; then # Save trace data in a file in /tmp/ and preserve a bareable interface # to user by removing lines from output that starts with a '+' test -z "${run_shell}" && run_shell=sh exec ${run_shell} -x $0 -recursive $trace $debug 2>&1 | \ tee -a /tmp/${FILE_NAME}_$$.trace | grep -v '^+' echo echo "Trace file saved in /tmp/${FILE_NAME}_$$.trace" echo exit 0 elif test -n "${run_shell}"; then exec ${run_shell} $0 -recursive exit 0 fi fi # trap ^C and exit clean trap 'myexit 0 "Exiting"' 2 # No clear when debug test -n "$debug" -o -n "$trace" && clear= # --- cleanup ---------------------------------------------------------------- # --- Clean up things created by initilize cleanup() { rm -rf $TMPDIR } # --- End of cleanup # --- myecho $1 $2 $3 ... ---------------------------------------------------- # --- Echo text with or without newline at end # --- $1 - optional '-n' to skip newline at end # --- $* - rest of options passed to echo echo_n=NO test X`echo -n` = X && echo_n=YES myecho() { if test X"$1" = "X-n"; then shift test $echo_n = YES && echo -n "$*" test $echo_n = NO && echo "$*" '\c' else echo "$*" fi } # --- End of myecho # --- lecho $* --------------------------------------------------------------- # --- Log text and echo to screen lecho () { myecho $* | tee -a $instalog } # --- lecho # --- logg $* ---------------------------------------------------------------- # --- Put message in log file logg () { myecho $* >> $instalog } # --- logg # --- strip $1 --------------------------------------------------------------- # --- Strip spaces from beginning and end of string $1 # --- Result on standard out; use $a=`strip $b` # --- Do not add "" around $1, it is because of that it is without # --- these that the string is stripped. strip() { echo $1 } # --- End of strip # --- myexit $1 [$2] -------------------------------------------------------- # --- Exit with an optional message and cleanup files. # --- The string "Error:" is printed if error code is other than 0 # --- $1 - error code # --- $2 - optional message myexit() { if test $# = 2; then if test "$1" != "0"; then lecho -n "$FILE_NAME: Error: " fi lecho "$2" fi cleanup if test -n "$instalog" -a -f "$instalog"; then echo "A log file is saved in the file $instalog." fi exit "$1" } # --- End of myexit # --- answerP $1 $2 -------------------------------------------------------- # --- Simple prompt with default for a text string answer. # --- $1 is prompt string. # --- $2 is default answer. answerP() { answer= if test "X$2" != "X"; then myecho -n "$1 (default $2): "; read answer else myecho -n "$1":; read answer fi test "X$answer" = "X" && answer=$2 } # --- yes_or_no $1 $2 [$3] -------------------------------------------------- # --- Prompt with default for a yes or no answer. # --- Leave answer in yes_or_no. # --- $1 is prompt string. # --- $2 is default answer (yes/no). # --- $3 is optional, extra option, can be used for abort yes_or_noP() { yes_or_no= while true; do extra_opt= test $# = 3 && extra_opt="$3" answerP "$1 [yn${extra_opt}] ?" "$2" yes_or_no=$answer test "X$yes_or_no" = "X" && yes_or_no=$2 case $yes_or_no in y | Y | yes | Yes | YES) yes_or_no=YES break # out of the while loop ;; n | N | no | No | NO) yes_or_no=NO break # out of the while loop ;; esac # Do we match the extra option then? if test $# -eq 3 && test "X$yes_or_no" = "X$3"; then break fi done } # --- range_answer $1 $2 [$3] ------------------------------------------------ # --- Prompt for one character of a given character class. # --- $1 is prompt string. # --- $2 is allowed answer characters class, in range [1-X]. # --- $3 is optional default answer (must belong to class in $2). range_answerP() { range_answer= while true; do answerP "$1 $2" "$3" range_answer=$answer test "X$range_answer" = "X" && test $# -eq 3 && range_answer=$3 if test "X$range_answer" != "X"; then # get low and high limit in range, [low-high] low=`echo $2 | sed -n -e '/.*/ s/\[\([0-9]*\).*/\1/p'` hi=`echo $2 | sed -n -e '/.*/ s/.*-\([0-9]*\)\]/\1/p'` # Accept that high can be nothing, set it to same as low test "X$hi" = X && hi=$low if test $low -le $range_answer -a $range_answer -le $hi; then break # out of the while loop. else range_answer= fi fi done } # --- End of range_answerP # --- get_sys_versionsP [-i] ------------------------------------------------ # --- Set the sys_version and sys_sub_version variables # --- -i - interactive mode, ask if the version number is correct. # # --- static variables only used in this function # Extract major version number, there may be no dot. # In HP-UX, there is a letter in the beginning, such as 'A.10.20' # this is removed with the first [^0-9]* group sed_ver_cmd='sed -n -e "/^[^0-9]*[0-9]\{1,\}/ \ s/^[^0-9]*\([0-9]\{1,\}\).*/\1/p"' # Extract minor version number, there should be a dot, do not include # minor-minor version numbers, such as 1.2.3 becomes 2 sed_subver_cmd="sed -n '/[^0-9]*[0-9]*\.[0-9]\{1,\}/ \ s/[^0-9]*[0-9]*\.\([0-9]\{1,\}\)/\1/p'" get_sys_versionsP () { uname_ver_cmd='uname -r' if test $sys_num -eq $AIX_n; then # AIX has their own version of how to answer to uname ... aix_uname_ver=`uname -v` aix_uname_sub_ver=`uname -r` uname_ver_cmd="echo $aix_uname_ver.$aix_uname_sub_ver" elif test $sys_num -eq ${SCO_WARE2_n}; then # UnixWare 2.x shows in version uname_ver_cmd='uname -v' fi if test "X$1" = "X-i"; then answerP "What is the version of the system" `eval $uname_ver_cmd` uname_ver_cmd="echo $answer" fi # These needs eval because of variable substitution sys_version=`eval "$uname_ver_cmd | $sed_ver_cmd"` sys_sub_version=`eval "$uname_ver_cmd | $sed_subver_cmd"` test "X$sys_version" = "X" && sys_version=0 test "X$sys_sub_version" = "X" && sys_sub_version=0 } # --- End of get_sys_versionsP # --- os_type_initP --------------------------------------------------------- # --- Determine what OS we are running under # --- Sets the global variables listed in the beginning of the function. os_type_initP() { # Supported systems SUN4_sys="SunOS 4 (SUN BSD, Solaris 1.x)" SUN5_sys="SunOS 5 (SUN SYS V, Solaris 2.x)" AIX_sys="AIX (IBM RS/6000, BULL DPX 20)" HPUX_sys="HP-UX (HP 9000)" BOS_sys="BOS (BULL DPX 2)" OSF1_sys="DEC OSF/1 (Digital Equipment, Alpha)" ULTRIX_sys="ULTRIX (Digital Equipment, DEC)" SGI_sys="IRIX (Silicon Graphics, SGI)" SCO_sys="SCO UNIX (Santa Cruz Operation)" SCO_WARE2_sys="SCO UnixWare 2.x" SCO_WARE7_sys="SCO UnixWare 7" SCO_OPEN_sys="SCO OpenServer" FreeBSD_sys="FreeBSD (Berkeley UNIX)" Linux_sys="Linux" # Generic systems BSD_sys="Generic BSD (Berkeley UNIX)" SYSV3_sys="Generic SYS V R3 (UNIX System V Release 3)" SYSV4_sys="Generic SYS V R4 (UNIX System V Release 4)" # Use these constants to identify the systems below NO_SYS=0 SUN4_n=1 SUN5_n=2 AIX_n=3 HPUX_n=4 BOS_n=5 OSF1_n=6 ULTRIX_n=7 SGI_n=8 SCO_n=9 SCO_WARE2_n=10 SCO_WARE7_n=11 SCO_OPEN_n=12 FreeBSD_n=13 Linux_n=14 BSD_n=15 SYSV3_n=16 SYSV4_n=17 MAX_SYS_n=$SYSV4_n # Match beginning of system name and version, print system number cat < $TMPDIR/os_opts /^SunOS 4/ { s/.*/$SUN4_n/p; q;} /^SunOS 5/ { s/.*/$SUN5_n/p; q;} /^AIX/ { s/.*/$AIX_n/p; q;} /^HP-UX/ { s/.*/$HPUX_n/p; q;} /^B.O.S. / { s/.*/$BOS_n/p; q;} /^OSF1/ { s/.*/$OSF1_n/p; q;} /^ULTRIX/ { s/.*/$ULTRIX_n/p; q;} /^IRIX/ { s/.*/$SGI_n/p; q;} /^FreeBSD/ { s/.*/$FreeBSD_n/p; q;} /^UNIX_SV/ { s/.*/$SCO_WARE2_n/p; q;} /^UnixWare/ { s/.*/$SCO_WARE7_n/p; q;} /^SCO_SV/ { s/.*/$SCO_OPEN_n/p; q;} /^Linux/ { s/.*/$Linux_n/p; q;} /./ { s/.*/$NO_SYS/p; q;} END sys_num= sys_version= sys_sub_version= sys_num=`uname -sr | sed -n -f $TMPDIR/os_opts` get_sys_versionsP # let the version number be for now, only change if asked for system test "X$sys_num" = "X" && sys_num=$NO_SYS # BSD has a printcap file but no lpadmin program if test $sys_num -eq $NO_SYS && test -f ${DEF_PRINTCAP} && test ! -x /usr/lib/lpadmin; then sys_num=$BSD_n fi # SCO UNIX cannot be found with the uname command if test $sys_num -eq $NO_SYS && test -f /boot; then grep "SCO " /boot > /dev/null test $? = 0 && sys_num=$SCO_n fi # SYSV has lpadmin and no printcap if test $sys_num -eq $NO_SYS && test -x /usr/lib/lpadmin && test ! -f ${DEF_PRINTCAP} ; then sys_num=$SYSV3_n test -f /etc/lp/Systems && sys_num=$SYSV4_n fi if test ! $sys_num -eq $NO_SYS; then case $sys_num in $SUN4_n) str=$SUN4_sys ;; $SUN5_n) str=$SUN5_sys ;; $AIX_n) str=$AIX_sys ;; $HPUX_n) str=$HPUX_sys ;; $BOS_n) str=$BOS_sys ;; $OSF1_n) str=$OSF1_sys ;; $ULTRIX_n) str=$ULTRIX_sys ;; $IRIX_n) str=$SGI_sys ;; $SCO_n) str=$SCO_sys ;; $SCO_WARE2_n) str=$SCO_WARE2_sys ;; $SCO_WARE7_n) str=$SCO_WARE7_sys ;; $SCO_OPEN_n) str=$SCO_OPEN_sys ;; $FreeBSD_n) str=$FreeBSD_sys ;; $Linux_n) str=$Linux_sys ;; $BSD_n) str=$BSD_sys ;; $SYSV3_n) str=$SYSV3_sys ;; $SYSV4_n) str=$SYSV4_sys ;; *) myexit 1 "Unknown system $sys_num" ;; esac echo echo "Your system is identified as being a $str" echo yes_or_noP "Is this correct" y test $yes_or_no = "NO" && sys_num=$NO_SYS fi if test $sys_num -eq $NO_SYS ; then cat << SYS_TYPE_END Which of the systems below are you running? ----------------------------------------------------- $SUN4_n....$SUN4_sys $SUN5_n....$SUN5_sys $AIX_n....$AIX_sys $HPUX_n....$HPUX_sys $BOS_n....$BOS_sys $OSF1_n....$OSF1_sys $ULTRIX_n....$ULTRIX_sys $SGI_n....$SGI_sys $SCO_n....$SCO_sys $SCO_WARE2_n...$SCO_WARE2_sys $SCO_WARE7_n...$SCO_WARE7_sys $SCO_OPEN_n...$SCO_OPEN_sys $FreeBSD_n...$FreeBSD_sys $Linux_n...$Linux_sys $BSD_n...$BSD_sys $SYSV3_n...$SYSV3_sys $SYSV4_n...$SYSV4_sys $NO_SYS....Quit this program ----------------------------------------------------- SYS_TYPE_END range_answerP " Enter choice" "[$NO_SYS-$MAX_SYS_n]" \ $NO_SYS sys_num=$range_answer if test $sys_num -eq $NO_SYS; then myexit 0 "Exit $FILE_NAME" fi get_sys_versionsP -i fi # SGI may have a BSD spooler as well if test $sys_num = $SGI_n; then if test -x /usr/etc/lpc -a -x /usr/bsd/lpr; then cat << SGI_BSD_END Your system seems to have BSD lpr spooler installed. Do you want to remove the printer from the BSD spool system or the SYS V spool system ? 1......Remove from SYS V spool system (lp print command). 2......Remove from BSD spool system (lpr print command). SGI_BSD_END class_answerP "Enter choice" '[1-2]' 1 if test $class_answer = 2; then sys_num=$BSD_n echo "Will use the BSD spool system" >> $instalog else echo "Will use the SYS V spool system" >> $instalog fi fi fi # --- Some default values stoplp=NO # Don't stop scheduler HPFIX=" " # If there should be space between lpadmin's options SHELL=/bin/sh # for the benefit of lpadmin. case $sys_num in $SUN4_n|$OSF1_n|$BSD_n) sys_family=bsd sys_type=bsd ;; $SUN5_n) # Sun OS 5.x sys_family=sysv sys_type=sysv4 ;; $AIX_n) # AIX (IBM AIX 3) sys_family=aix sys_type=aix ;; $HPUX_n) # HP-UX sys_family=sysv sys_type=sysv4 HPFIX= stoplp=YES ;; $BOS_n) # BOS (BULL DPX 2) sys_family=sysv sys_type=sysv3 HPFIX= stoplp=YES ;; $ULTRIX_n) # ULTRIX sys_family=bsd sys_type=bsd ;; $SGI_n) # SGI sys_family=sysv sys_type=sysv3 HPFIX= stoplp=YES ;; $FreeBSD_n|$Linux_n) # FreeBSD and Linux are generic BSD sys_family=bsd sys_type=bsd ;; $SYSV3_n|$SCO_n|$SCO_OPEN_n) # SYS V3, SCO, SCO OpenServer sys_family=sysv sys_type=sysv3 stoplp=YES ;; $SYSV4_n|${SCO_WARE2_n}|${SCO_WARE7_n}) # SYS V4, UnixWare 2 and 7 sys_family=sysv sys_type=sysv4 ;; $NO_SYS) # No system, exit myexit 0 "No system found, Exit $FILE_NAME" ;; *) # Other (unknown). myexit 1 "Unknown OS type ($sys_type)" ;; esac } # --- End of os_type_initP # --- extract_valueP $1 $2 [$3 [$4]] --------------------------------------- # --- Extract the value of option $2 in file $1 # --- Extracts B in a line like $2=B, stops on eol or ':' # --- $3 - optional assign chatacter, default '=' # --- $4 - optional character group for separator, default is ':' # the assign character should not be among the separators # If this option is given, then assign character must be given extract_valueP () { extract_value= ass='=' sep=':' test $# -ge 3 && ass=$3 test $# -eq 4 && sep=$4 cat <<- EOF > $TMPDIR/sed_bsd_pcap /$2[ ]\{0,\}$ass/ s/.*$2[ ]\{0,\}$ass\([^$sep]*\).*/\1/p EOF extract_value=`sed -n -f $TMPDIR/sed_bsd_pcap $1` myecho $extract_value } # --- End of extract_valueP # --- initilize -------------------------------------------------------------- # --- Initilize variables and temporary directory etc initilize() { PROD_TYPES=$PROD_TYPE"s" TMPDIR="/tmp/${FILE_NAME}.$$" PRINTCAP=/etc/printcap instalog="/tmp/${FILE_NAME}_$$.log" mkdir $TMPDIR umask 022 $clear cat << WELCOME_END ================================================================================ $FILE_NAME, version $REVISION. Welcome to the $PROD_TYPE installation and uninstallation program. This program will lead you through a procedure to install or uninstall $PROD_TYPES on your system. Installation requires that the IP address of your $PROD_TYPE is defined. Before installation or uninstallation of each printer you will be able to accept or reject the action. You can stop this program with the interrupt key at any time. An installation log will be saved in the file $instalog WELCOME_END def_cont='y' if test "X`id | tr '()' '::' | cut -f2 -d:`" != "Xroot"; then cat < $instalog << LOGMSG_END ====================== $PROD_TYPE installation log ========================== LOGMSG_END } # --- End of initilize # --- Check for needed programs check_programsP() { ftp_path=`which ftp` if test "X${ftp_path}" = "X"; then myexit 1 "ftp program could not be found" fi } # --- end of check_programsP # --- Simple prompt with default for a file path and name. # --- The path MUST begin with a / # --- Leave answer in variable path_answer. path_answer= path_answerP() # $1 is prompt string. # $2 is default answer. { path_answer= while true; do answerP "$1" "$2" path_answer=$answer case $path_answer in /*) # Valid path. break ;; *) # missing / at beginning. path_answer= ;; esac done } # --- lpshutP ----------------------------------------------------------------- lpshutP () { lpshut if test $sys_num -eq $HPUX_n; then while true; do test -f /usr/spool/lp/SCHEDLOCK if test $? != 0; then break fi done fi } # --- lpshutP # ============================================================================ # Installer Code # ============================================================================ # --- mult_answer $1 $2 [$3] ------------------------------------------------ # --- Prompt for one character in a list of characters. # --- $1 is prompt string. # --- $2 is allowed answer characters class, such as 'abft'. # --- $3 is optional default answer (must belong to class in $2). mult_answerP() { mult_answer= while true; do answerP "$1 [$2]" "$3" mult_answer=$answer test "X$mult_answer" = "X" && test $# -eq 3 && mult_answer=$3 mult_num=1 mult_loop=YES mult_found=NO # Loop through answer class to see if answer is valid while test $mult_loop = YES; do mult_char=`echo $2 | cut -c$mult_num` # cut after end of string results in empty string if test "X${mult_char}" = "X"; then mult_loop=NO elif test "X${mult_char}" = "X$mult_answer"; then mult_loop=NO mult_found=YES else mult_num=`expr 1 + $mult_num` fi done if test $mult_found = YES; then break # out of the while loop. fi done } # --- End of mult_answerP # --- Say not if the parameter = NO say_not() { test "X$1" = "XNO" && echo " NOT" } # --- Say y or n when $1 is YES or NO. say_y_or_n() { test "X$1" = "XYES" && echo y test "X$1" = "XNO" && echo n } # --- Say i or o when $1 is if or of. say_io() { test "X$1" = "Xif" && echo i test "X$1" = "Xof" && echo o } # --- Say in or out when $1 is if or of. say_in_or_out() { test "X$1" = "Xif" && echo input test "X$1" = "Xof" && echo output } # --- Test if we hawe write permission in the directory. has_permission() # $1 is path to test { if test ! -d $1; then has_permission `dirname $1`; return elif test -w $1; then true; return else false; return fi } # --- not do boolean negation on return value of . not() { if $*; then false; return else true; return fi } # --- ftp_downloadP $1 $2 $3 [$4] -------------------------------------------- # --- Download a file ($2/$3) from a host ($1), error returned in $ftp_download # --- $1 Host name # --- $2 Path name to file # --- $3 file name, relative to path # --- $4 Optional mode, bin as default ftp_downloadP () { ftp_mode='bin' test $# -eq 4 && ftp_mode=$4 $ftp -n $1 <<- FTP_END user anonymous void $ftp_mode cd $2 get $3 quit FTP_END ftp_download=$? } # --- End of ftp_downloadP # --- print_methodP $1 ------------------------------------------------------- # --- Prompt for the print method to use, first argument is the preferred. prompt_print_method= counter= # help function print_single_methodP () { print_single_method= if test $1 = YES && test "X$print_prefix" != "X$2"; then echo " $counter......$2" print_single_method=$counter counter=`expr $counter + 1` fi } prompt_print_methodP () { counter=1 # find out preferred method case $1 in lpd) print_prefix=LPD; lpd_method_num=$counter;; ftp) print_prefix=FTP; ftp_method_num=$counter;; prosa) print_prefix=PROSA; prosa_method_num=$counter;; prosb) print_prefix=PROSB; prosb_method_num=$counter;; *) myexit 1 "Print method not supported ($1)" ;; esac echo echo " ----------------" echo " $counter......$print_prefix" counter=`expr $counter + 1` # now scan methods one by one print_single_methodP $lpd_enabled LPD test "X$print_single_method" != "X" && lpd_method_num=$print_single_method print_single_methodP $ftp_enabled FTP test "X$print_single_method" != "X" && ftp_method_num=$print_single_method print_single_methodP $prosa_enabled PROSA test "X$print_single_method" != "X" && prosa_method_num=$print_single_method print_single_methodP $prosb_enabled PROSB test "X$print_single_method" != "X" && prosb_method_num=$print_single_method # counter is alwys one too much here counter=`expr $counter - 1` # Read which item that the user selects echo " ----------------" echo range_answerP " Enter choice" "[1-$counter]" 1 # Match the answer to a method case $range_answer in $lpd_method_num) prompt_print_method=lpd ;; $ftp_method_num) prompt_print_method=ftp ;; $prosb_method_num) prompt_print_method=prosB ;; $prosa_method_num) prompt_print_method=prosA ;; *) myexit 1 "Bad case in prompt_print_methodP: $range_answer" ;; esac } # --- prompt_print_methodP # --- set_rprinterP ---------------------------------------------------- # --- Set remote printer name, can set both logical and physical printer # --- names. If physical printer is set, $REM_HOST_PRINTER_NUM is set # --- to 0. If logical printer is set, $REM_HOST_PRINTER is set to # --- "pr${REM_HOST_PRINTER_NUM}" set_rprinterP () { echo echo "If you want to print using LPT1 with the default parameter values," echo "choose logical printer '1' for straight-through printing." echo "Choose '5' for printing with UNIX New Line to CR+LF conversion." echo "Choose '0' to set physical printer name, such as 'LPT1' or 'COM1'" echo range_answerP "Enter logical printer number" '[0-8]' $REM_HOST_PRINTER_NUM REM_HOST_PRINTER_NUM="$range_answer" if test $REM_HOST_PRINTER_NUM = '0' ; then if test "X$REM_HOST_PRINTER" = "X"; then REM_HOST_PRINTER="lpt1" fi answerP "Enter physical printer name" $REM_HOST_PRINTER REM_HOST_PRINTER=`strip $answer` else REM_HOST_PRINTER="pr${REM_HOST_PRINTER_NUM}" fi } # --- End of set_rprinterP # --- aix_get_colon_fileP ----------------------------------------------------- # --- Get Colon file name in AIX # --- Sets 'aix_printer' to printer type # --- 'aix_stream' to the data stream name and # --- 'aix_stream_desc' to a description of data stream # --- Colon files looks like 'printer.data', where printer is the printer # --- type and data is the printer data that is generated for that printer. # --- There may be several data types for each printer model. aix_get_colon_fileP () { savedir=`pwd` cd ${DEF_AIX_COLONDIR} # list all colon files, one at each line ls -1 > $TMPDIR/pio_list # Make a list of all printer models available and print four columns # Split fields on ".", parse the lines (one line per file) and # if the current file prefix (printer model) is the same as last one, # then don't print it. # This method ASSUMES SORTED OUTPUT from ls cat << 'AWK_END' > $TMPDIR/awk_get_unique BEGIN {name = ""; FS="."; nbr=0} { newn = $1 if (newn == name) next name = newn nbr++ printf "%18s", name if (nbr == 4) { print ""; nbr = 0} } END {print ""} AWK_END # Make a list of available data types for the printer # Split fields by ".", look at suffix of file and print # a description of the data type, along with what line # in the input file it is in. cat << 'AWK_END1' > $TMPDIR/awk_get_data BEGIN {name = ""; FS="."; nbr=0} { if ($2 ~ /^asc$/) { Desc = "Extended ASCII" } else if ($2 ~ /^ps$/) { Desc = "PostScript" } else if ($2 ~ /^pcl$/) { Desc = "Hewlett-Packard PCL" } else if ($2 ~ /^630$/) { Desc = "Diablo 630" } else if ($2 ~ /^855$/) { Desc = "Texas Instruments 855" } else if ($2 ~ /^gl$/) { Desc = "Hewlett-Packard GL" } else if ($2 ~ /^kji$/) { Desc = "Kanji" } else if ($2 ~ /^lips/) { Desc = "Canon LIPS" } else { Desc = "Unknown" } printf (" %s: %25s (%s)\n", NR, Desc, $0); } AWK_END1 while true; do $clear cat </dev/null > $TMPDIR/chosen_model # What is the line number of the last data stream? last_num=`sed -n -e '$ =' $TMPDIR/chosen_model` last_num=`strip $last_num` # Make a list of valid data streams awk -f $TMPDIR/awk_get_data $TMPDIR/chosen_model > $TMPDIR/stream_list # Find out which number that the default stream type has def_stream=`grep ${aix_stream} $TMPDIR/stream_list | cut -d':' -f1` def_stream=`strip ${def_stream}` echo echo " Available data streams:" echo " --------------------------------------------" cat $TMPDIR/stream_list echo " --------------------------------------------" echo range_answerP " Number of data stream" "[1-$last_num]" \ ${def_stream} aix_stream_nbr=${range_answer} # Get the file name on line $aix_stream_nbr - this is the # colon file name aix_colon_file=`sed -n -e "$aix_stream_nbr p" $TMPDIR/chosen_model` # Trick to get description of data stream, run the printer through # the script above and then extract the stream type aix_stream_desc=`echo "${aix_colon_file}"|awk -f $TMPDIR/awk_get_data"` aix_stream_desc=`echo ${aix_stream_desc} |cut -d':' -f2 |cut -d'(' -f1` if test -f ${DEF_AIX_COLONDIR}/${aix_colon_file}; then break else echo "No such colon file - ${aix_colon_file}" fi fi echo "Press enter to proceed" read dummyplug done aix_stream=`echo ${aix_colon_file} | cut -f2 -d"."` aix_printer=`echo ${aix_colon_file} | cut -f1 -d"."` cd $savedir } # --- aix_get_colon_fileP # --- sysv_set_model_nameP $1 ------------------------------------------------- # --- Ask user for model to use and use $1 as default sysv_set_model_nameP () { sysv_set_model_name=$1 while true; do answerP "Enter model script name (? to list models)" $1 model_answer=$answer if test "X$model_answer" = "X?"; then $clear cat < $ftp_err 1> $ftp_msg quit TEST_FTP_END err=`cat $ftp_err` msg=`grep -i "${PROD_TYPE}" $ftp_msg` if test "X${err:+mumble}" != "X"; then more_changes=YES echo "The $PROD_TYPE \"$REM_HOST_NAME\" is not responding" echo "Check your host table" elif test "X${msg:+mumble}" = "X"; then # --- New ftp login did not work, try the old one msg=`grep -i "FTP Printer Server " $ftp_msg` if test "X${msg:+mumble}" = "X"; then more_changes=YES echo "The host \"$REM_HOST_NAME\" is not recognized as a $PROD_TYPE" echo "Check your host table" fi fi rm $ftp_err $ftp_msg if test $more_changes != "YES"; then case $sys_family in # CASE BSD bsd) if test $create_spooldir = YES && test -d $SPOOLDIR; then echo "The spool directory $SPOOLDIR already exists" yes_or_noP "Do you want to use the existing spool directory" n if test $yes_or_no = YES; then create_spooldir=NO else more_changes=YES myecho "Please choose another spool directory." fi fi if test $create_logfile = YES && test -f $LOGFILE; then echo "The log file $LOGFILE already exists" yes_or_noP "Do you want to use the existing log file" n if test $yes_or_no = YES; then create_logfile=NO else myecho "Please choose another log file." more_changes=YES fi fi if test -f $PRINTCAP; then sedcmd="/^$PRINTER|.*:/p;/^.*|$PRINTER|.*:/p;/^.*|$PRINTER:/p" pcap_entry=`sed -n -e $sedcmd $PRINTCAP` if test ! -w $PRINTCAP; then echo "No permission to modify the printcap file $PRINTCAP." more_changes=YES edit_pcap=NO elif test X${pcap_entry:+mumble} != X; then echo "There is already an entry in the $PRINTCAP file for \ $PRINTER." echo "The $PRINTCAP file will NOT be modified" more_changes=YES edit_pcap=NO else edit_pcap=YES fi elif test $create_pcap = NO; then echo echo "The $PRINTCAP file does not exists." yes_or_noP "Do you want to create the $PRINTCAP file" n create_pcap=$yes_or_no if test $create_pcap = YES; then if has_permission `dirname $PRINTCAP`; then edit_pcap=YES else echo "No permission to create printcap file $PRINTCAP." create_pcap=NO more_changes=YES fi fi fi # create_pcap ;; # CASE SYSV sysv) printer_exists=`/usr/bin/lpstat -p | grep $PRINTER 2> /dev/null` if test "X${printer_exists}" != "X"; then echo "Printer $PRINTER is already present in the system" more_changes=YES fi ;; # CASE AIX aix) qchk -P$PRINTER 2> /dev/null 1> /dev/null if test $? = 0; then echo "Printer $PRINTER is already present in the system" more_changes=YES fi if test ! -f $DEF_AIX_COLONDIR/$aix_printer.$aix_stream; then echo "Printer Colon File \ $DEF_AIX_COLONDIR/$aix_printer.$aix_stream not present." more_changes=YES fi ;; esac # Case system fi # test $more_changes if test $more_changes != "YES"; then case $print_method in prosA) method_dir_str="PROS daemon" ;; prosB) method_dir_str="PROS filter" ;; ftp) method_dir_str="FTP filter" ;; esac if test $create_proshome = YES && not has_permission `dirname $PROSHOME`; then myecho "No permission to create the $method_dir_str directory \ $PROSHOME" create_proshome=NO more_changes=YES fi # $create_proshome = YES && not has_permission ... fi # test $more_changes if test $more_changes != "YES"; then if test $create_prosdev = YES && test -p $PROSDEV; then echo "The pros daemon pipe $PROSDEV already exists" yes_or_noP "Do you want to use the existing pipe" n if test $yes_or_no = YES; then create_prosdev=NO else more_changes=YES myecho "Please choose another pipe name." fi fi if test $create_prosdev = YES && \ not has_permission `dirname $PROSDEV` ; then echo "No permission to create the pipe $PROSDEV" create_prosdev=NO more_changes=YES fi # test $create_prosdev fi # test $more_changes if test $more_changes != "YES"; then if test $create_proslog = YES && test -f $PROSLOG &&\ test $more_changes != "YES"; then echo "The pros log file $PROSLOG already exists" yes_or_noP "Do you want to use the existing pros log file" n if test $yes_or_no = YES; then create_proslog=NO else myecho "Please choose another log file." more_changes=YES fi fi # test $create_proslog = YES && test -f $PROSLOG if test $create_proslog = YES && not has_permission `dirname $PROSLOG`; then echo "No permission to create the pros log file $PROSLOG" create_proslog=NO more_changes=YES fi fi # test $more_changes if test $compile_pros = YES && test $more_changes != "YES"; then case $print_method in prosA) if test -f $PROSHOME/prosd; then echo "The PROS daemon in directory $PROSHOME already exists" yes_or_noP "Do you want to use the existing PROS daemon" y if test $yes_or_no = YES; then compile_pros=NO else myecho "Please choose another directory for the daemon." more_changes=YES fi fi ;; prosB) FILTER_NAME=`eval $DEF_PROSB_FILE_EVAL` if test -f ${PROSHOME}/${FILTER_NAME}; then echo "The PROS filter ${FILTER_NAME} in directory $PROSHOME ," echo "already exists; remove it or choose another printer name." more_changes=YES fi # In AIX, one prosb filter can be used by many printers, therefore # the user should be able to use that filter or update it # if it has become old if test -f $PROSHOME/prosaix; then echo "The PROSB filter help program $PROSHOME/prosaix is used " echo "by all prosb filters. If you want, you can update the" echo "program, but this might effect all your printers." echo "A backup will be put in /tmp/prosaix.$PRINTER." echo yes_or_noP "Do you wish to update the program" y if test $yes_or_no = YES; then compile_pros=YES cp $PROSHOME/prosaix $TMPDIR/prosaix.$printer else myecho "Please choose another filter directory." more_changes=YES fi fi ;; ftp) FILTER_NAME=`eval ${DEF_FTP_FILE_EVAL}` if test -f ${PROSHOME}/${FILTER_NAME}; then echo "The FTP filter ${FILTER_NAME} in directory $PROSHOME " echo "already exists; remove it or choose another printer name." more_changes=YES compile_pros=NO fi ;; esac fi # test $compile_pros if test $more_changes = NO; then echo "No conflicts found" fi } # --- check_setupP # --- install_initP ----------------------------------------------------------- install_initP () { if test "X$ftp" = "X"; then echo "Cannot find your FTP program." path_answerP "Please enter the full path name of your FTP program: " ftp=$path_answer if test "X$ftp" = "X"; then myexit 1 "Cannot install without FTP program." fi echo fi if test "X$HOSTNAME" = "X"; then echo "Cannot find out the network name of this host." answerP "Please enter host name: " HOSTNAME=$answer if test "X$HOSTNAME" = "X"; then myexit 1 "Cannot install any network utilities without a host name." fi echo fi # by default, all print methods are enabled lpd_enabled=YES ftp_enabled=YES prosa_enabled=YES prosb_enabled=YES # set system family options case $sys_family in sysv) filt_name=sysv ;; bsd) filt_name=bsd # ULTRIXFIX is used by all BSD systems, but only some set it. ULTRIXFIX= ;; aix) filt_name=piobe prosa_enabled=NO ;; *) myexit 1 "Bad case in system family, $sys_family" ;; esac # set standard model name MODEL= case $sys_num in $SUN5_n|$SYSV3_n|$SCO_n|$SYSV4_n) DEF_MODEL="standard" ;; $HPUX_n|$BOS_n|$SGI_n) DEF_MODEL="dumb" ;; esac # other things, specific to odd systems case $sys_num in $ULTRIX_n) # ULTRIX # A line in the printcap entry for PROS A (OBS no ":" here). ULTRIXFIX="of=xf" ;; $FreeBSD_n) # FreeBSD $mknod=mkfifo ;; esac # test mkfifo or mknod for prosa availability case $sys_num in $FreeBSD_n) $mknod ${TMPDIR}/nisse p 2>/dev/null if test $? != 0; then prosa_enabled=NO echo echo " Your system does not support FIFOs, PROS A cannot be used." fi rm ${TMPDIR}/nisse ;; $SUN5_n) if test $sys_sub_version -lt 5; then prosa_enabled=NO fi esac # Only OpenServer has a bsd spooler for LPD in a sysv3 system sysv3_bsd_lpd=NO # Sysv3 does not have lpd if test $sys_type = sysv3; then # But SCO OpenServer has a BSD spooler for LPD sometimes... if test $sys_num -eq $SCO_OPEN_n && test -f $PRINTCAP; then sysv3_bsd_lpd=YES else lpd_enabled=NO fi fi saved_pcap=NO # Not saved yet. REM_HOST_NAME= PROSHOME= } # --- install_initP # --- install_init_methodP ---------------------------------------------------- # --- Set common variables that depends on the printing method install_init_methodP () { # --- Common variables. # REM_HOST_NAME & PROSHOME are initialized outside more_printers loop # so we remember their values. REM_HOST_PRINTER_NUM=1 PRINTER= SPOOLDIR= # BSD only LOGFILE= # BSD only PRINTCAP=${DEF_PRINTCAP} # BSD only PROSDEV= PROSLOG= PROSPWD=netprinter # Neither asked for nor changed. MODEL= # --- Common control variables. case $sys_family in bsd) create_pcap=NO edit_pcap=YES create_spooldir=YES create_logfile=YES ;; sysv) create_pcap=NO edit_pcap=NO create_spooldir=NO create_logfile=NO printer_content=any printer_ptypes=unknown ;; aix) create_pcap=NO edit_pcap=NO create_spooldir=NO create_logfile=NO aix_data_type=1 if test $sys_version -eq 4; then aix_printer="generic" else aix_printer="printer" fi aix_stream="asc" ;; esac # --- Print method specific control variables. case $print_method in prosA) compile_pros=YES create_proshome=YES create_proslog=YES create_prosdev=YES start_prosd=YES MODEL=${DEF_MODEL} ;; prosB) compile_pros=YES create_proshome=YES create_proslog=NO if test $sys_family = aix; then aix_log_mode=$DEF_AIX_LOG_MODE fi create_prosdev=NO start_prosd=NO if_or_of=of ;; ftp) compile_pros=YES create_proshome=YES create_proslog=NO create_prosdev=NO start_prosd=NO if_or_of=of ;; lpd) compile_pros=NO create_proshome=NO create_proslog=NO create_prosdev=NO start_prosd=NO if test $sys_num -eq $HPUX_n && test -f ${DEF_MODELDIR}/rmodel.asx then MODEL=${DEF_MODEL} fi ;; esac } # --- install_init_methodP # --- bsd_install_printerP ----------------------------------------------------- bsd_install_printerP () { if test $create_pcap = YES; then if test ! -d `dirname $PRINTCAP`; then mkdir -p `dirname $PRINTCAP` test $? != 0 && error=YES fi cat <<- PCAP_HEADER_END > $PRINTCAP # --- This printcap was created by the $PROD_TYPE installation script. --- # PCAP_HEADER_END test $? != 0 && error=YES else # test $create_pcap != YES # --- It is wise to save the printcap. saved_pcap_file=/tmp/$$_saved_pcap cp $PRINTCAP $saved_pcap_file test $? != 0 && error=YES logg "saved file $PRINTCAP in file $saved_pcap_file." fi # test $create_pcap = YES if test $edit_pcap = YES ; then logg -n "Modifying printcap file $PRINTCAP, " logg "installed following printcap entry:" logg case $print_method in prosA) # PROS A cat <<- PROSA_PCAP_ENTRY_END | $tee -a $PRINTCAP >> $instalog $PRINTER| Network printer on $REM_HOST_NAME using PROS A:\\ :lp=$PROSDEV:\\ :sd=$SPOOLDIR:\\ :lf=$LOGFILE:\\ :$ULTRIXFIX:\\ :sh: PROSA_PCAP_ENTRY_END test $? != 0 && error=YES ;; prosB) # PROS B cat <<- PROSB_PCAP_ENTRY_END | $tee -a $PRINTCAP >> $instalog $PRINTER| Network printer on $PROD_TYPE $REM_HOST_NAME using PROS B:\\ :lp=$SPOOLDIR/null:\\ :sd=$SPOOLDIR:\\ :lf=$LOGFILE:\\ :$if_or_of=$PROSHOME/${FILTER_NAME}:\\ :ff=\\r\\f:\\ :sh: PROSB_PCAP_ENTRY_END test $? != 0 && error=YES ;; ftp) # FTP cat <<- FTP_PCAP_ENTRY_END | $tee -a $PRINTCAP >> $instalog $PRINTER| Network printer on $PROD_TYPE $REM_HOST_NAME using FTP:\\ :lp=$SPOOLDIR/null:\\ :sd=$SPOOLDIR:\\ :lf=$LOGFILE:\\ :of=${PROSHOME}/${FILTER_NAME}:\\ :ff=\\r\\f:\\ :sh: FTP_PCAP_ENTRY_END test $? != 0 && error=YES ;; lpd) # LPD cat <<- LPD_PCAP_ENTRY_END | $tee -a $PRINTCAP >> $instalog $PRINTER| Network printer on $PROD_TYPE $REM_HOST_NAME:\\ :lp=:\\ :sd=$SPOOLDIR:\\ :lf=$LOGFILE:\\ :rm=$REM_HOST_NAME:\\ :rp=$REM_HOST_PRINTER: LPD_PCAP_ENTRY_END test $? != 0 && error=YES ;; esac logg fi if test $create_spooldir = YES; then mkdir -p $SPOOLDIR test $? != 0 && error=YES logg "Created spool directory $SPOOLDIR." if test $sys_type = freebsd; then chown bin $SPOOLDIR chmod 744 $SPOOLDIR fi case $print_method in prosB|ftp) # PROS B and FTP need dummy devices. touch $SPOOLDIR/null test $? != 0 && error=YES logg "Created dummy device $SPOOLDIR/null." if test $sys_num -eq $FreeBSD_n ; then chown bin $SPOOLDIR/null chmod 744 $SPOOLDIR/null fi ;; esac fi if test $create_logfile = YES; then if not test -d `dirname $LOGFILE`; then mkdir -p `dirname $LOGFILE` test $? != 0 && error=YES logg "Created directory `dirname $LOGFILE`." if test $sys_num -eq $FreeBSD_n ; then chown bin `dirname $LOGFILE` chmod 744 `dirname $LOGFILE` fi fi touch $LOGFILE test $? != 0 && error=YES logg "Created log file $LOGFILE." if test $sys_num -eq $FreeBSD_n; then chown bin $LOGFILE chmod 744 $LOGFILE fi fi } # --- bsd_install_printerP # --- sysv_install_printerP ---------------------------------------------------- sysv_install_printerP () { test $stoplp = YES && lpshutP if test $sys_num -eq $BOS_n; then logg "Modifying /etc/config.lp with the following entries:" fi case $print_method in prosA) lpadmin -p$HPFIX$PRINTER -m$HPFIX$MODEL -v$HPFIX$PROSDEV 2>> $instalog if test $? != 0; then lperror=YES else lperror=NO logg "installed $PRINTER with lpadmin using "$MODEL\ " model on device $PROSDEV." fi if test $sys_num -eq $BOS_n; then cat <<- PROSA_BOS_ENTRY_END | tee -a /etc/config.lp >> $instalog $PRINTER on $CAT_NAME $REM_HOST_NAME.$REM_HOST_PRINTER - m $MODEL - - - - PROSA_BOS_ENTRY_END fi ;; prosB) lpadmin -p$HPFIX$PRINTER -i$HPFIX$PROSHOME/${FILTER_NAME} \ -v$HPFIX/dev/null 2>> $instalog if test $? != 0; then lperror=YES else lperror=NO logg "installed $PRINTER with lpadmin using interface \ $PROSHOME/${FILTER_NAME}." logg "device used is /dev/null (dummy device)." fi if test $sys_num -eq $BOS_n; then cat <<- PROSB_BOS_ENTRY_END | tee -a /etc/config.lp >> $instalog $PRINTER on $CAT_NAME null - i $PROSHOME/${FILTER_NAME} - - - - PROSB_BOS_ENTRY_END fi ;; ftp) lpadmin -p$HPFIX$PRINTER -i$HPFIX$PROSHOME/${FILTER_NAME} \ -v$HPFIX/dev/null 2>> $instalog if test $? != 0; then lperror=YES else lperror=NO logg "installed $PRINTER with lpadmin using interface \ $PROSHOME/${FILTER_NAME}." logg "device used is /dev/null (dummy device)." fi if test $sys_num -eq $BOS_n; then cat <<- FTP_BOS_ENTRY_END | tee -a /etc/config.lp >> $instalog $PRINTER on $CAT_NAME null - i $PROSHOME/${FILTER_NAME} - - - - FTP_BOS_ENTRY_END fi ;; lpd) if test $sys_num -ne $HPUX_n; then lpsystem -t bsd $REM_HOST_NAME >> $instalog if test $? != 0; then lperror=YES else lperror=NO logg "used lpsystem to add(modify) an entry for $REM_HOST_NAME" logg "in /etc/lp/Systems" fi fi if test $sys_num -eq $HPUX_n; then if test ${HP_LPDMODEL} = "rmodel.asx"; then logg "Copying ${DEF_MODELDIR}/${MODEL} to " \ "${DEF_HP_LPDMODELDIR}/${PRINTER}" # Put model in remote model directory (HP_UX 10.20) cp ${DEF_MODELDIR}/${MODEL} ${DEF_HP_LPDMODELDIR}/${PRINTER} chmod 755 ${DEF_HP_LPDMODELDIR}/${PRINTER} >/dev/null chgrp lp ${DEF_HP_LPDMODELDIR}/${PRINTER} >/dev/null chown lp ${DEF_HP_LPDMODELDIR}/${PRINTER} >/dev/null fi lpadmin -p$HPFIX$PRINTER \ -v$HPFIX/dev/null \ -orm$HPFIX$REM_HOST_NAME \ -orp${HPFIX}${REM_HOST_PRINTER} \ -m$HPFIX${HP_LPDMODEL} \ >> $instalog elif test $sys_num -eq $SUN5_n && test $sys_sub_version -ge 6; then # Solaris 2.6 and higher uses the netstandard script lpadmin -p$HPFIX$PRINTER \ -i$HPFIX/usr/lib/lp/model/netstandard \ -v${HPFIX}/dev/null \ -o${HPFIX}protocol=bsd \ -o${HPFIX}dest=$REM_HOST_NAME:${REM_HOST_PRINTER} \ >> $instalog else lpadmin -p$HPFIX$PRINTER \ -s$HPFIX$REM_HOST_NAME!$REM_HOST_PRINTER >> $instalog fi if test $? != 0; then lperror=YES else lperror=NO logg "installed $PRINTER with lpadmin using remote system" \ "name $REM_HOST_NAME and" logg " remote printer name $REM_HOST_PRINTER" fi ;; esac # Add content-type any to printers, except in HP-UX if test $sys_num != $HPUX_n && test $sys_type = sysv4; then logg "Contents type=${printer_content}, printer type=${printer_ptypes}" /usr/lib/lpadmin -p$HPFIX$PRINTER -I${HPFIX}${printer_content} \ -T${HPFIX}${printer_ptypes} 2>&1 | tee -a ${instalog} # add possibility for user to use -o banner when printing logg "Adding nobanner option" /usr/lib/lpadmin -p$HPFIX$PRINTER -o${HPFIX}nobanner \ 2>&1 | tee -a ${instalog} fi # nobanner does not work in Solaris 2.6, fix in config file if test -f /etc/lp/printers/$PRINTER/configuration; then cat < ${TMPDIR}/ed_tmp /Banner:/ s/on/off/ w q EOF lecho "Edited /etc/lp/printers/$PRINTER/configuration" ed -s /etc/lp/printers/$PRINTER/configuration < ${TMPDIR}/ed_tmp rm ${TMPDIR}/ed_tmp fi test $stoplp = YES && lpsched # No accept, enable for SunOS 5.6 or higher # Yes, if we change to netstandard # if test ! \( $print_method = lpd -a \ # $sys_num -eq $SUN5_n -a $sys_sub_version -ge 6 \);then test $lperror = NO && accept $PRINTER test $lperror = NO && enable $PRINTER # fi test $lperror = YES && error=YES } # --- sysv_install_printerP # --- aix_install_printerP aix_install_printerP () { test $print_method = prosB && print_method=pros case $print_method in pros | ftp) ln /dev/null /dev/$PRINTER'd' if test $? = 0; then logg "linked printer device /dev/"$PRINTER"d to /dev/null" else error=YES fi if test $error = NO; then mkque -q $PRINTER if test $? = 0; then logg "used mkque, local queue is "$PRINTER else logg "mkque did not work." error=YES rm /dev/$PRINTER'd' fi fi if test $error = NO; then mkquedev -d $PRINTER'd' -q $PRINTER \ -a 'backend = '$PROSHOME'/'$print_method'_'$PRINTER'' if test $? = 0; then logg "used mkquedev, created queue device "$PRINTER"d" logg " backend is "$PROSHOME"/"$print_method"_"$PRINTER else logg "mkquedev did not work." error=YES rm /dev/$PRINTER'd' rmque -q $PRINTER fi fi if test $error = NO; then mkvirprt -d $PRINTER'd' -n $PRINTER'd' -q $PRINTER \ -s $aix_stream -t $aix_printer if test $? = 0; then logg "used mkvirprt, created virtual printer $PRINTER" logg " data stream type $aix_stream, printer type $aix_printer" else logg "mkvirprt did not work." error=YES rm /dev/$PRINTER'd' rmquedev -q $PRINTER -d $PRINTER'd' rmque -q $PRINTER fi fi ;; lpd) mkque -q$PRINTER -a"up = "'TRUE' -a"host = "$REM_HOST_NAME\ -a"s_statfilter = "'/usr/lpd/bsdshort'\ -a"l_statfilter = "'/usr/lpd/bsdlong'\ -a"rq = "$REM_HOST_PRINTER if test $? = 0; then logg "used mkque:, created remote printer queue $PRINTER" logg " destination host is $REM_HOST_NAME" logg " remote queue is "$REM_HOST_PRINTER mkquedev -q$PRINTER -d$PRINTER'd'\ -a"backend = "'/usr/lpd/rembak' if test $? = 0; then logg "used mkquedev, created printer queue device "$PRINTER"d" else logg "mkquedev did not work." rmque -q $PRINTER error=YES fi else logg "mkque did not work." error=YES fi ;; esac } # aix_install_printerP # --- install_prosAP ----------------------------------------------------------- install_prosAP () { ftp_downloadP $REM_HOST_NAME npipe prosd.c test $ftp_download != 0 && error=YES # --- Compilatilon of prosd differ from BSD to SYSV, and even # --- worse, it differ from one SYSV to another. # If gcc exists, use it CC=cc gcc -v 1> /dev/null 2>&1 test $? = 0 && CC=gcc case $sys_family in bsd) $CC $ALWAYS_OPEN $LINK_OPT -o prosd prosd.c if test $? != 0; then error=YES start_prosd=NO else cat <<- BSD_LOGNOTE_END | cat >> $instalog Compiled prosd in directory $PROSHOME. If you want the PROS daemon to start automatically at system reboot then add the following line to /etc/rc.local: $PROSHOME/prosd $prosd_options 2> $PROSLOG 1>&2 & BSD_LOGNOTE_END fi ;; sysv) compile_error=FirstTime altlist=" : -lsocket : -lsocket -lnsl : -linet " num_alts=4 counter=1 while test $compile_error != NO -a $counter -le $num_alts; do # --- Select one alternative of load libraries. LOADLIBES=`echo $altlist | cut -f$counter -d\:` echo "Compiling..." # --- First make a try with load libraries after source # --- and if that fail then try with them before source. $CC -o prosd prosd.c $LOADLIBES 2> /dev/null if test $? != 0; then $CC -o prosd $LOADLIBES prosd.c 2> /dev/null if test $? != 0; then compile_error=YES else compile_error=NO fi else compile_error=NO fi counter=`expr $counter + 1` done if test $compile_error != NO; then error=YES start_prosd=NO else cat <<- SYSV_LOGNOTE_END | cat >> $instalog Compiled prosd in directory $PROSHOME. If you want the PROS daemon to start automatically at system reboot then add the following line to /etc/inittab: id01::respawn:$PROSHOME/prosd $prosd_options 2> $PROSLOG 1>&2 Note! The ID string 'id01' must be four (4) characters long and individual for every entry in /etc/inittab. On some systems, the /etc/inittab file is recreated each time the system is booted, erasing the entries you just added. To cure this problem, put the added lines in a separate file in the /etc/conf/init.d directory as well. Any file name will do, such as /etc/conf/init.d/printer-init. SYSV_LOGNOTE_END fi ;; esac } # --- install_prosAP # --- install_prosBP ----------------------------------------------------------- install_prosBP () { ftp_downloadP $REM_HOST_NAME $sys_family pros$sys_family.c test $ftp_download != 0 && error=YES # If gcc exists, use it CC=cc gcc -v 1> /dev/null 2>&1 test $? = 0 && CC=gcc case $sys_family in bsd) CFLAGS="-DHOSTNAME=\"$HOSTNAME\" \ -DBOXNAME=\"$REM_HOST_NAME\" \ -DPRINTERNAME=\"$REM_HOST_PRINTER\"" $CC $CFLAGS -o ${FILTER_NAME} prosbsd.c test $? != 0 && error=YES ;; sysv) CFLAGS="-DHOSTNAME=\"$HOSTNAME\" \ -DBOXNAME=\"$REM_HOST_NAME\" \ -DPRINTERNAME=\"$REM_HOST_PRINTER\"" compile_error=FirstTime altlist=" : -lsocket : -lsocket -lnsl : -linet " num_alts=4 counter=1 while test $compile_error != NO -a $counter -le $num_alts; do # --- Select one alternative of load libraries. LOADLIBES=`echo $altlist | cut -f$counter -d\:` echo "Compiling..." # --- First make a try with load libraries after source # --- and if that fail then try with them before source. $CC -o ${FILTER_NAME} $CFLAGS prossysv.c $LOADLIBES \ 2> /dev/null if test $? != 0; then $CC -o ${FILTER_NAME} $CFLAGS $LOADLIBES prossysv.c \ 2> /dev/null if test $? != 0; then compile_error=YES else compile_error=NO fi else compile_error=NO fi counter=`expr $counter + 1` done test $compile_error != NO && error=YES ;; aix) $CC -o prosaix -DTRY_FOREVER prosaix.c ftp_downloadP $REM_HOST_NAME $sys_family pros_piobe PROSPATH=$PROSHOME"/prosaix" sedcmd="/^internet_address=.*/s/.*/internet_address=$REM_HOST_NAME/" sedcmd="$sedcmd;/^logical_printer=.*/ \ s/.*/logical_printer=$REM_HOST_PRINTER/" sedcmd="$sedcmd;/^pros_path=.*/s+.*+pros_path=$PROSPATH+" sedcmd="$sedcmd;/^hostname=.*/s/.*/hostname=$HOSTNAME/" sedcmd="$sedcmd;/^logfile=.*/s+.*+logfile=$PROSLOG+" sed -e "$sedcmd" pros_piobe > ${FILTER_NAME} test $? != 0 && error=YES rm -f pros_piobe chmod 755 ${FILTER_NAME} logg "Placed ${FILTER_NAME} in directory $PROSHOME." ;; esac rm -f pros${sys_family}.c if test $sys_family = aix; then logg "Compiled pros${sys_family} in directory $PROSHOME." else logg "Compiled ${FILTER_NAME} in directory $PROSHOME." fi } # --- install_prosBP # --- install_ftpP ------------------------------------------------------------- install_ftpP () { ftp_downloadP $REM_HOST_NAME $sys_family ftp_$filt_name test $ftp_download != 0 && error=YES # Patch ftp filter with binary grep "binary" ftp_$filt_name > /dev/null if test $? != 0; then ed ftp_$filt_name <<- ED_END > /dev/null 1 /^user/a binary . w q ED_END fi ftp_path=`which ftp` ftp_path=`strip ${ftp_path}` if test "X${ftp_path}" = "X"; then myexit 1 "Could not find ftp program" fi sedcmd="/^internet_address=.*/ s/.*/internet_address=$REM_HOST_NAME/" sedcmd="$sedcmd;/^logical_printer=.*/ \ s/.*/logical_printer=$REM_HOST_PRINTER/" sedcmd="$sedcmd;/^ftp_path=.*/s+.*+ftp_path=${ftp_path}+" sed -e "$sedcmd" ftp_$filt_name > ${FILTER_NAME} test $? != 0 && error=YES rm -f ftp_$filt_name chmod 755 ${FILTER_NAME} # rwx r-x r-x logg "Placed ${FILTER_NAME} in directory $PROSHOME." } # --- install_ftpP # --- compile_prosP ------------------------------------------------------------ compile_prosP () { if test $create_proshome = YES -a ! -f $PROSHOME; then mkdir -p $PROSHOME test $? != 0 && error=YES logg "Created directory $PROSHOME." fi prosd_options="$HOSTNAME $PROSDEV $REM_HOST_NAME $REM_HOST_PRINTER $PROSPWD" pwd=`pwd`; cd $PROSHOME case $print_method in prosA) install_prosAP ;; prosB) install_prosBP ;; ftp) install_ftpP ;; *) myexit 1 "compile_prosP: Unknown print method." esac cd $pwd } # --- compile_prosP # --- create_proslogP --------------------------------------------------------- create_proslogP () { case $print_method in prosA) logsource="pros daemon" ;; prosB) logsource="pros filter" ;; ftp) logsource="ftp filter" ;; esac if test ! -d `dirname $PROSLOG`; then mkdir -p `dirname $PROSLOG` test $? != 0 && error=YES logg "Created $logsource log file directory `dirname $PROSLOG`. " fi touch $PROSLOG test $? != 0 && error=YES logg "Created $logsource log file $PROSLOG." if test $sys_family = aix; then chmod 666 $PROSLOG fi } # --- create_proslogP # --- create_prosdevP ---------------------------------------------------------- create_prosdevP () { if test ! -d `dirname $PROSDEV`; then mkdir -p `dirname $PROSDEV` test $? != 0 && error=YES logg "Created prosd pipe directory `dirname $PROSDEV`. " fi if test $sys_num -ne $FreeBSD_n; then $mknod $PROSDEV p else mkfifo $PROSDEV fi test $? != 0 && error=YES case $sys_family in bsd) chmod 660 $PROSDEV # rw- rw- --- ;; sysv) chmod 600 $PROSDEV # rw- --- --- chown lp $PROSDEV ;; esac logg "Made prosd pipe $PROSDEV." } # --- create_prosdevP # --- start_prosdP ------------------------------------------------------------ start_prosdP () { prosd_options="$HOSTNAME $PROSDEV $REM_HOST_NAME $REM_HOST_PRINTER $PROSPWD" nohup $PROSHOME/prosd $prosd_options 2> $PROSLOG 1>&2 & test $? != 0 && error=YES cat <<- PROSD_LOGNOTE_END | cat >> $instalog Started prosd in directory $PROSHOME for device $PROSDEV with command: nohup $PROSHOME/prosd $prosd_options 2> $PROSLOG 1>&2 & PROSD_LOGNOTE_END if test $sys_family=sysv; then cat <<- PROSD_SYSV_STRT_END | cat >> $instalog If you want the PROS daemon to start automatically at system reboot then add the following line to /etc/inittab: id01::respawn:$PROSHOME/prosd $prosd_options 2> $PROSLOG 1>&2 PROSD_SYSV_STRT_END fi echo "Started prosd for device $PROSDEV." echo "See log file for more information." # --- Install the prosd startup line in /etc/inittab and place a # --- line in /etc/conf/init.d/$CAT_NAME-init. } # --- start_prosdP # --- install_printerP --------------------------------------------------------- # --- Install the specified printer. install_printerP () { logg " ========================= Install $PRINTER ========================" echo "Installing printer $PRINTER..." # compile_pros is YES for prosB, prosA and ftp test $compile_pros = YES && compile_prosP test $create_proslog = YES && create_proslogP test $create_prosdev = YES && create_prosdevP test $start_prosd = YES && start_prosdP case $sys_family in bsd) bsd_install_printerP ;; sysv) sysv_install_printerP ;; aix) aix_install_printerP ;; esac logg if test $error = NO; then lecho "Installation of printer $PRINTER done." echo yes_or_noP "Do you want a test printout" y if test $yes_or_no = YES; then case $sys_family in bsd) echo | tr '\012' '\014' | cat $instalog - | lpr -P$PRINTER ;; sysv) echo | tr '\012' '\014' | cat $instalog - | lp -d$HPFIX$PRINTER ;; aix) echo | tr '\012' '\014' | cat $instalog - | qprt -P$PRINTER ;; esac fi else lecho "Installation of printer $PRINTER FAILED." fi logg " ==================== Finished install $PRINTER ===================" logg echo # Not to log file } # --- install_printerP # --- main_install ----------------------------------------------------------- main_install () { # Init some system dependent and other variables install_initP saved_sys_type=$sys_type more_printers=YES while test $more_printers = "YES"; do echo echo "Select a print method from the list below." # Make sure that we reset sys_type here, it might be set to # something else in some cases below. sys_type=$saved_sys_type case $sys_type in sysv4|bsd|aix) echo "The recommended basic print method is LPD, for more advanced " echo "functionality and status feedback use PROS." prompt_print_methodP lpd ;; sysv3) echo "The recommended basic print method is FTP, for more advanced " echo "functionality and status feedback use PROS." prompt_print_methodP ftp ;; *) myexit 1 "Unknown system type when selecting preferred print method" esac print_method=$prompt_print_method # Pretend that it is a BSD system if it is a sysv3 system with bsd spool if test $print_method = lpd && test ${sysv3_bsd_lpd} = YES; then $sys_type=BSD fi # Set common variables that depends on the printing method install_init_methodP # --- Here starts the installation loop ---- # First time, dont ask for all details, use defaults # unless user wants advanved mode from beginning. set_ask_configP ${advanced} more_changes=YES while test $more_changes = "YES"; do abort_install=NO barf_setupP echo " ---------------------------------" echo " 1....Install printer" echo " 2....Change configuration" echo " 0....Abort installation" echo " ---------------------------------" echo range_answerP " Choose action" "[0-2]" 1 case ${range_answer} in 1) check_setupP ;; # Sets more_changes if conflicts found 2) more_changes=YES ;; # More changes 0) more_changes=NO abort_install=YES ;; esac # If user wants to change something, let him see # all options if test $more_changes = "YES"; then set_ask_configP YES fi done # while $more_changes if test $more_changes = "NO" && test $abort_install = "NO"; then error=NO install_printerP fi # do_install yes_or_noP "Do you want to install more printers" n more_printers=$yes_or_no done # while more_printers } # --- main_install # ============================================================================ # Uninstaller Code # ============================================================================ # --- bsd_create_printer_listP ----------------------------------------------- # --- Create a file named 'printers' in TMPDIR with all printers # --- found in the /etc/printcap file bsd_create_printer_listP() { if test ! -f $PRINTCAP ; then myexit 1 "There was no $PRINTCAP file." fi # --- Remove lines that start with # (comment) or :, whitespaces before # --- are accepted. Then match lines like ' printer| comment ' and # --- extract 'printer' and 'comment' cat < $TMPDIR/sedfile /^[ ]*[:#]/ d /^[ ]*[^|]*|[^:]*/ { s/^[ ]*\([^|]*\)|\([^:]*\).*$/\1: \2/p } END1 sed -n -f $TMPDIR/sedfile $PRINTCAP > $TMPDIR/printers } # --- End of bsd_create_printer_listP # --- sysv_create_printer_listP ----------------------------------------------- # --- Create a file named 'printers' in TMPDIR with all printers # --- found in by issue the lpstat command sysv_create_printer_listP() { # --- Match lines that starts with 'printer' # --- Extract 'printer' and some other info and print in nicer format cat < $TMPDIR/sysv_sed_list /^printer/ { s/^printer \([^ ]*\) .*\(enabled.*\)$/\1: \2/p } END3 lpstat -p | sed -n -f $TMPDIR/sysv_sed_list > $TMPDIR/printers } # --- End of sysv_create_printer_listP # --- aix_create_printer_listP ----------------------------------------------- # --- Create a file named 'printers' in TMPDIR with all printers # --- found in by issue the lpstat command aix_create_printer_listP() { # Label over columns in qchk output start with 'Queue' and then there is # a separator line, these are remove by the first two lines below. # The third is to get the first two colums, queue name and device name, # separated by whitespeces. No colon (:) is accepted, this is output from # remote queue. cat < $TMPDIR/aix_sed_list /^Queue/ d /^----/ d /^[^: ]*[ ]\{1,\}[^: ]*/ { s/^\([^: ]*\)[ ]\{1,\}\([^: ]*\).*/\1: On dev \2/p } EOF # list all printers in wide format and do not contact remote hosts enq -A -W -s | sed -n -f $TMPDIR/aix_sed_list > $TMPDIR/printers } # --- End of aix_create_printer_listP # --- choose_printerP -------------------------------------------------------- # --- Choose a printer from the ones available in the system. # --- Returns empty string if no printer is choosen. # --- Uses the *_create_printer_listP functions that should create # --- a file 'printers' that looks like below for each printer found. # --- ^printer_name:__\tcomment$, where # --- ^ = beginning of line, _ = space, \t = tab, $ = end of line) choose_printerP() { choose_printer= echo echo "Please wait, retreiving list of printers..." # --- Create the 'printers' file. case $sys_family in bsd) bsd_create_printer_listP ;; sysv) sysv_create_printer_listP ;; aix) aix_create_printer_listP ;; *) myexit 1 "'choose_printerP' not implemented for $sys_family yet" ;; esac test ! -f $TMPDIR/printers && myexit 1 "$TMPDIR/printers does not exist!" # --- Add a number before each printer and display choices to user. sed = $TMPDIR/printers | \ sed -n -e 'N; s/^/ /; s/ *\(.\{4,\}\)\n/\1: /p' > $TMPDIR/printers2 $clear cat < $TMPDIR/sedfile2 /^[^0-9]*$range_answer:/ s/^[^0-9]*$range_answer:\([^:]*\):.*/\1/p END2 choose_printer=`sed -n -f $TMPDIR/sedfile2 $TMPDIR/printers2` choose_printer=`strip $choose_printer` fi } # --- End of choose_printerP # --- bsd_extract_pcapP ------------------------------------------------------ # --- Extract printers printcap entry bsd_extract_pcapP() { # --- Search for printer name from line one in file, set bookmark a # --- from a, search for a line that does not end with '\', bookmark b # --- delete lines between a and b, save and quit. # --- save the output in a file. cat << END_PCAP > $TMPDIR/pcap_extract 1 /[ ]*${PRINTER}/ ka 'a /[^\]$/ kb 'b 'a,'b w $TMPDIR/bsd_pcap_extracted q END_PCAP ed -s ${PRINTCAP} < ${TMPDIR}/pcap_extract > /dev/null } # --- End of bsd_extract_pcapP # --- add_cmdP $1 ----------------------------------------------------------- # --- Add a command that should be executed when uninstalling the printer # --- Command output will be written to install log add_cmdP () { if test ! -f ${TMPDIR}/commands; then touch ${TMPDIR}/commands fi echo "echo '--- $1:' >> $instalog" >> ${TMPDIR}/commands echo "$1 2>&1 | tee -a $instalog" >> ${TMPDIR}/commands } # --- add_cmdP # --- find_out_filter_typeP $1 ---------------------------------------------- # --- $1 - name of filter. find_out_filter_typeP () { printer_type=unknown tmp_interface=$1 if test -f ${tmp_interface}; then if grep ftp ${tmp_interface} > /dev/null; then printer_type=ftp printer_rm=`extract_valueP $tmp_interface internet_address` printer_rp=`extract_valueP $tmp_interface logical_printer` printer_desc="FTP printer $printer_rp on host $printer_rm" elif strings $tmp_interface | grep netprinter > /dev/null; then # prosb has a string in it that is netprinter printer_type=prosb printer_desc="PROSB printer" fi fi if test "X${printer_type}" = Xunknown; then lecho "Could not find out type of printer by file ${tmp_interface}" fi } # --- find_out_filter_typeP # --- bsd_present_filesP ---------------------------------------------------- bsd_present_filesP () { printer_type=unknown bsd_extract_pcapP printer_device=`extract_valueP $TMPDIR/bsd_pcap_extracted lp` if test "X$printer_device" = "X"; then printer_type=lpd printer_rm=`extract_valueP $TMPDIR/bsd_pcap_extracted rm` printer_rp=`extract_valueP $TMPDIR/bsd_pcap_extracted rp` printer_desc="LPD printer $printer_rp on host $printer_rm" else # ftp and prosb has null device, prosa has named pipe echo $printer_device | grep null > /dev/null if test $? -ne 0; then printer_type=prosa printer_desc="PROSA printer" printer_prosa_log=`eval ${DEF_PROSLOG_EVAL}` test ! -f ${printer_prosa_log} && printer_prosa_log= else printer_filter=`extract_valueP $TMPDIR/bsd_pcap_extracted of` if test "X$printer_filter" = "X"; then printer_filter=`extract_valueP $TMPDIR/bsd_pcap_extracted if` fi if test "X$printer_filter" != "X"; then find_out_filter_typeP $printer_filter fi fi fi printer_spooldir=`extract_valueP $TMPDIR/bsd_pcap_extracted sd` printer_logfile=`extract_valueP $TMPDIR/bsd_pcap_extracted lf` echo test $printer_type = unknown && printer_desc="Unknown type" echo "Description : $printer_desc" echo "Log file : $printer_logfile" add_cmdP "rm $printer_logfile" case $printer_type in prosa) echo "Printer device : $printer_device" add_cmdP "rm $printer_device" if test -n $printer_prosa_log; then echo "PROSA log file: ${printer_prosa_log}" add_cmdP "rm ${printer_prosa_log}" else echo "PROSA log file will not be removed" fi ;; ftp|prosb) echo "Printer device : $printer_device" add_cmdP "rm $printer_device" echo "Printer filter : $printer_filter" add_cmdP "rm $printer_filter" ;; esac # We want to remove spool directory after device and log file, as # they often, but not always are placed in the spool dir. echo "Spool dir : $printer_spooldir" add_cmdP "rm -rf $printer_spooldir" echo "Printcap file ${PRINTCAP} will be modified." if test $printer_type = unknown; then lecho "Unknown printer type, all files may not be removed" fi } # --- bsd_present_filesP # --- aix_present_filesP ---------------------------------------------------- aix_present_filesP () { printer_type=unknown lsque -q $PRINTER > $TMPDIR/aix_lsque_extracted printer_device=`extract_valueP $TMPDIR/aix_lsque_extracted device` printer_rm=`extract_valueP $TMPDIR/aix_lsque_extracted host` if test "X$printer_rm" != "X"; then printer_type=lpd printer_rp=`extract_valueP $TMPDIR/aix_lsque_extracted rq` printer_desc="LPD printer $printer_rp on host $printer_rm" else lsquedev -q $PRINTER -d $printer_device > $TMPDIR/aix_lsquedev_extracted printer_filter=`extract_valueP $TMPDIR/aix_lsquedev_extracted backend` find_out_filter_typeP ${printer_filter} if test $printer_type = prosb; then printer_rm=`extract_valueP $printer_filter internet_address` printer_rp=`extract_valueP $printer_filter logical_printer` printer_logfile=`extract_valueP $printer_filter logfile` printer_desc="PROSB printer $printer_rp on host $printer_rm" fi fi # test "X$printer_rm" != "X" echo test $printer_type = unknown && printer_desc="Unknown type" echo "Desciption : $printer_desc" if test $printer_type != lpd; then add_cmdP "rmvirprt -q $PRINTER -d $printer_device" fi echo "Queue Device : $printer_device" add_cmdP "rmquedev -q $PRINTER -d $printer_device" add_cmdP "rm /dev/$printer_device > /dev/null 2>&1" add_cmdP "rmque -q $PRINTER" if test "X$printer_logfile" != "X"; then echo "Log file : $printer_logfile" add_cmdP "rm $printer_logfile" fi case $printer_type in ftp|prosb) echo "Printer filter : $printer_filter" add_cmdP "rm $printer_filter" ;; unknown) lecho "Unknown printer type, all files may not be removed" ;; esac } # --- aix_present_filesP # --- sysv_config_file_printerP $1 ------------------------------------------- # --- Determine printer type from configuration file in system # --- Only Solaris 2.6 has this, but maybe other systems are compatible? # --- $1 - configration file. # --- Output: printer_type, printer_desc for all printers # printer_interface for ftp and pros. sysv_config_file_printerP () { sysv_config_file=$1 # Solaris 2.6 has a configuration file for each printer printer_interface=`extract_valueP ${sysv_config_file} Interface :` if echo ${printer_interface} | grep netstandard > /dev/null ; then # solaris 2.6 new lpd method or reverse telnet printer_proto=`extract_valueP ${sysv_config_file} protocol = ,` printer_dest=`extract_valueP ${sysv_config_file} dest = ,` if test "X$printer_proto" = "Xbsd"; then printer_type=lpd printer_rm=`echo ${printer_dest} | cut -d: -f1` printer_rp=`echo ${printer_dest} | cut -d: -f2` printer_desc="LPD printer ${printer_rp} on ${printer_rm}" else lecho "No support for protocol '$printer_proto' in netstandard" printer_type=unknown fi else find_out_filter_typeP ${printer_interface} fi } # --- sysv_config_file_printerP # --- sysv_interface_lookupP ------------------------------------------------ # --- Try to find out printer type by looking up the interface # --- Output: printer_type, printer_desc for all printers # printer_interface for ftp and pros. sysv_interface_lookupP () { printer_type=unknown printer_home=${DEF_PROSHOME} if test ! -d ${printer_home} ; then myecho "Cannot find interface or filter directory." myecho "The default path is ${printer_home}." myecho "Please give path to directory, or just '/'" myecho "if the path is unknown." while true; do path_answerP "Absolute path" printer_home=$path_answer if -d ${printer_home}; then break fi done fi if test "X$printer_home" != "X/"; then printer_filter_ftp=`eval ${DEF_FTP_FILE_EVAL}` printer_filter_pros=`eval ${DEF_PROSB_FILE_EVAL}` if test -f ${printer_home}/${printer_filter_ftp}; then printer_interface=${printer_home}/${printer_filter_ftp} elif test -f ${printer_home}/${printer_filter_pros}; then printer_interface=${printer_home}/${printer_filter_pros} else echo "Cannot find interface file for $PRINTER in ${printer_home}." echo "The deafult name would be ${printer_filter_ftp} if it is a" echo "ftp printer and ${printer_filter_pros} if it is a pros printer" echo "Please give name of interface, relative to ${printer_home}," echo "or as an absolute path, beginning with '/'." echo "If the name is unknown, enter '?'" while true; do answerP "Interface name" "?" printer_filter=$answer case ${printer_filter} in ?) printer_filter= ; break ;; /*) ;; # Absolute path, do nothning *) printer_filter=${printer_home}/${printer_filter} ;; esac if test -f ${printer_filter} ; then break else lecho "The file ${printer_filter} doesn't exist, choose another" fi done if test "X${printer_filter}" != "X" && test -f ${printer_filter}; then printer_interface=${printer_filter} fi fi if test "X${printer_interface}" != "X"; then find_out_filter_typeP ${printer_interface} fi fi if test "X${printer_type}" = Xunknown; then lecho "Could not find printer type by interface" printer_interface= fi } # --- sysv_interface_lookupP # --- sysv_present_filesP ---------------------------------------------------- sysv_present_filesP () { lpstat -v$PRINTER > $TMPDIR/sysv_lpstat_dev printer_type=unknown sed_cmd="sed -ne '/^device [^:]*:/ s/^device [^:]*:\(.*\)/\1/p'" printer_device=`eval "$sed_cmd $TMPDIR/sysv_lpstat_dev"` printer_device=`strip ${printer_device}` sysv_config_file="/etc/lp/printers/$PRINTER/configuration" if test "X${printer_device}" != "X"; then # In here, device should only be PROSA pipe or /dev/null if test -p ${printer_device}; then printer_type=prosa printer_desc="PROSA printer" printer_prosa_log=`eval ${DEF_PROSLOG_EVAL}` test ! -f ${printer_prosa_log} && printer_prosa_log= elif echo ${printer_device} | grep '/dev/null' > /dev/null; then # FTP or PROSB or LPD in Solaris 2.6+ using netstandard if grep 'remote to:' $TMPDIR/sysv_lpstat_dev > /dev/null 2>&1; then # HP-UX: # device for lp9100_lpd5: /dev/null # remote to: pr5 on lp9100 printer_type=lpd sed_cmd="sed -ne '/remote to:/ s/.*:\(.*\)$/\1/p'" printer_remote=`eval "$sed_cmd $TMPDIR/sysv_lpstat_dev"` printer_desc="LPD printer $printer_remote" elif test -f ${sysv_config_file}; then sysv_config_file_printerP ${sysv_config_file} else sysv_interface_lookupP fi else lecho "Unknown device ${printer_device}" fi elif grep '^system for' $TMPDIR/sysv_lpstat_dev > /dev/null 2>&1; then # solaris 2.x : # system for pelle: nps (as printer pr7) # this is old variant, using lpadmin -s, installed by axinstall < 1.9.0 printer_type=lpd printer_remote=`sed -ne '/:/ s/.*:\(.*\)$/\1/p' $TMPDIR/sysv_lpstat_dev` printer_desc="LPD printer $printer_remote" else lecho "Could not determine type of $PRINTER" fi echo test $printer_type = unknown && printer_desc="Unknown type" echo "Desciption : $printer_desc" test ${stoplp} = YES && add_cmdP "lpshut" add_cmdP "lpadmin -x${HPFIX}${PRINTER}" test ${stoplp} = YES && add_cmdP "lpsched" case $printer_type in prosa) echo "Printer device : $printer_device" add_cmdP "rm ${printer_device}" if test -n $printer_prosa_log; then echo "PROSA log file: ${printer_prosa_log}" add_cmdP "rm ${printer_prosa_log}" else echo "PROSA log file will not be removed" fi ;; ftp|prosb) echo "Printer interface : $printer_interface" add_cmdP "rm $printer_interface" ;; lpd) if test $sys_num -eq $HPUX_n && \ test -f ${DEF_HP_LPDMODELDIR}/${PRINTER}; then echo "Printer model file : ${DEF_HP_LPDMODELDIR}/${PRINTER}" add_cmdP "rm ${DEF_HP_LPDMODELDIR}/${PRINTER}" fi ;; unknown) lecho "Unknown printer type, some files may not be removed." ;; esac } # --- sysv_present_filesP # --- present_filesP --------------------------------------------------------- # --- Show the user what kind of printer he is about to remove. present_filesP () { printer_type=unknown print_interface= printer_desc= printer_filter= printer_device= printer_home= printer_spooldir= printer_logfile= # Remove old commands file if it still exists rm ${TMPDIR}/commands > /dev/null 2>&1 case $sys_family in bsd) bsd_present_filesP ;; aix) aix_present_filesP ;; sysv) sysv_present_filesP ;; *) myexit 1 "present_filesP - does not support system family $sys_family" ;; esac } # --- End of present_filesP # --- bsd_remove_pcap_entryP ------------------------------------------------- # --- Removes the printer entry in the printcap file and makes # --- a backup of the old printcap in /tmp/printcap.$PRINTER bsd_remove_pcap_entryP() { logg "Will change ${PRINTCAP}, backup is saved in /tmp/printcap.${PRINTER}" # --- Make a backup file in tmp cp ${PRINTCAP} /tmp/printcap.${PRINTER} # --- if the printer's not in the file, we may remove the first entry ... grep ${PRINTER} ${PRINTCAP} > /dev/null if test $? != 0; then myexit 1 "Printer ${PRINTER} is not present in printcap file!" fi # FIX to allow deletion of printer that is on first line # in printcap file, simply add an empty line, unless there is # one already. bytes_on_first_line=`head -1 ${PRINTCAP} | wc -c` bytes_on_first_line=`strip $bytes_on_first_line` if test "X$bytes_on_first_line" != "X1"; then ed ${PRINTCAP} <<- END_PCAPADD > /dev/null 1 i . w q END_PCAPADD fi # --- Search for printer name from line one in file, set bookmark a # --- from a, search for a line that does not end with '\', bookmark b # --- delete lines between a and b, save and quit. cat << END_PCAP > $TMPDIR/pcap_edit 1 /[ ]*${PRINTER}/ ka 'a /[^\]$/ kb 'b 'a,'b d w q END_PCAP # --- Now, edit!. ed -s ${PRINTCAP} < ${TMPDIR}/pcap_edit > /dev/null if test $? != 0; then lecho "${PRINTER} could not be removed from ${PRINTCAP}." fi } # --- End of bsd_remove_pcap_entryP # --- remove_printerP -------------------------------------------------------- # --- This function removes the printer from the system remove_printerP() { logg logg "================== Removing printer ${PRINTER} ==================" case $sys_family in bsd) bsd_remove_pcap_entryP ;; esac if test -f ${TMPDIR}/commands; then logg "Executing the following commands to remove printer:" sh ${TMPDIR}/commands rm ${TMPDIR}/commands fi logg "============== Finished Removing printer ${PRINTER} ===============" logg } # --- End of remove_printerP # --- main_uninstall -------------------------------------------------------- main_uninstall() { will_continue=YES while test ${will_continue} = YES; do choose_printerP PRINTER=$choose_printer if test "X${PRINTER}" = "X"; then break fi echo # Add some fact collecting here, and present what will be deleted present_filesP echo yes_or_noP "Do you want to remove the printer ${PRINTER}" if test $yes_or_no = YES; then remove_printerP fi yes_or_noP "Do you want to remove another printer" y will_continue=$yes_or_no done # ${will_continue} = YES } # --- End of main_uninstall # ============================================================================ # Main Function and Control # ============================================================================ main_func () { initilize check_programsP os_type_initP default_ans=1 while true; do $clear cat <