From wollman@hergotha.csail.mit.edu  Thu Sep 23 22:41:18 2010
Return-Path: <wollman@hergotha.csail.mit.edu>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id AED1B1065670
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 23 Sep 2010 22:41:18 +0000 (UTC)
	(envelope-from wollman@hergotha.csail.mit.edu)
Received: from hergotha.csail.mit.edu (hergotha.csail.mit.edu [66.92.79.170])
	by mx1.freebsd.org (Postfix) with ESMTP id 5B8338FC17
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 23 Sep 2010 22:41:17 +0000 (UTC)
Received: from hergotha.csail.mit.edu (localhost [127.0.0.1])
	by hergotha.csail.mit.edu (8.14.4/8.14.4) with ESMTP id o8NMfGCE075523
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 23 Sep 2010 18:41:16 -0400 (EDT)
	(envelope-from wollman@hergotha.csail.mit.edu)
Received: (from wollman@localhost)
	by hergotha.csail.mit.edu (8.14.4/8.14.4/Submit) id o8NMfGfc075522;
	Thu, 23 Sep 2010 18:41:16 -0400 (EDT)
	(envelope-from wollman)
Message-Id: <201009232241.o8NMfGfc075522@hergotha.csail.mit.edu>
Date: Thu, 23 Sep 2010 18:41:16 -0400 (EDT)
From: Garrett Wollman <wollman@hergotha.csail.mit.edu>
Reply-To: Garrett Wollman <wollman@hergotha.csail.mit.edu>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [cups-base] slightly more worked-out example devd scripts
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         150891
>Category:       ports
>Synopsis:       print/cups-base: slightly more worked-out example devd scripts
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dinoex
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 23 22:50:01 UTC 2010
>Closed-Date:    Sat Feb 12 20:09:54 CET 2011
>Last-Modified:  Sat Feb 12 20:09:54 CET 2011
>Originator:     Garrett Wollman
>Release:        FreeBSD 8.1-RELEASE amd64
>Organization:
FreeBSD project
>Environment:
System: FreeBSD hergotha.csail.mit.edu 8.1-RELEASE FreeBSD 8.1-RELEASE #0 r212140M: Sat Sep 4 00:16:21 EDT 2010 wollman@hergotha.csail.mit.edu:/usr/obj/usr/src/sys/HERGOTHA amd64

>Description:

cups-base installs a devd configuration fragment that handles one
aspect (permissions) of ulpt devices' transitory existence.  I built
something a little bit more complicated that also pauses and unpauses
the relevant print queues when printers arrive and depart.  I don't
know if anyone else will find this useful -- I didn't even notice the
example script until after I had built mine.  (Is it possible that
cupsd will keep retrying until the printer reappears?  It wasn't at
all obvious to me.)

>How-To-Repeat:


