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

Bug#520753: Potential serious bug on ghostscript-cups



Le vendredi, 27 juillet 2012 14.23:27, Jonas Smedegaard a écrit :
> severity 520753 serious
> thanks
> 
> On 12-07-27 at 11:48am, Bastien ROUCARIES wrote:
> > Bug 520753 is about a faillure in postinst script when /etc/cups/ppd
> > is not present. i am tented to raise this bug as serious, because ti
> > could break install.
> 
> Agreed.

A nice solution to this bug is IMHO to replicate in ghostscript-cups what has 
been done for most packages shipping Cups drivers: transform the postinst code 
into a dpkg trigger and let the Cups postinst do the job "as cups".

See the Cups postinst and e.g. c2esp, which has a file under 
/usr/share/cups/ppd-updaters/ containing the two only package-specific 
informations (DRIVER_REGEXP & GENNICKNAME_REGEXP) and a Breaks against 
"cups (<< 1.5.0-2~)" which is the version at which this was finally corrected.

This would reduce the code duplication, move more of what is cups' job to 
cups, and solve this RC bug (by ensuring that the postinst code only gets run 
by cups, so only when cups is installed).

A possible patch is attached; 

Cheers

OdyX
From 353726d65c2db847f3ba9b9fd69d1e09fc60614d Mon Sep 17 00:00:00 2001
From: Didier Raboud <odyx@debian.org>
Date: Sun, 29 Jul 2012 14:18:32 +0200
Subject: [PATCH] Replace the PPD-updater postinst by CUPS' trigger (Closes: #520753)

  - Breaks against too old cups versions.
  - Add a ppd-updater file, to trigger with parameters.
---
 debian/changelog                    |    6 +++
 debian/control.in                   |    1 +
 debian/control.in.in                |    1 +
 debian/ghostscript-cups.install     |    3 ++
 debian/ghostscript-cups.postinst    |   62 -----------------------------------
 debian/ghostscript-cups.ppd-updater |    2 +
 6 files changed, 13 insertions(+), 62 deletions(-)
 delete mode 100644 debian/ghostscript-cups.postinst
 create mode 100644 debian/ghostscript-cups.ppd-updater

diff --git a/debian/changelog b/debian/changelog
index 2f94a6a..f174b3e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,6 @@
 ghostscript (9.05~dfsg-7) UNRELEASED; urgency=low
 
+  [ Jonas Smedegaard ]
   * Clarify consequences of linking against shared libjpeg (i.e. not
     setting custom D_MAX_BLOCKS_IN_MCU).
     Closes: bug#582522. Thanks to Bastien ROUCARIÈS.
@@ -22,6 +23,11 @@ ghostscript (9.05~dfsg-7) UNRELEASED; urgency=low
   * Add patch cherry-picked upstream, to improve error feedback.
     Closes: bug#682407. Thanks to Bastien ROUCARIÈS and Chris Liddell.
 
+  [ Didier Raboud ]
+  * Replace the PPD-updater postinst by CUPS' trigger (Closes: #520753)
+    - Breaks against too old cups versions.
+    - Add a ppd-updater file, to trigger with parameters.
+
  -- Jonas Smedegaard <dr@jones.dk>  Tue, 24 Jul 2012 20:54:10 +0200
 
 ghostscript (9.05~dfsg-6) unstable; urgency=low
diff --git a/debian/control.in b/debian/control.in
index 992655e..85f712c 100644
--- a/debian/control.in
+++ b/debian/control.in
@@ -43,6 +43,7 @@ Recommends: ${cdbs:Recommends},
 Conflicts: ${cdbs:Conflicts}
 Replaces: ${cdbs:Replaces}
 Provides: ${cdbs:Provides}
+Breaks: cups (<< 1.5.0-2~)
 Description: interpreter for the PostScript language and for PDF - CUPS filters
  GPL Ghostscript is used for PostScript/PDF preview and printing.
  Usually as a back-end to a program such as ghostview, it can display
diff --git a/debian/control.in.in b/debian/control.in.in
index 05d1310..7db845c 100644
--- a/debian/control.in.in
+++ b/debian/control.in.in
@@ -43,6 +43,7 @@ Recommends: ${cdbs:Recommends},
 Conflicts: ${cdbs:Conflicts}
 Replaces: ${cdbs:Replaces}
 Provides: ${cdbs:Provides}
+Breaks: cups (<< 1.5.0-2~)
 Description: interpreter for the PostScript language and for PDF - CUPS filters
  GPL Ghostscript is used for PostScript/PDF preview and printing.
  Usually as a back-end to a program such as ghostview, it can display
