#!/usr/bin/sh
# (c) Copyright 1993,1994 Hewlett-Packard Company. All Rights Reserved.
#@(#) $Header: /users/hpnp/odyssey/repository/sh/net_lj3x.psh,v 1.13 1999/10/12 09:28:42 hpnp Exp $
#----------------------------------------------------------------------
# USER CAUTION: If any changes are desired, you should first make a copy
# of this model under a new name. Changes can then be made to the copy
#----------------------------------------------------------------------
log=/var/adm/lp/log
BANNER="yes" # CHANGE BANNER PAGE PRINTING
TMP=/var/tmp
# [ Modify by the Amit R. to solve the problem of security on 20th Feb. 1998
HPNP=/opt/hpnp
# [ Modified by Suresha on 26th Sep 99 to support JPIU
HPNP=/opt/hpnpl
ID=/usr/bin/id
CUT=/usr/bin/cut
AWK=/usr/bin/awk
MKDIR=/usr/bin/mkdir
USERNAME=`$ID | $CUT -f1 -d" " | $CUT -f2 -d"(" | $CUT -f1 -d")"` # get user name
if [ $USERNAME = "root" -o $USERNAME = "lp" ]
then
TMP=$HPNP/tmp
else
/usr/bin/sun > /dev/null 2>&1
if [ $? -eq 0 ]
then
# [ Modified by Amit Raval to fix the defect#57434 on 20th Apr. 1999
# HOME=`$AWK 'BEGIN { FS=":" }
# {if ( $1 == UNAME) print $6 ; }' UNAME=$USERNAME /etc/passwd` # get home dir. from /etc/passwd
JAHOME=`$AWK 'BEGIN { FS=":" }
{if ( $1 == UNAME) { print $6 ; exit } }' UNAME=$USERNAME /etc/passwd` # get home dir. from /etc/passwd
# ]
else
# [ Modified by Amit Raval to fix the defect#57434 on 20th Apr. 1999
# HOME=`$AWK -v UNAME=$USERNAME 'BEGIN { FS=":" }
# {if ( $1 == UNAME) print $6 ; }' /etc/passwd` # get home dir. from /etc/passwd
JAHOME=`$AWK -v UNAME=$USERNAME 'BEGIN { FS=":" }
{if ( $1 == UNAME) { print $6 ; exit } }' /etc/passwd` # get home dir. from /etc/passwd
# ]
fi
if [ -z "$JAHOME" ] # Handle the NIS issue
then
JAHOME=$HOME # Assign the env veriable HOME if JAHOME is null.
fi
# [Modified by Kumaresan for JPIU on 26th Sept '99.
if [ ! -d $JAHOME/.jpiu ]
then
$MKDIR $JAHOME/.jpiu > /dev/null 2>&1
if [ $? -eq 0 ]
then
TMP=$JAHOME/.jpiu
fi
else
TMP=$JAHOME/.jpiu
fi
fi
# ]
# --------- Definitions of functions used within this script ------------
# print the option listing with -ooptions while submitting a job
all_options()
{ # map lf->cr+lf; bold
echo "\033&k2G\033(s3B\t\t\033&d0D\c"
echo "Available Options for Model Script net_lj3x\n"
echo "\033&d@SYNOPSIS:\033(s0B\c"
echo "\tlp -o -o ... ...\n"
echo "\033(s3BDESCRIPTION:\033(s0B"
echo "
This script may be used with HP LaserJet II, IID, III, and IIID. Options
below may not be applied to all models. Use them discreetly.
"
echo "\033(s3BOPTIONS:\033(s0B\033&k2S\033&l6C\c" # compressed font, 8 line/in
# >>>>>>>>>>>>> BEGIN OF OPTION SECTION <<<<<<<<<<<<<<<<<<<
echo "
options list all options
hpgl2,hpgl2_p print in HP-GL/2 landscape mode or portrait mode
r/raw print in PCL raw mode.
yb, nb print, or do not print banner page (Default: $BANNER)
btray1,btray2 feed banner page from tray1 (upper) or tray2 (lower)
portrait,landscape print in portrait/landscape mode (Default: Front Panel)
simplex/mduplex single side/manual double sided printing
duplex, hduplex double sided printing, long edge/short edge binding
legal,letter,A4,exec select legal, letter, A4, or executive sized paper
manual,tray1(upper),tray2(lower), com10env
feed paper from the indicated tray
3hole adjust left/top margin to account for the holes (TEXT)
ln66 print 66 lines of text on portrait
2up/4up print 2/4 pages on one side of paper
rev reverse the output page (TEXT only)
l#, tl# set logical page length/text length to # lines
tm#, lm#, rm# set top margin to # lines, or left/right margin in column #
c, 10, 12, fp# set font pitch to compressed, or 10/12/# char/inch
ps, fs select proportional, or fixed spacing font
lpi# print at # lines per inch
hsi#, vsi# set horizontal/vertical spacing increment
cs#, type# set character set/typeface to #
height# set height to #
style#, i, upright set font style to #, italic, or upright
weight#, b/bold set font stroke weight to #, or bold
n/nroff, pr print output of nroff/pr (run nroff first)
HP Network Printer Only (see also man pages for xjjm and jetdirect)
debugm send model script output to a file for examination. If
no file name, $TMP/ is used. File name must be
preceded by absolute path.
job/jobnp,nojob bring, or not bring up the job monitor for this job.
a display name can be specified by -ojob+.
"
# [ Modify by the Amit R. to solve the problem of security on 20th Feb. 1998
# Replace following five lines code in above echo command.
# #ifndef UX9
# no file name, $TMP/ is used. File name must be
# #else /* UX9 */
# no file name, /tmp/ is used. File name must be
# #endif UX9
# with
# no file name, $TMP/ is used. File name must be
# ]
# >>>>>>>>>>>>> END OF OPTION SECTION <<<<<<<<<<<<<<<<<<<
echo "\n\033&k0S\033(s3BNOTE:\033(s0B\033&l8C\n"
echo "
1. 2up/4up will use the defaults for all options except duplex, orientation,
in/out bin selection, and banner page printing.
2. Unexpected results may occur when using option \"l#\" or \"tl#\" alone.
3. Most options described above are intended for text (ASCII) files.
4. Option \"-oraw\" is required for printing PCL raster files.
"
echo "\033E\c"
}
# list the some options on the banner page.
partial_options()
{
echo "\033&a5976v40L\c"
echo "********* Option Summary *********"
echo "(use -ooptions to get a description)\n"
echo "\033&k2S\c" # use compressed font
echo "manual, tray1(upper), tray2(lower), com10env "
echo "hpgl2, hpgl2_p, raw 3hole"
echo "nroff, pr yb, nb "
echo "simplex, duplex, hduplex ln66"
echo "legal, letter, A4, exec"
echo "2up, 4up portrait, landscape "
# draw box
echo "\033&a5818v2808H\033*c4h1440v0P\033*c2880h4v0P\c"
echo "\033&a7258v2808H\033*c2880h4v0P\c"
echo "\033&a5818v5688H\033*c4h1440v0P\c"
}
# PCL banner
do_banner()
{
# Print the standard header
echo "\033&l0O\c" # always in portrait mode
echo "\033)8U\033)s1p60v1s0b16901T\n $user\033)s14v0S"
user1=`pwget -n $user | line | cut -d: -f5`
if [ -n "$user1" ]
then
echo "\n\t\t\t\t\t\t\t\tUser: $user1\n"
else
echo "\n\t\t\t\t\t\t\t\tUser: (No User Info in /etc/passwd)\n"
fi
echo "\t\t\t\t\t\t\t\tRequest: $reqid from $syst\n"
echo "\t\t\t\t\t\t\t\tOptions: $options\n"
if [ -n "$title" ]
then
echo "\t\t\t\t\t\t\t\tTitle: $title"
else
echo ""
fi
date1=`date`
echo " $date1"
echo "\c"
# draw box
echo "\033&l0E\c"
echo "\033&a120v0H\033*c4h1680v0P\033*c5616h4v0P\c"
echo "\033&a1800v0H\033*c5616h4v0P\c"
echo "\033&a120v5616H\033*c4h1680v0P\c"
# shade the area
echo "\033&l0e8C\033&a0v0H\c"
echo "\033*c5616h1800v10g2P\c"
partial_options
# [ Modified by Suresha on 26th Sep 99 to support JPIU
#if [ -r /opt/hpnp/etc/hplogo.pcl ]
if [ -r $HPNP/etc/hplogo.pcl ]
# end of change by suresha ]
then
echo "\033&a140v5075H\c"
# [ Modified by Suresha on 26th Sep 99 to support JPIU
#cat /opt/hpnp/etc/hplogo.pcl
cat $HPNP/etc/hplogo.pcl
# end of change by suresha ]
fi
}
#------------------------
# [ Modified by Amit Raval to fix the defect# 57429 on Apr. 20th 1999
#PATH="$PATH:/usr/bin:/usr/lbin"
PATH="/usr/bin:$PATH:/usr/lbin"
# ]
export PATH
# set up redirection of stderr
exec 2>>$log
/usr/bin/rm -f $TMP/lj3x*
# Save the arguments to the model
printer=`basename $0`
reqid=$1
user=$2
title=$3 # CHANGE TITLE
copies=$4 # CHANGE COPIES
options=$5 # CHANGE OPTIONS
opt6=$6
# Assume that the rest of the arguments are files
shift; shift; shift; shift; shift
files="$*"
# find out orignal submitted system
dfname=`basename $opt6`
cfname=`dirname $opt6`/c`expr match $dfname '\d\(.*\)'`
syst=`sed -n "/^H/s/H//p" $cfname`
# for serial connection
baudrate="9600"
# Set up interface (parallel/serial, no effect on JetDirect)
if [ -t 1 ]
then
stty raw $baudrate -parenb cs8 ixon -istrip clocal <&1 2>/dev/null
else
slp -r 2>/dev/null
fi
# Handle disable and cancel traps.
CancelJob()
{
# [ Modify by the Amit R. to solve the problem of security on 20th Feb. 1998
# #ifndef UX9
# rm -f $TMP/lj3x$$
# #else /* UX9 */
# rm -f /tmp/lj3x$$
# #endif UX9
rm -f $TMP/lj3x$$
# ]
echo "$reqid is cancelled!" >> $log
if [ -t 1 ]
then
stty raw $baudrate -parenb cs8 ixon -istrip clocal <&1 2>/dev/null
fi
exit 0
}
trap CancelJob 15
# initialize the variables
lang_user="PCL"
listopt=""
# internal use
nroff=""
reverse=""
banner=$BANNER
ThreeHoles="" # CHANGE DEFAULT 3HOLE OPTION
ln66=""
dividing="" # CHANGE DEFAULE PAGE DIVIDE MODE , '-hh' for 2+, '-h'
# for 2up and '-q' for 4up
manuald=""
outputmode="cooked"
bannerpagesrc="def" # CHANGE DEFAULT BANNER PAGE SOURCE
resolution="def" # CHANGE DEFAULT RESOLUTION
duplex="def" # CHANGE DEFAULT DUPLEX MODE
mediasrc="def" # CHANGE DEFAULT MEDIA SOURCE
mediadest="def" # CHANGE DEFAULT MEDIA DESTINATION ONLY FOR PCL FILE
orientation="def" # CHANGE DEFAULT ORIENTATION
paper="def" # CHANGE DEFAULT PAPER SIZE
length="def"
pitch="def"
hsi="def"
lpagelen="def"
textlen="def"
lmargin="def"
rmargin="def"
tmargin="def"
italic=""
spacing="def"
lpi="def"
vsi="def"
charset="def"
height="def"
style="def"
typeface="def"
weight="def"
# Determine which options have been invoked
for i in $options
do
case "$i" in
#
pcl )
lang_user="PCL";;
hpgl2)
lang_user="HPGL2"
outputmode="raw";;
hpgl2_p)
lang_user="HPGL2_P"
outputmode="raw";;
r | raw)
lang_user="PCL"
outputmode="raw";;
n | nroff)
nroff="-n"
length="-l66";;
pr)
nroff="-p"
length="";;
nb ) # No banner page
banner="";;
yb ) # output banner page
banner="yes";;
options )
listopt="yes";;
rev)
reverse="yes";;
3hole)
ThreeHoles="yes";;
portrait) # print in portrait mode
orientation="p";;
landscape) # print in landscape mode
orientation="l";;
# duplex
simplex)
duplex="simplex";;
vd | duplex | double | d) # vertical binding
duplex="vduplex";;
hd | hduplex) # double side, horizontal binding
duplex="hduplex";;
md | mduplex) # duplexing manually
manuald="mdouble";;
# paper source
manual | m | man | mb ) # manual sheet feed
mediasrc="2";;
tray1 | upper | ub | ubin) # feed from upper cassette
mediasrc="1";;
tray2 | lower | lb | lbin) # feed from lower cassette
mediasrc="4";;
com10env) # feed from envelope tray,
mediasrc="6";;
# paper size
legal)
paper="legal";;
letter)
paper="letter";;
A4)
paper="A4";;
exec)
paper="exec";;
# feed banner page from upper(1)/lower (4) tray,
btray1 | bupper | ubb | ubbin)
bannerpagesrc="1";;
btray2 | blower | lbb | lbbin)
bannerpagesrc="4";;
# 2-up/4-up.
half | 2 | 2up)
dividing="-h";;
quarter | 4 | 4up)
dividing="-q";;
# PCL Font Control
10) # set to 10.00 cpi
pitch="10";;
12) # set to 12.00 cpi
pitch="12";;
c) # compressed print
pitch="c";;
# set font pitch to value following fp
fp[0-9]* | fp.[0-9]*)
pitch="`echo "$i" | sed 's/^[-]*fp//'`" ;;
# set horizontal spacing increment to #/120 in.
hsi[0-9]*)
hsi="`echo "$i" | sed 's/^[-]*hsi//'`";;
ps) # proportional spacing
spacing="1";;
fs) # fixed spacing
spacing="0";;
# set lines per inch
lpi[0-9]*)
lpi="`echo "$i" | sed 's/^[-]*lpi//'`";;
# set vertical spacing increment to #/48 inch
vsi[0-9]*)
vsi="`echo "$i" | sed 's/^[-]*vsi//'`";;
# set character set to value following cs
cs[0-9]*)
charset="`echo "$i" | sed 's/^[-]*cs//'`";;
# set height value
height[0-9]*)
height="`echo "$i" | sed 's/^[-]*height//'`";;
# set font style
style[0-1])
style="`echo "$i" | sed 's/^[-]*style//'`";;
i | italic)
style=italic;;
upright)
style="0";;
# set typeface
type[0-9]*)
typeface="`echo "$i" | sed 's/^[-]*type//'`";;
# set font weight
weight[0-9]* | weight-[0-9]*)
weight="`echo "$i" | sed 's/^[-]*weight//'`";;
# set font weight
b | bold)
weight=1;;
#set absolute length of page
ln66)
ln66="yes";;
l[0-9]*)
lpagelen="`echo "$i" | sed 's/^[-]*l//'`";;
#set text length of page
tl[0-9]*)
textlen="`echo "$i" | sed 's/^[-]*tl//'`";;
# set top margin in lines
tm[0-9]*)
tmargin="`echo "$i" | sed 's/^[-]*lm//'`";;
# set left margin in columns
lm[0-9]*)
lmargin="`echo "$i" | sed 's/^[-]*lm//'`";;
# set right margin in columns
rm[0-9]*)
rmargin="`echo "$i" | sed 's/^[-]*rm//'`";;
esac
done
# settle outputmode precedence: raw, 2/4-up, and mdouble
if [ "$outputmode" = "raw" ]
then
dividing="" # invalidate 2/4-up
manuald="" # invalidate manual duplex
fi
if [ -n "$manuald" ]
then
outputmode="mdouble"
omode_user="mdouble"
fi
if [ -n "$dividing" ] # override manaul double
then
outputmode="divide"
omode_user="divide"
fi
if [ "$ln66" = "yes" ]
then
vsi="7.4"
textlen="66"
pitch="10.7"
orientation="p"
lpi="def" # reset, if specified.
fi
if [ "$ThreeHoles" = "yes" ]
then
pitch="10.7"
if [ "$orientation" = "def" ]
then
orientation="p"
fi
if [ "$orientation" = "p" ]
then
lmargin="4"
else
tmargin="4"
vsi="7.85"
fi
fi
if [ "$mediasrc" = "6" ]
then
banner=""
orientation="l"
paper="com10"
fi
# ********** Start sending bytes out ****************
# Print the spooled files
echo "\033E\c"
i=1
while [ $i -le $copies ]
do
for file in $files
do
# banner page ;
if [ -n "$banner" -a -z "$reverse" ]
then
echo "\033&k2G\c"
# where does the paper come from
if [ "$bannerpagesrc" != "def" ]
then
echo "\033&l${bannerpagesrc}H\c"
elif [ "$mediasrc" = "1" -o "$mediasrc" = "4" ]
then
echo "\033&l${mediasrc}H\c"
fi
do_banner
echo "\033E\c" # kick the page out
banner=""
fi
if [ "$listopt" = "yes" ]
then
all_options
listopt=""
fi
if [ "$outputmode" != "raw" ]
then
echo "\033&k2G\c"
fi
# download font if dividing is "half" or "quarter"; text only
if [ $outputmode = "divide" ]
then
# reset following if they are set
reverse=""
pitch="def"
hsi="def"
spacing="def"
lpi="def"
vsi="def"
charset="def"
style="def"
typeface="def"
weight="def"
lpagelen="def"
textlen="def"
lmargin="def"
rmargin="def"
nroff=""
italic=""
length="def"
case "$orientation" in
p | def)
orientation="p"
case "$dividing" in
-h);;
-q) fontdl /usr/lib/lp/fonts/lp4p;;
esac;;
l)
case "$dividing" in
-h) fontdl /usr/lib/lp/fonts/lp2l;;
-q) fontdl -l /usr/lib/lp/fonts/lp4l;;
esac;;
esac
fi
case "$mediasrc" in
def);;
*) echo "\033&l${mediasrc}H\c";;
esac
case "$paper" in
A4) echo "\033&l26A\c";;
exec) echo "\033&l1A\c";;
letter) echo "\033&l2A\c";;
legal) echo "\033&l3A\c";;
com10) echo "\033&l81A\c";;
esac
case "$duplex" in
simplex) echo "\033&l0S\c";;
vduplex) echo "\033&l1S\c";;
hduplex) echo "\033&l2S\c";;
esac
case "$orientation" in
p) echo "\033&l0O\c";;
l) echo "\033&l1O\c"
length="-l45";;
esac
case "$vsi" in
def);;
*) echo "\033&l${vsi}C\c";;
esac
case "$lpi" in
def);;
*) echo "\033&l${lpi}D\c";;
esac
case "$lpagelen" in
def) if [ "$length" = "def" ]
then
length="-l60"
fi
;;
*) echo "\033&l${lpagelen}P\c"
length="-l$lpagelen";;
esac
case "$textlen" in
def);;
*) echo "\033&l${textlen}F\c"
length="-l$textlen";;
esac
case "$charset" in
def);;
*) echo "\033(${charset}\c";;
esac
case "$spacing" in
def);;
*) echo "\033(s${spacing}P\c";;
esac
case "$pitch" in
def);;
c) echo "\033&k2S\c";;
*) echo "\033(s${pitch}H\c";;
esac
case "$hsi" in
def);;
*) echo "\033&k${hsi}H\c";;
esac
case "$height" in
def);;
*) echo "\033(s${height}V\c";;
esac
case "$style" in
def);;
italic) echo "\033(s1S\c"
italic="-i";;
*) echo "\033(s${style}S\c";;
esac
case "$weight" in
def);;
*) echo "\033(s${weight}B\c";;
esac
case "$typeface" in
def);;
*) echo "\033(s${typeface}T\c";;
esac
case "$lmargin" in
def);;
*) echo "\033&a${lmargin}L\c";;
esac
case "$rmargin" in
def);;
*) echo "\033&a${rmargin}M\c";;
esac
case "$tmargin" in
def);;
*) echo "\033&l${tmargin}E\c";;
esac
case "$mediadest" in
def);;
*) echo "\033&l${mediadest}G\c";; #
esac
case "$outputmode" in
raw)
echo "\033&k0G\c"
case "$lang_user" in
# [[ Changed by Devu on Sept 25 1999 to fix problems
# with -ohpgl* options resetting all previous PCL commands
#HPGL2_P) echo "\033E\033&l3O\033%1B\c";;
#HPGL2) echo "\033E\033%1B\c";;
HPGL2_P) echo "\033&l3O\033%1B\c";;
HPGL2) echo "\033%1B\c";;
# end of change Devu]]
*) ;;
esac
# [ Modify by the Amit R. to solve the problem of security on 20th Feb. 1998
# #ifndef UX9
# cat "$file" 2>$TMP/lj3x$$
# if [ -s $TMP/lj3x$$ ]
# #else /* UX9 */
# cat "$file" 2>/tmp/lj3x$$
# if [ -s /tmp/lj3x$$ ]
# #endif UX9
cat "$file" 2>$TMP/lj3x$$
if [ -s $TMP/lj3x$$ ]
# ]
then
case "$lang_user" in
HPGL2 | HPGL2_P )
# [ Modify by the Amit R. to solve the problem of security on 20th Feb. 1998
# #ifndef UX9
# cat $TMP/lj3x$$ >> $log;;
# *) cat $TMP/lj3x$$ ;; # output any errors
# #else /* UX9 */
# cat /tmp/lj3x$$ >> $log;;
# *) cat /tmp/lj3x$$ ;; # output any errors
# #endif UX9
cat $TMP/lj3x$$ >> $log;;
*) cat $TMP/lj3x$$ ;; # output any errors
# ]
esac
fi
# [ Modify by the Amit R. to solve the problem of security on 20th Feb. 1998
# #ifndef UX9
# rm -f $TMP/lj3x$$;;
# #else /* UX9 */
# rm -f /tmp/lj3x$$;;
# #endif UX9
rm -f $TMP/lj3x$$;;
# ]
cooked)
echo "\r\c"
if [ -n "$reverse" ]
then
lprpp $italic $length $nroff < "$file" 2>&1 | reverse $length
else
lprpp $italic $length $nroff < "$file" 2>&1
fi
;;
mdouble)
if [ -n "$reverse" ]
then
lprpp $italic $length $nroff -o < "$file" 2>&1 | reverse $length
else
lprpp $italic $length $nroff -o < "$file" 2>&1
fi
echo "\033&l2H\c"
lprpp $italic $length $nroff -e < "$file" 2>&1;;
divide)
divpage -$orientation "$dividing" "$file" 2>&1;;
esac
echo "\033E\c" # Reset Printer; end of PCL file
done
i=`expr $i + 1`
done
if [ -n "$banner" ]
then
echo "\033&k2G\c"
if [ "$bannerpagesrc" != "def" ]
then
echo "\033&l${bannerpagesrc}H\c"
elif [ "$mediasrc" = "1" -o "$mediasrc" = "4" ]
then
echo "\033&l${mediasrc}H\c"
fi
do_banner
echo "\033E\c"
fi
# end of job
# RS-232 interface insure all buffers are flushed to printer
if [ -t 1 ]
then
stty raw $baudrate -parenb cs8 ixon -istrip clocal <&1 2>/dev/null
fi
exit 0