>Fix:

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	ulpt.awk
#	ulpt.conf
#	ulpt.script
#
echo x - ulpt.awk
sed 's/^X//' >ulpt.awk << '0ad6437134085951c9cf3a730210b10c'
X/^<(Default)?Printer[[:space:]]/ { 
X	if (match($0, /[^[:space:]>]+>/)) {
X		PRINTER=substr($0, RSTART, RLENGTH - 1);
X	}
X}
X/^<\/(Default)?Printer/ {
X	PRINTER=""
X}
Xmatch($0, "DeviceURI[[:space:]]+usb:/dev/" ENVIRON["DEVICENAME"] "\$") {
X	print PRINTER
X}
0ad6437134085951c9cf3a730210b10c
echo x - ulpt.conf
sed 's/^X//' >ulpt.conf << '5f167b5e895f429179122d02fa2a01a2'
X# Tell cups to pause and unpause the printer when it arrives and departs.
Xattach 10 {
X	device-name "ulpt[0-9]";
X	action "/etc/devd/ulpt.script enable $device-name";
X};
X
Xdetach 10 {
X	device-name "ulpt[0-9]";
X	action "/etc/devd/ulpt.script disable $device-name";
X};
5f167b5e895f429179122d02fa2a01a2
echo x - ulpt.script
sed 's/^X//' >ulpt.script << '0f8c62a030511cba959e182fedf10721'
X#!/bin/sh
X
Xusage() {
X	echo "$0: usage:" >&2
X	echo "$0 [enable|disable] devicename" >&2
X	exit 1
X}
X
Xif [ -z "$2" ]; then
X	usage
Xfi
X
Xprinter="$(DEVICENAME="$2" awk -f /etc/devd/ulpt.awk /usr/local/etc/cups/printers.conf)"
X
Xif [ -z "$printer" ]; then
X	# nothing to do
X	exit 0
Xfi
X
Xcase "$1" in
Xenable)	chown cups:cups "/dev/$2"
X	/usr/local/sbin/cupsenable "$printer"
X	;;
Xdisable)
X	/usr/local/sbin/cupsdisable "$printer"
X	;;
X*)
X	usage
X	;;
Xesac
Xexit 0
0f8c62a030511cba959e182fedf10721
exit
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->dinoex 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Sep 24 00:01:18 UTC 2010 
Responsible-Changed-Why:  
Fix synopsis and assign. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150891 
State-Changed-From-To: open->feedback 
State-Changed-By: dinoex 
State-Changed-When: Sat Nov 27 10:53:51 CET 2010 
State-Changed-Why:  

Your scripts looks useful. 

Please test this patch. 


diff -ur --exclude=CVS --exclude=Makefile.local -N ./Makefile /usr/ports/current/cups-base/Makefile 
--- ./Makefile	2010-11-27 10:06:57.000000000 +0100 
+++ /usr/ports/current/cups-base/Makefile	2010-11-27 11:06:01.000000000 +0100 
@@ -75,7 +75,7 @@ 
CUPS_SUFFIX=	-image 
LICENSE=	LGPL21 
.else 
-PORTREVISION=	1 
+PORTREVISION=	2 
CUPS_SUFFIX=	-base 
CONFLICTS+=	cupsddk-* 
.endif 
@@ -266,6 +266,8 @@ 
MLINKS=	accept.8 reject.8  
cupsaccept.8 cupsreject.8  
cupsenable.8 cupsdisable.8 
+ 
+SUB_FILES+=	ulpt-cupsd.conf ulpt-cupsd.sh 
.endif 

