Package: cups-pdf
Version: 2.4.8-4
Severity: normal
Tags: patch
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu intrepid ubuntu-patch

We applied these changes in Ubuntu and thought you might consider doing the 
same:
Sometime due to restart/configuration race condition the PDF-printer (queue) is 
not created
We have modified the postinstall so that it no longer restarts cups and 
installs a pdf queue and printer.
Patches are attached.

*** /tmp/tmpowFKGE
In Ubuntu, we've applied the attached patch to achieve the following:

  * Merge from debian unstable (LP: #310290), remaining changes:
    - debian/postinst, debian/prerm: Let PDF print queue being created
      automatically when installing the package and being removed
      automatically when uninstalling the package.
    - debian/postinst: Updated PPD file name to the new one used by the
      upstream package (LP: #241701). Updated the name of the CUPS startup
      script to "cups".

We thought you might be interested in doing the same. 


-- System Information:
Debian Release: lenny/sid
  APT prefers intrepid-updates
  APT policy: (500, 'intrepid-updates'), (500, 'intrepid-security'), (500, 
'intrepid-backports'), (500, 'intrepid')
Architecture: i386 (i686)

Kernel: Linux 2.6.27-9-generic (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
diff -u cups-pdf-2.4.8/debian/changelog cups-pdf-2.4.8/debian/changelog
diff -u cups-pdf-2.4.8/debian/postinst cups-pdf-2.4.8/debian/postinst
--- cups-pdf-2.4.8/debian/postinst
+++ cups-pdf-2.4.8/debian/postinst
@@ -14,9 +14,81 @@
                chown nobody:nogroup /var/spool/cups-pdf/ANONYMOUS
                chmod 1777 /var/spool/cups-pdf/ANONYMOUS
                chmod 0700 /usr/lib/cups/backend/cups-pdf
+               # This package needs the CUPS daemon running to actually work
                if [ -f /etc/init.d/cups ]
                then
-                       invoke-rc.d cups force-reload || invoke-rc.d cups start 
|| /bin/true
+                       lpstat -r > /dev/null 2>&1 || invoke-rc.d cups start || 
/bin/true
+               fi
+               if lpstat -r > /dev/null 2>&1
+               then
+                       # Create a PDF CUPS queue if we have none yet (only
+                       # if CUPS daemon is running)
+                       if [ -z "`LC_ALL=C lpstat -v 2>/dev/null | grep 
'cups-pdf:/'`" ]
+                       then
+                               # Find a name for the PDF queue
+                               queue=PDF
+                               number=0
+                               while LC_ALL=C lpstat -v 2>/dev/null | cut -d 
':' -f 1 | cut -d ' ' -f 3 | grep -q ^$queue\$
+                               do
+                                       number=$(($number + 1))
+                                       queue="PDF$number"
+                               done
+                               # Find system's default paper size
+                               size="`LC_ALL=C paperconf 2>/dev/null`" || 
size=a4
+                               # Create the queue
+                               lpadmin -h localhost -p $queue -E -v cups-pdf:/ 
-m lsb/usr/cups-pdf/CUPS-PDF.ppd -o printer-is-shared=no -o PageSize=$size 
2>/dev/null || :
+                               # Set the PDF printer as default when there is 
not
+                               # already a default printer
+                               #if [ -z "`LC_ALL=C lpstat -d 2>/dev/null | 
grep 'system default destination:'`" ]
+                               #then
+                               #       lpadmin -d $queue 2>/dev/null || :
+                               #fi
+                       fi
+               else
+                       # Create a PDF CUPS queue if we have none yet (for the
+                       # case that CUPS is not running or even not installed)
+                       if [ -z "`grep 'DeviceURI cups-pdf:/' 
/etc/cups/printers.conf 2> /dev/null`" ]
+                       then
+                               # Find a name for the PDF queue
+                               queue=PDF
+                               number=0
+                               while grep -q "Printer $queue>" 
/etc/cups/printers.conf
+                               do
+                                       number=$(($number + 1))
+                                       queue="PDF$number"
+                               done
+                               # Find system's default paper size
+                               size="`LC_ALL=C paperconf 2>/dev/null`" || 
size=a4
+                               # Create the queue
+                               time=`date +%s`
+                               mkdir -p /etc/cups/ppd
+                               cat << EOF >> /etc/cups/printers.conf
+<Printer $queue>
+Info Print into PDF file
+DeviceURI cups-pdf:/
+State Idle
+StateTime $time
+Accepting Yes
+Shared No
+JobSheets none none
+QuotaPeriod 0
+PageLimit 0
+KLimit 0
+OpPolicy default
+ErrorPolicy retry-job
+</Printer>
+EOF
+                               cp /usr/share/ppd/cups-pdf/CUPS-PDF.ppd 
/etc/cups/ppd/$queue.ppd
+                               ucsize=`echo $size | perl -p -e 
's/^(\S)(\S*)/uc($1) . $2/e'`
+                               perl -p -i -e 
's/^(\*DefaultPageSize:\s*)\S+/$1'$ucsize'/' /etc/cups/ppd/$queue.ppd
+                               perl -p -i -e 
's/^(\*DefaultPageRegion:\s*)\S+/$1'$ucsize'/' /etc/cups/ppd/$queue.ppd
+                               perl -p -i -e 
's/^(\*DefaultImageableArea:\s*)\S+/$1'$ucsize'/' /etc/cups/ppd/$queue.ppd
+                               perl -p -i -e 
's/^(\*DefaultPaperDimension:\s*)\S+/$1'$ucsize'/' /etc/cups/ppd/$queue.ppd
+                               if [ -f /etc/init.d/cups ]
+                               then
+                                   lpstat -r > /dev/null 2>&1 || invoke-rc.d 
cups start || /bin/true
+                               fi
+                       fi
                fi
        ;;
 
diff -u cups-pdf-2.4.8/debian/postrm cups-pdf-2.4.8/debian/postrm
--- cups-pdf-2.4.8/debian/postrm
+++ cups-pdf-2.4.8/debian/postrm
@@ -13,10 +13,6 @@
                then
                        rm -rf /var/spool/cups-pdf
                fi
-               if [ -f /etc/init.d/cups ]
-               then
-                       invoke-rc.d cups force-reload || invoke-rc.d cups start 
|| /bin/true
-               fi
        ;;
 
        abort-upgrade|upgrade|failed-upgrade|remove|disappear)
only in patch2:
unchanged:
--- cups-pdf-2.4.8.orig/debian/prerm
+++ cups-pdf-2.4.8/debian/prerm
@@ -0,0 +1,29 @@
+#! /bin/sh
+# prerm script for cups-pdf
+
+set -e
+
+case "$1" in
+       remove)
+               # Remove all PDF queues (only if CUPS daemon is running)
+               if `lpstat -r > /dev/null 2>&1`
+               then
+                       for queue in `LC_ALL=C lpstat -v 2>/dev/null | grep 
'cups-pdf:/' | cut -d ':' -f 1 | cut -d ' ' -f 3`
+                       do
+                               lpadmin -x $queue 2>/dev/null || :
+                       done
+               fi
+               ;;
+       upgrade|deconfigure)
+               ;;
+       failed-upgrade)
+               ;;
+       *)
+               echo "prerm called with unknown argument \`$1'" >&2
+               exit 1
+               ;;
+esac
+
+#DEBHELPER#
+
+exit 0

Reply via email to