G. Paul Ziemba on Fri, 9 Nov 2001 23:14:26 +0100 (CET)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[patch] banner page printing + NFS optimization


Greetings,

We like to have a banner page identifying the user; attached are diffs
to apsfilter to do it. I am sure there is room for parametrization
(via apsfilterrc) of the "big letters" program (figlet or whatever)
as well as whether to enable banners at all.

I also tweaked the check for user apsfilterrc to avoid referencing the
user's home directory unless USE_USER_CODE is actually defined - this
avoids nfs mount attempts on our print host.

Iff you like these changes, I'd be happy if they were incorporated into
the baseline.

cheers,

 ~!paul

-- 
G. Paul Ziemba  paul@w6yx.stanford.edu
FreeBSD unix:
 2:01PM  up 54 days, 16:57, 15 users, load averages: 0.04, 0.03, 0.00
--- apsfilter	Fri Nov  9 13:54:49 2001
+++ apsfilter-banner-011108.cleaned	Fri Nov  9 13:58:43 2001
@@ -275,6 +275,39 @@
 	"$@" -o /dev/stdout /dev/stdin | print_pnm
 }
 
+# gpz 010928 start
+#=============================================================================
+# print_banner
+#
+# print a leading banner page with user info
+#=============================================================================
+
+print_banner()
+{
+
+    unset _apsf_usr
+    if [ "$USER" ]; then
+	_apsf_usr=`echo $USER|perl -pe 'chomp;$_=(getpwnam($_))[6]'` ;
+    fi
+
+
+    logger -p lpr.info -t apsfilter "Q:$QUEUE U:$USER H:$HOST F:$FNAME"
+
+    [ "$USER" -a -x /usr/local/bin/figlet ] &&	/usr/local/bin/figlet -f banner $USER
+			echo "####"
+#   [ "$USER" ] &&	echo "#### Username: $USER"
+    [ "$_apsf_usr" ] &&	echo "####    Owner: $_apsf_usr"
+			echo "####"
+    [ "$FNAME" ] &&	echo "####     File: $FNAME"
+    [ "$JOB" ] &&	echo "####   Job ID: $JOB"
+    [ "$QUEUE" ] &&	echo "#### Queue ID: $QUEUE"
+    [ "$HOST" ] &&	echo "####     Host: $HOST"
+			echo "####  Printed: "`date`
+			echo "####"
+}
+
+# gpz 010928 end
+
 #=============================================================================
 # print_ascii
 #
@@ -566,6 +599,34 @@
 	fi
     }
 
+    # gpz 010928 start
+    # we run the plain text banner through print_ascii because
+    # the ascii->ps processing encodes EOF (in postscript) and
+    # enables the ptinter to understand that the data following
+    # is a new file. If the printer device is not a postscript
+    # printer, presumably gs will embed some end-of-file or reset
+    # codes at the end of the printer-specific output that accomplishes
+    # the same thing.
+    #
+    # If we don't embed this EOF somehow, then the printer does not
+    # notice (for example) the postscript header at the start of the
+    # user data, and prints the postscript source as plain ascii (ugh!)
+    #
+    if [ "$PRINTING_BANNER" ]; then
+	:
+    else
+	PRINTING_BANNER="YES";
+	# override FILE_TYPE for print_ascii so that a2ps doesn't
+	# get confused
+	PRINTING_BANNER_SAVE_FILE_TYPE=$FILE_TYPE
+	FILE_TYPE="ASCII English text"
+        print_banner | perl -pe 's/$/\r/' | print_ascii
+	FILE_TYPE=$PRINTING_BANNER_SAVE_FILE_TYPE
+	unset PRINTING_BANNER_SAVE_FILE_TYPE
+	unset PRINTING_BANNER
+    fi
+    # gpz 010928 end
+
     if [ "$SAVE_DUPLEX_COPY" ]; then
 	# print_ps_duplex() does the manual copying
 	tee "$APS_TMPDIR/copy-$SAVE_DUPLEX_COPY" | print_copy
@@ -1499,7 +1560,9 @@
 [ -f "$CONF_DIR/$QUEUE/apsfilterrc.$USER" ] && \
     . "$CONF_DIR/$QUEUE/apsfilterrc.$USER"
 
-[ -n "$USE_USER_CODE" -a -f "$HOMEDIR/.apsfilter/apsfilterrc.$QUEUE" ] && \
+# gpz 011108 avoid referencing user's home directory unless
+# USE_USER_CODE is actually set - cut down on NFS mounts
+[ -n "$USE_USER_CODE" ] && [ -f "$HOMEDIR/.apsfilter/apsfilterrc.$QUEUE" ] && \
     . "$HOMEDIR/.apsfilter/apsfilterrc.$QUEUE"
 
 export PATH