pre-configure:: 
@@ -361,7 +363,8 @@ 
cd ${CUPS_ETCDIR}/; if test ! -f ${f}; then ${CP} -p ${f}.N ${f}; fi 
.endfor 
${MKDIR} ${EXAMPLESDIR} 
-	${INSTALL_DATA} ${FILESDIR}/lpt-cupsd.conf ${EXAMPLESDIR}/ 
+	${INSTALL_DATA} ${WRKDIR}/ulpt-cupsd.conf ${EXAMPLESDIR}/ 
+	${INSTALL_SCRIPT} ${WRKDIR}/ulpt-cupsd.sh ${PREFIX}/sbin/ 
${INSTALL} -d ${CUPS_SPOOLDIR}/tmp/ 
${CHOWN} -R ${CUPSOWN}:${CUPSGRP} ${CUPS_SPOOLDIR}/ 
${CHMOD} -R g+w ${CUPS_SPOOLDIR}/ 
diff -ur --exclude=CVS --exclude=Makefile.local -N ./files/lpt-cupsd.conf /usr/ports/current/cups-base/files/lpt-cupsd.conf 
--- ./files/lpt-cupsd.conf	2008-01-17 10:15:54.000000000 +0100 
+++ /usr/ports/current/cups-base/files/lpt-cupsd.conf	1970-01-01 01:00:00.000000000 +0100 
@@ -1,17 +0,0 @@ 
-# /usr/local/etc/devd/cups.conf 
-attach 110 { 
-device-name "unlpt[0-9]+"; 
-action "chown cups:cups /dev/$device-name"; 
-}; 
- 
-attach 110 { 
-device-name "ulpt[0-9]+"; 
-action "chown cups:cups /dev/$device-name"; 
-}; 
- 
-attach 110 { 
-device-name "lpt[0-9]+"; 
-action "chown cups:cups /dev/$device-name"; 
-}; 
- 
-# eof 
diff -ur --exclude=CVS --exclude=Makefile.local -N ./files/ulpt-cupsd.conf.in /usr/ports/current/cups-base/files/ulpt-cupsd.conf.in 
--- ./files/ulpt-cupsd.conf.in	1970-01-01 01:00:00.000000000 +0100 
+++ /usr/ports/current/cups-base/files/ulpt-cupsd.conf.in	2010-11-27 10:51:15.000000000 +0100 
@@ -0,0 +1,33 @@ 
+# /usr/local/etc/devd/cups.conf 
+# Tell cups to pause and unpause the printer when it arrives and departs. 
+attach 110 { 
+device-name "unlpt[0-9]+"; 
+action "%%PREFIX%%/sbin/ulpt-cupsd.sh enable $device-name"; 
+}; 
+ 
+attach 110 { 
+device-name "ulpt[0-9]+"; 
+action "%%PREFIX%%/sbin/ulpt-cupsd.sh enable $device-name"; 
+}; 
+ 
+attach 110 { 
+device-name "lpt[0-9]+"; 
+action "%%PREFIX%%/sbin/ulpt-cupsd.sh enable $device-name"; 
+}; 
+ 
+detach 110 { 
+device-name "unlpt[0-9]+"; 
+action "%%PREFIX%%/sbin/ulpt-cupsd.sh disable $device-name"; 
+} 
+ 
+detach 110 { 
+device-name "ulpt[0-9]+"; 
+action "%%PREFIX%%/sbin/ulpt-cupsd.sh disable $device-name"; 
+} 
+ 
+detach 110 { 
+device-name "lpt[0-9]+"; 
+action "%%PREFIX%%/sbin/ulpt-cupsd.sh disable $device-name"; 
+} 
+ 
+# eof 
diff -ur --exclude=CVS --exclude=Makefile.local -N ./files/ulpt-cupsd.sh.in /usr/ports/current/cups-base/files/ulpt-cupsd.sh.in 
--- ./files/ulpt-cupsd.sh.in	1970-01-01 01:00:00.000000000 +0100 
+++ /usr/ports/current/cups-base/files/ulpt-cupsd.sh.in	2010-11-27 10:42:02.000000000 +0100 
@@ -0,0 +1,47 @@ 
+#!/bin/sh 
+# 
+# $FreeBSD$ 
+ 
+usage() { 
+	echo "$0: usage:" >&2 
+	echo "$0 [enable|disable] devicename" >&2 
+	exit 1 
+} 
+ 
+if [ -z "$2" ]; then 
+	usage 
+fi 
+ 
+printer="$(awk -v DEVICENAME="$2" ' 
+/^<(Default)?Printer[[:space:]]/ {  
+	if (match($0, /[^[:space:]>]+>/)) { 
+		PRINTER=substr($0, RSTART, RLENGTH - 1); 
+	} 
+} 
+/^</(Default)?Printer/ { 
+	PRINTER="" 
+} 
+match($0, "DeviceURI[[:space:]]+usb:/dev/" DEVICENAME "$") { 
+	print PRINTER 
+} 
+' %%PREFIX%%/etc/cups/printers.conf)" 
+ 
+if [ -z "$printer" ]; then 
+	# nothing to do 
+	exit 0 
+fi 
+ 
+case "$1" in 
+enable) 
+	chown cups:cups "/dev/$2" 
+	%%PREFIX%%/sbin/cupsenable "$printer" 
+	;; 
+disable) 
+	%%PREFIX%%/sbin/cupsdisable "$printer" 
+	;; 
+*) 
+	usage 
+	;; 
+esac 
+exit 0 
+# eof 
diff -ur --exclude=CVS --exclude=Makefile.local -N ./log /usr/ports/current/cups-base/log 
--- ./log	2010-11-27 10:45:46.000000000 +0100 
+++ /usr/ports/current/cups-base/log	1970-01-01 01:00:00.000000000 +0100 
@@ -1,3 +0,0 @@ 
-- better devd scripts 
-PR:		150891 
-Submitted by:	Garrett Wollman 
diff -ur --exclude=CVS --exclude=Makefile.local -N ./pkg-message /usr/ports/current/cups-base/pkg-message 
--- ./pkg-message	2010-08-28 11:17:42.000000000 +0200 
+++ /usr/ports/current/cups-base/pkg-message	2010-11-27 10:42:43.000000000 +0100 
@@ -21,7 +21,7 @@ 
3) Restart devfs: /etc/rc.d/devfs restart 