diff --git a/debian/ghostscript-cups.install b/debian/ghostscript-cups.install
index 4cef0b0..b7747bd 100644
--- a/debian/ghostscript-cups.install
+++ b/debian/ghostscript-cups.install
@@ -5,3 +5,6 @@ etc/cups/*.convs	usr/share/cups/mime/
 
 usr/lib/cups/filter/
 usr/share/ppd/
+
+# Cups triggering file
+debian/ghostscript-cups.ppd-updater	usr/share/cups/ppd-updaters/
diff --git a/debian/ghostscript-cups.postinst b/debian/ghostscript-cups.postinst
deleted file mode 100644
index 3bed084..0000000
--- a/debian/ghostscript-cups.postinst
+++ /dev/null
@@ -1,62 +0,0 @@
-#! /bin/bash
-
-set -e
-
-# Limit lp* commands to localhost to avoid hanging. See bug#543468
-lpopts='-h /var/run/cups/cups.sock'
-
-case "$1" in
-    configure)
-	# Do the following only if CUPS is running and the needed CUPS tools
-	# are available
-	# and directory /etc/cups/ppd exist (see #520753)
-	if which lpstat > /dev/null 2>&1 \
-	  && which lpinfo > /dev/null 2>&1 \
-	  && which lpadmin > /dev/null 2>&1 \
-	  && test -d /etc/cups/ppd \
-	  && LC_ALL=C lpstat $lpopts -r > /dev/null 2>&1; then
-		# Update the PPD files of all already installed print queues
-		driverregexp='lsb/usr/ghostscript/'
-		gennicknameregexp=''
-		[ ! -z "$gennicknameregexp" ] \
-		  && gennicknameregexp="; $gennicknameregexp"
-		gennicknameregexp='s/\s*\(recommended\)//'"$gennicknameregexp"
-		tempfiles=
-		trap 'rm -f $tempfiles; exit 0' 0 HUP INT QUIT ILL ABRT PIPE TERM
-		tmpfile1=`mktemp -t updateppds.XXXXXX`
-		tempfiles="$tempfiles $tmpfile1"
-		lpinfo $lpopts -m | grep -E $driverregexp > $tmpfile1
-		cd /etc/cups/ppd
-		for ppd in *.ppd; do
-			[ -r "$ppd" ] || continue
-			queue=${ppd%.ppd}
-			lpstat $lpopts -p "$queue" >/dev/null 2>&1 || continue
-			nickname=`grep '\*NickName:' "$ppd" | cut -d '"' -f 2 | perl -p -e 's/\n$//' | perl -p -e "$gennicknameregexp" | perl -p -e 's/(\W)/\\\\$1/g'`
-			lang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'`
-			ppdfound="0"
-			englishppduri=""
-			tmpfile2=`mktemp -t updateppds.XXXXXX`
-			tempfiles="$tempfiles $tmpfile2"
-			cat $tmpfile1 | perl -p -e "$gennicknameregexp" | grep -E '^\S+\s+.*'"$nickname"'$' | cut -d ' ' -f 1 > $tmpfile2
-			while read newppduri; do
-				[ "$ppdfound" = "0" ] && lpadmin $lpopts -p "$queue" -m $newppduri 2>/dev/null || continue
-				newlang=`grep '\*LanguageVersion:' "$ppd" | cut -d ' ' -f 2 | perl -e 'print lc(<>)' | perl -p -e 's/[\r\n]//gs'`
-				[ "$newlang" = "$lang" ] && ppdfound="1"
-				[ "$newlang" = "english" ] && englishppduri="$newppduri"
-			done < $tmpfile2
-			[ "$ppdfound" = "0" ] && [ ! -z "$englishppduri" ] && lpadmin $lpopts -p "$queue" -m $englishppduri 2>/dev/null && ppdfound="1"
-			[ "$ppdfound" = "1" ] && echo PPD for printer $queue updated >&2
-		done
-	fi
-	;;
-    abort-upgrade|abort-remove|abort-deconfigure)
-	;;
-    *)
-	echo "postinst called with unknown argument \`$1'" >&2
-	exit 1
-	;;
-esac
-
-#DEBHELPER#
-
-exit 0
diff --git a/debian/ghostscript-cups.ppd-updater b/debian/ghostscript-cups.ppd-updater
new file mode 100644
index 0000000..fbeed05
--- /dev/null
+++ b/debian/ghostscript-cups.ppd-updater
@@ -0,0 +1,2 @@
+DRIVER_REGEXP='lsb/usr/ghostscript/'
+GENNICKNAME_REGEXP=''
-- 
1.7.2.5


Reply to: