From eab28ede1c32dfbf4c5a4e026beb3339f3e49817 Mon Sep 17 00:00:00 2001
From: Andrew Bower <andrew@bower.uk>
Date: Mon, 16 Dec 2024 23:29:16 +0000
Subject: [PATCH 1/6] d/pcscd.init: restore from history. (Closes: #1090333)

d/pcscd.maintscript: don't remove restored initscript
---
 debian/pcscd.init        | 146 +++++++++++++++++++++++++++++++++++++++
 debian/pcscd.maintscript |   1 -
 2 files changed, 146 insertions(+), 1 deletion(-)
 create mode 100644 debian/pcscd.init

diff --git a/debian/pcscd.init b/debian/pcscd.init
new file mode 100644
index 0000000..58ff62a
--- /dev/null
+++ b/debian/pcscd.init
@@ -0,0 +1,146 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides: pcscd
+# Required-Start:    $local_fs $remote_fs $syslog
+# Required-Stop:     $local_fs $remote_fs $syslog
+# Should-Start:      udev
+# Should-Stop:       udev
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Daemon to access a smart card using PC/SC
+# Description:       The PC/SC daemon is used to dynamically
+#                    allocate/deallocate reader drivers at runtime and manage
+#                    connections to the readers.
+### END INIT INFO
+
+# Authors: 
+#   Carlos Prados Bocos <cprados@debian.org>
+#   Ludovic Rousseau <rousseau@debian.org>
+
+# Do NOT "set -e"
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="PCSC Lite resource manager"
+NAME=pcscd
+DAEMON=/usr/sbin/$NAME
+IPCDIR=/var/run/pcscd
+PIDFILE=$IPCDIR/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+
+# if you need to pass arguments to pcscd you should edit the file
+# /etc/default/pcscd and add a line 
+# DAEMON_ARGS="--your-option"
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
+. /lib/lsb/init-functions
+
+# get LANG variable (code from /etc/init.d/keymap.sh)
+ENV_FILE="none"
+[ -r /etc/environment ] && ENV_FILE="/etc/environment"
+[ -r /etc/default/locale ] && ENV_FILE="/etc/default/locale"
+
+value=$(grep -E "^[^#]*LANG=" $ENV_FILE | tail -n1 | cut -d= -f2)
+eval LANG=$value
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+	# create $IPCDIR with correct access rights
+	if [ ! -d $IPCDIR ]
+	then
+		rm -rf $IPCDIR
+		mkdir $IPCDIR
+	fi
+	chmod 0755 $IPCDIR
+
+	# Return
+	#   0 if daemon has been started
+	#   1 if daemon was already running
+	#   2 if daemon could not be started
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
+		|| return 1
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
+		$DAEMON_ARGS \
+		|| return 2
+	# Add code here, if necessary, that waits for the process to be ready
+	# to handle requests from services started subsequently which depend
+	# on this one.  As a last resort, sleep for some time.
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+	# Return
+	#   0 if daemon has been stopped
+	#   1 if daemon was already stopped
+	#   2 if daemon could not be stopped
+	#   other if a failure occurred
+	start-stop-daemon --stop --quiet --retry=3 --pidfile $PIDFILE --name $NAME
+	RETVAL="$?"
+	[ "$RETVAL" = 2 ] && return 2
+}
+
+case "$1" in
+  start)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+	do_start
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  stop)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+	do_stop
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  status)
+	  status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
+	  ;;
+  restart|force-reload)
+	#
+	# If the "reload" option is implemented then remove the
+	# 'force-reload' alias
+	#
+	log_daemon_msg "Restarting $DESC" "$NAME"
+	do_stop
+	case "$?" in
+	  0|1)
+		do_start
+		case "$?" in
+			0) log_end_msg 0 ;;
+			1) log_end_msg 1 ;; # Old process is still running
+			*) log_end_msg 1 ;; # Failed to start
+		esac
+		;;
+	  *)
+	  	# Failed to stop
+		log_end_msg 1
+		;;
+	esac
+	;;
+  *)
+	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+	exit 3
+	;;
+esac
+
+:
diff --git a/debian/pcscd.maintscript b/debian/pcscd.maintscript
index 478d7ae..3588431 100644
--- a/debian/pcscd.maintscript
+++ b/debian/pcscd.maintscript
@@ -1,2 +1 @@
 rm_conffile /etc/reader.conf.d/0comments 1.9.3-2~ pcscd
-rm_conffile /etc/init.d/pcscd 2.3.0-3~ pcscd
-- 
GitLab


From 84cca1c936267ae448614cafb5e24dfe78be6c44 Mon Sep 17 00:00:00 2001
From: Andrew Bower <andrew@bower.uk>
Date: Mon, 16 Dec 2024 23:30:10 +0000
Subject: [PATCH 2/6] d/pcscd.init: fix hidden whitespace

---
 debian/pcscd.init | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/debian/pcscd.init b/debian/pcscd.init
index 58ff62a..9658b2c 100644
--- a/debian/pcscd.init
+++ b/debian/pcscd.init
@@ -13,7 +13,7 @@
 #                    connections to the readers.
 ### END INIT INFO
 
-# Authors: 
+# Authors:
 #   Carlos Prados Bocos <cprados@debian.org>
 #   Ludovic Rousseau <rousseau@debian.org>
 
@@ -29,7 +29,7 @@ PIDFILE=$IPCDIR/$NAME.pid
 SCRIPTNAME=/etc/init.d/$NAME
 
 # if you need to pass arguments to pcscd you should edit the file
-# /etc/default/pcscd and add a line 
+# /etc/default/pcscd and add a line
 # DAEMON_ARGS="--your-option"
 
 # Exit if the package is not installed
@@ -132,7 +132,7 @@ case "$1" in
 		esac
 		;;
 	  *)
