Bug#718798: cups-daemon: suggestions for init script: bashisms, lsb...

2013-08-05 Thread Nicolas Boulenguez
Package: cups-daemon
Version: 1.6.2-10
Severity: minor
Tags: patch

Hello. Please consider the attached changes, inspired by
/etc/init.d/skeleton and
http://refspecs.linuxbase.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html.
The skeleton may suggest many other easy improvements in calls to
start-stop-daemon, but I lack knowledge of CUPS to decide such
changes.

Comments, roughly in the order of the attached diff:

SCRIPTNAME replaces N=${0##*/}. This construct is specific to bash,
while init scripts may be executed by sh.

Include /lib/init/vars.sh and respect VERBOSE when appropriate.

Replace restart_xprint() implicit parameter (success) with an explicit
first parameter for readability.

log_daemon_msg() should be used instead of log_begin_msg(). The former
wraps the latter with vendor-specific formatting.

I tryed to clarify the exit status handling. For example: in start),
the displayed $? was the one of coldplug_usb_printers instead of the
one from start-stop-daemon.

coldplug_usb_printer was called even if in case of failure to start
the daemon. I changed this, but maybe this was wanted.

status_of_proc() replaces hand-written status reporting, with a more
accurate selection of non-zero exit statuses. It needs lsb-base (=
3.2-14).

Unimplemented actions must return 3.
diff --git a/debian/control b/debian/control
index 549219d..f1c333a 100644
--- a/debian/control
+++ b/debian/control
@@ -142,7 +142,7 @@ Depends: ${shlibs:Depends},
  poppler-utils (= 0.12),
  procps,
  ghostscript (= 9.02~),
- lsb-base (= 3),
+ lsb-base (= 3.2-14),
  cups-common (= ${source:Version}),
  cups-server-common (= ${source:Version}),
  cups-client (= ${binary:Version}),
diff --git a/debian/cups-daemon.cups.init b/debian/cups-daemon.cups.init
index 06a6d8f..de25cee 100644
--- a/debian/cups-daemon.cups.init
+++ b/debian/cups-daemon.cups.init
@@ -14,22 +14,33 @@
 #make it's web interface accessible on http://localhost:631/
 ### END INIT INFO
 
+# Author: Debian Printing Team debian-printing@lists.debian.org
+
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 DAEMON=/usr/sbin/cupsd
 NAME=cupsd
 PIDFILE=/var/run/cups/$NAME.pid
 DESC=Common Unix Printing System
+SCRIPTNAME=/etc/init.d/cups
 
 unset TMPDIR
 
+# Exit if the package is not installed
 test -x $DAEMON || exit 0
 
 mkdir -p /var/run/cups/certs
 
+# Read configuration variable file if it is present
 if [ -r /etc/default/cups ]; then
   . /etc/default/cups
 fi
 
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (= 3.2-14) to ensure that this file is present
+# and status_of_proc is working.
 . /lib/lsb/init-functions
 
 # Get the timezone set.
@@ -38,8 +49,9 @@ if [ -z $TZ -a -e /etc/timezone ]; then
 export TZ
 fi
 
+# Only effective if first parameter = 0.
 restart_xprint() {
-if [ -n $success ]  [ -x /etc/init.d/xprint ]; then
+if [ $1 = 0 ]  [ -x /etc/init.d/xprint ]; then
 invoke-rc.d xprint force-reload || true
 fi
 }
@@ -57,7 +69,7 @@ coldplug_usb_printers() {
 
 case $1 in
   start)
-	log_begin_msg Starting $DESC: $NAME
+	[ $VERBOSE != no ]  log_daemon_msg Starting $DESC $NAME
 
 	mkdir -p `dirname $PIDFILE`
 	if [ $LOAD_LP_MODULE = yes -a -f /usr/lib/cups/backend/parallel \
@@ -67,50 +79,41 @@ case $1 in
 	  modprobe -q -b parport_pc || true
 	fi
 
-	start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON  success=1
-
-	coldplug_usb_printers
-	log_end_msg $?
-	restart_xprint
+	start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
+	status=$?
+	[ $status = 0 ]  coldplug_usb_printers
+	[ $VERBOSE != no ]  log_end_msg $status
+	restart_xprint $status
 	;;
   stop)
-	log_begin_msg Stopping $DESC: $NAME
-	start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE --name $NAME  success=1
-	log_end_msg $?
-	restart_xprint
+	[ $VERBOSE != no ]  log_daemon_msg Stopping $DESC $NAME
+	start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE --name $NAME
+	status=$?
+	[ $VERBOSE != no ]  log_end_msg $status
+	restart_xprint $status
 	;;
   reload|force-reload)
-   log_begin_msg Reloading $DESC: $NAME
-   start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $NAME --signal 1  success=1
-   log_end_msg $?
-	restart_xprint
+   log_daemon_msg Reloading $DESC $NAME
+   start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $NAME --signal 1
+   status=$?
+   log_end_msg $status
+   restart_xprint $status
;;
   restart)
-	log_begin_msg Restarting $DESC: $NAME
+	log_daemon_msg Restarting $DESC $NAME
 	if start-stop-daemon --stop --quiet --retry 5 --oknodo --pidfile $PIDFILE --name $NAME; then
-		start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON  success=1
+		start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
 	fi
-	log_end_msg $?
-	restart_xprint
+	status=$?
+	log_end_msg 

Bug#895659: gutenprint: please stop using --ignore debhelper option

2018-04-14 Thread Nicolas Boulenguez
Source: gutenprint
Version: 5.3.0~pre1-2
Severity: wishlist
Tags: patch

Hello.

Debhelper is considering deprecating the --ignore option.
It is used once in gutenprint.

Commit 5b3f43f1 stops installing the usb directory on non Linux architectures.
Among other changes, it moves "usr/share/cups/usb" from
debian/printer-driver-gutenprint.install to the freshly created
debian/printer-driver-gutenprint.install.linux.
The intent was probably that both files are used when
DEB_HOST_ARCH_OS=linux, else only the first one.

This does not work because debhelper only considers the most specific file.
Commit 49ffeb1f fixes this in debian/rules by adding:
  ifeq ($(DEB_BUILD_ARCH_OS),linux)
# Install common files
dh_install -pprinter-driver-gutenprint 
--ignore=debian/printer-driver-gutenprint.install.linux
  endif
right before
dh_install -a

The effect is that
* on linux, the first dh_install run installs normal files,
  and the second run installs the usb directory.
* on other architectures, dh_install is only run once and installs the
  normal files.

If all this is correct, the attached patch should have the same effect
in a more readable way, and without --ignore.

Thanks.
--- a/debian/printer-driver-gutenprint.install.linux
+++ /dev/null
@@ -1 +0,0 @@
-usr/share/cups/usb
--- a/debian/rules
+++ b/debian/rules
@@ -38,10 +38,9 @@ override_dh_clean:
 
 override_dh_install-arch:
 ifeq ($(DEB_BUILD_ARCH_OS),linux)
-	# Install common files
-	dh_install -pprinter-driver-gutenprint --ignore=debian/printer-driver-gutenprint.install.linux
+	dh_install -pprinter-driver-gutenprint usr/share/cups/usb
 endif
-	dh_install -a
+	dh_install -a --remaining-packages
 # Remove rpath
 	find debian/printer-driver-gutenprint/usr/lib -type f -perm /0111 -print0 | xargs -0 chrpath --delete
 # Install ppd-updater file