If your system supports 'devd' you can copy 
-$PREFIX/share/examples/cups/lpt-cupsd.conf to $PREFIX/etc/devd/ 
+$PREFIX/share/examples/cups/ulpt-cupsd.conf to $PREFIX/etc/devd/ 

To enable printing under Gimp and MS-Windows clients do the following: 

diff -ur --exclude=CVS --exclude=Makefile.local -N ./pkg-plist /usr/ports/current/cups-base/pkg-plist 
--- ./pkg-plist	2010-11-15 06:42:42.000000000 +0100 
+++ /usr/ports/current/cups-base/pkg-plist	2010-11-27 11:09:30.000000000 +0100 
@@ -106,6 +106,7 @@ 
sbin/cupsenable 
sbin/cupsfilter 
sbin/cupsreject 
+sbin/ulpt-cupsd.sh 
sbin/lpadmin 
sbin/lpc 
sbin/lpinfo 
@@ -922,7 +923,7 @@ 
%%DOCSDIR%%/pl/index.html 
%%DOCSDIR%%/robots.txt 
%%DOCSDIR%%/ru/index.html 
-%%EXAMPLESDIR%%/lpt-cupsd.conf 
+%%EXAMPLESDIR%%/ulpt-cupsd.conf 
share/applications/cups.desktop 
share/icons/hicolor/16x16/apps/cups.png 
share/icons/hicolor/32x32/apps/cups.png 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150891 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/150891: commit references a PR
Date: Fri,  7 Jan 2011 21:25:11 +0000 (UTC)

 dinoex      2011-01-07 21:24:59 UTC
 
   FreeBSD ports repository
 
   Modified files:
     print/cups-base      Makefile distinfo pkg-message pkg-plist 
   Added files:
     print/cups-base/files ulpt-cupsd.conf.in ulpt-cupsd.sh.in 
   Removed files:
     print/cups-base/files lpt-cupsd.conf 
   Log:
   - better devd scripts
   PR:             150891
   Submitted by:   Garrett Wollman
   
   - udpate to 1.4.6
   
   Revision  Changes    Path
   1.151     +5 -4      ports/print/cups-base/Makefile
   1.32      +2 -2      ports/print/cups-base/distinfo
   1.2       +0 -17     ports/print/cups-base/files/lpt-cupsd.conf (dead)
   1.1       +38 -0     ports/print/cups-base/files/ulpt-cupsd.conf.in (new)
   1.1       +47 -0     ports/print/cups-base/files/ulpt-cupsd.sh.in (new)
   1.29      +1 -1      ports/print/cups-base/pkg-message
   1.59      +2 -1      ports/print/cups-base/pkg-plist
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: feedback->closed 
State-Changed-By: dinoex 
State-Changed-When: Sat Feb 12 20:09:32 CET 2011 
State-Changed-Why:  
feedback timeout 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150891 
>Unformatted:
