head	1.1;
access;
symbols;
locks
	root:1.1; strict;
comment	@# @;


1.1
date	95.09.27.14.28.36;	author root;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Initial revision
@
text
@#!/bin/sh
# printconfig  -- create '/etc/printcap' and adjust 'any-defs'
#                 in '/usr/local/lib/magic-filter/sample-filters'.
# $Id$

# What          When                  Who
# $Log$

# Show the existing print settings and provide a way to back out.
dialog --title "Current printer queues" \
  --yesno \
"\nWe are about to update the 'lpr/lpd' settings in '/etc/printcap'.\n\
Currently you have the following printers in this file:\n\
\n\
`grep '^[^# 	]' /etc/printcap | cut -d ':' -f1`\
\n\n\
If you wish to change '/etc/printcap', select 'Yes'.
Select 'No' to cancel this script ($0)." \
    17 74
if [ $? != 0 ]; then
  exit
fi

# Selecting the major type of the primary printer 'lp'
dialog --title "Select your primary printer type" \
 --menu "Select the type of your primary printer, 'lp'.  \
The 'Non_PS' choice provides Ghostscript emulation for PostScript \
printing.  'PS_PCL' supports printing text files and files containing \
HP PCL escape sequences in HP PCL mode with a dual-emulation PostScript \
printer capable of emulating HP PCL commands." 17 76 5 \
  Non_PS       "Show a menu for HP/Epson/Canon/DEC/... printers" \
  PostScript   "A local PostScript printer is connected to this computer" \
  PS_PCL       "A PostScript printer which also accepts HP PCL" \
  Remote       "'lpr' should send files to another computer for printing" \
  No_Printer   "'lpr' print command is not needed on this computer" \
2>/tmp/reply
if [ $? != 0 ]; then
  rm -f /tmp/reply
  exit
fi
SEL="`cat /tmp/reply`"
rm -f /tmp/reply
case $SEL in
  No_Printer)
echo '# No printers selected in printconfig.' >/etc/printcap
exit
;;
  Remote)
dialog --title "Remote computer name" --inputbox \
"Please enter the TCP/IP name of the computer \
to which the remote printer is connected." 12 60 \
2> /tmp/reply
if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/reply
  exit
fi
RMHOST="`cat /tmp/reply`"
rm -f /tmp/reply

dialog --title "Remote printer name" --inputbox \
"Please enter the printer queue name on $RMHOST \
you wish to use as the default printer of this computer.  \
Please remember to enable remote access in $RMHOST's '/etc/hosts.lpd' \
(or equivalent)." 12 60 \
2> /tmp/reply
if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/reply
  exit
fi
RMPR="`cat /tmp/reply`"
rm -f /tmp/reply

cat >/etc/printcap <<EOF-marker-with-no-quoted-chars-to-get-var-expansion
lp|default|remoteprinter:\\
        :lp=:mx#0:rm=$RMHOST:rp=$RMPR:\\
        :sd=/var/spool/lp1:\\
        :lf=/var/adm/lpd-errs:
EOF-marker-with-no-quoted-chars-to-get-var-expansion
mkdir -p /var/spool/lp1
chown root.lp /var/spool/lp1
chmod ug=rwx,o= /var/spool/lp1
touch /var/adm/lpd-errs
exit
;;
  PostScript)
# Input filter for plain PostScript is (currently, unfortunately):
LPIF="qms01.if"
;;
  PS_PCL)
# And the input filter for PS+PCL is:
LPIF="qms02.if"
;;
  Non_PS)
dialog --title "Select printer type" \
 --menu "Select the printer type that most closely matches \
the printer you are using.  For some printer models there are \
multiple driver alternatives, as well as alternatives for printing \
in color or in b/w." 21 76 10 \
`grep '^MOD' printer-gs-specs | cut -b4-` \
2>/tmp/reply
if [ $? != 0 ]; then
  rm -f /tmp/reply
  exit
fi
GSDEV="`cat /tmp/reply`"
rm -f /tmp/reply

# Check that the printer has a definition of text file filter
TEFSPEC="`grep "^TEF$GSDEV " printer-gs-specs | cut -d ' ' -f2-`"
if [ "$TEFSPEC" = "" ]; then
  TEFSPEC="text2pc8"  # the default is the simple one, PC-8 char set conversion
fi

# Check for a "borrowed" resolution list.
RESDEV="`grep "^RRE$GSDEV " printer-gs-specs | cut -d ' ' -f2-`"
if [ "$RESDEV" = "" ]; then
  RESDEV="$GSDEV"
fi

# Selecting a resolution supported by the printer.
dialog --title "Select Ghostscript resolution" \
 --menu "Select the resolution ('dots per inch') you want to use \
when printing PostScript documents with Ghostscript emulation.  \
A large dpi figure delivers better quality, but it takes longer \
to print and uses more computer memory. \
$(echo `grep "^RIN$GSDEV " printer-gs-specs | cut -d ' ' -f2-`) \
" 21 76 9 \
`grep "^RES$RESDEV " printer-gs-specs | cut -d ' ' -f2-` \
2>/tmp/reply
if [ $? != 0 ]; then
  rm -f /tmp/reply
  exit
fi
GSRES="`cat /tmp/reply`"
rm -f /tmp/reply

# Selecting a default paper size for Ghostscript.
dialog --title "Select Ghostscript default paper size" \
 --menu "Select the default paper size you will be using in your printer \
when printing PostScript documents with \
Ghostscript emulation." 21 51 11 \
`fgrep 'begin .setpagesize end' /usr/lib/ghostscript/gs_statd.ps | cut -d ' ' -f2 | cut -b2- | sed -e 's/$/ (size)/'` \
2>/tmp/reply
if [ $? != 0 ]; then
  rm -f /tmp/reply
  exit
fi
GSPAP="`cat /tmp/reply`"
rm -f /tmp/reply

# Allow entering extra parameters to 'gs'.
dialog --title "Extra parameters to Ghostscript" --inputbox \
"\nIf there are additional parameters you would like to pass to 'gs',\n\
you can enter them on the line below.  (You can leave it blank, too.)\n\
Separate multiple parameters with a blank.\n\n\
`grep "^EXS$GSDEV " printer-gs-specs | cut -d ' ' -f2-`\n" 23 77 \
2> /tmp/reply
if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/reply
  exit
fi
GSEXS="`cat /tmp/reply`"
rm -f /tmp/reply

# Now plant the Ghostscript settings into 'any-defs' in magic filter dir.
cat >/usr/local/lib/magic-filter/sample-filters/any-defs <<EOF-marker-with-no-quoted-chars-to-get-var-expansion
DEV="$GSDEV"
RES="$GSRES"
PAP="$GSPAP"
EXS="$GSEXS"
TEF="$TEFSPEC"
EOF-marker-with-no-quoted-chars-to-get-var-expansion

# And the input filter which uses 'any-defs' is 'lp.if'.
LPIF="lp.if"
;;
esac

# All local printers need a device name to write to, preferably a par port.
dialog --title "Local printer port device name" --inputbox \
"Please specify the name of the parallel port \
to which your local printer is connected.  \
Usually this is '/dev/lp1'." 12 60 \
2> /tmp/reply
if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/reply
  exit
fi
LPDEV="`cat /tmp/reply`"
rm -f /tmp/reply

# Now we create the /etc/printcap for one local printer.
cat >/etc/printcap <<EOF-marker-with-no-quoted-chars-to-get-var-expansion
lp|default|anyprinter:\\
        :lp=$LPDEV:\\
        :sd=/var/spool/lp1:\\
        :sh:mx#0:pw#80:px#80:\\
        :if=/usr/local/lib/magic-filter/$LPIF:\\
        :lf=/var/adm/lpd-errs:
EOF-marker-with-no-quoted-chars-to-get-var-expansion

# Then we ensure that the spool directory and log file exist.
mkdir -p /var/spool/lp1
chown root.lp /var/spool/lp1
chmod ug=rwx,o= /var/spool/lp1
touch /var/adm/lpd-errs

# Finally, ensure that the new printcap takes effect.
lpc restart all

exit 0
@