-	  	# Failed to stop
+		# Failed to stop
 		log_end_msg 1
 		;;
 	esac
-- 
GitLab


From cf2c2c2a72989fd553b959f602c00aa23b23042e Mon Sep 17 00:00:00 2001
From: Andrew Bower <andrew@bower.uk>
Date: Mon, 16 Dec 2024 23:30:11 +0000
Subject: [PATCH 3/6] d/pcscd.init: simplify since usr-merge

---
 debian/pcscd.init | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/debian/pcscd.init b/debian/pcscd.init
index 9658b2c..57702e6 100644
--- a/debian/pcscd.init
+++ b/debian/pcscd.init
@@ -19,12 +19,11 @@
 
 # Do NOT "set -e"
 
-# PATH should only include /usr/* if it runs after the mountnfs.sh script
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 DESC="PCSC Lite resource manager"
 NAME=pcscd
 DAEMON=/usr/sbin/$NAME
-IPCDIR=/var/run/pcscd
+IPCDIR=/run/pcscd
 PIDFILE=$IPCDIR/$NAME.pid
 SCRIPTNAME=/etc/init.d/$NAME
 
-- 
GitLab


From 9106adb70ec29daac33f2ad4a3cf754fa4a9dda3 Mon Sep 17 00:00:00 2001
From: Andrew Bower <andrew@bower.uk>
Date: Mon, 16 Dec 2024 23:30:12 +0000
Subject: [PATCH 4/6] d/pcscd.init: remove some legacy boilerplate

---
 debian/pcscd.init | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/debian/pcscd.init b/debian/pcscd.init
index 57702e6..c7dde30 100644
--- a/debian/pcscd.init
+++ b/debian/pcscd.init
@@ -25,7 +25,6 @@ NAME=pcscd
 DAEMON=/usr/sbin/$NAME
 IPCDIR=/run/pcscd
 PIDFILE=$IPCDIR/$NAME.pid
-SCRIPTNAME=/etc/init.d/$NAME
 
 # if you need to pass arguments to pcscd you should edit the file
 # /etc/default/pcscd and add a line
@@ -34,24 +33,10 @@ SCRIPTNAME=/etc/init.d/$NAME
 # Exit if the package is not installed
 [ -x "$DAEMON" ] || exit 0
 
-# Read configuration variable file if it is present
 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
-
-# Load the VERBOSE setting and other rcS variables
 . /lib/init/vars.sh
-
-# Define LSB log_* functions.
-# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
 . /lib/lsb/init-functions
 
-# get LANG variable (code from /etc/init.d/keymap.sh)
-ENV_FILE="none"
-[ -r /etc/environment ] && ENV_FILE="/etc/environment"
-[ -r /etc/default/locale ] && ENV_FILE="/etc/default/locale"
-
-value=$(grep -E "^[^#]*LANG=" $ENV_FILE | tail -n1 | cut -d= -f2)
-eval LANG=$value
-
 #
 # Function that starts the daemon/service
 #
@@ -137,7 +122,7 @@ case "$1" in
 	esac
 	;;
   *)
-	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+	echo "Usage: $0 {start|stop|status|restart|force-reload}" >&2
 	exit 3
 	;;
 esac
-- 
GitLab


From 3e12a0ba0947e6124729a00a0d4be7fea37a5eac Mon Sep 17 00:00:00 2001
From: Andrew Bower <andrew@bower.uk>
Date: Mon, 16 Dec 2024 23:30:14 +0000
Subject: [PATCH 5/6] d/pcscd.init: use PCSCD_ARGS as per systemd

---
 debian/pcscd.init | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/debian/pcscd.init b/debian/pcscd.init
index c7dde30..4efd466 100644
--- a/debian/pcscd.init
+++ b/debian/pcscd.init
@@ -26,13 +26,10 @@ DAEMON=/usr/sbin/$NAME
 IPCDIR=/run/pcscd
 PIDFILE=$IPCDIR/$NAME.pid
 
-# if you need to pass arguments to pcscd you should edit the file
-# /etc/default/pcscd and add a line
-# DAEMON_ARGS="--your-option"
-
 # Exit if the package is not installed
 [ -x "$DAEMON" ] || exit 0
 
+# Prefer PCSCD_ARGS per systemd, falling back to DAEMON_ARGS for old configs.
 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
 . /lib/init/vars.sh
 . /lib/lsb/init-functions
@@ -57,7 +54,7 @@ do_start()
 	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
 		|| return 1
 	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
-		$DAEMON_ARGS \
+		${PCSCD_ARGS-$DAEMON_ARGS} \
 		|| return 2
 	# Add code here, if necessary, that waits for the process to be ready
 	# to handle requests from services started subsequently which depend
-- 
GitLab


From 081c0671a5a82a81964461c8509c690cbf9d6fb4 Mon Sep 17 00:00:00 2001
From: Andrew Bower <andrew@bower.uk>
Date: Mon, 16 Dec 2024 23:30:16 +0000
Subject: [PATCH 6/6] d/pcscd.init: simplify by not creating IPC directory; the
 daemon will do it

---
 debian/pcscd.init | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/debian/pcscd.init b/debian/pcscd.init
index 4efd466..0cb91ce 100644
--- a/debian/pcscd.init
+++ b/debian/pcscd.init
@@ -39,14 +39,6 @@ PIDFILE=$IPCDIR/$NAME.pid
 #
 do_start()
 {
-	# create $IPCDIR with correct access rights
-	if [ ! -d $IPCDIR ]
-	then
-		rm -rf $IPCDIR
-		mkdir $IPCDIR
-	fi
-	chmod 0755 $IPCDIR
-
 	# Return
 	#   0 if daemon has been started
 	#   1 if daemon was already running
-- 
GitLab