From e2f6fe704223e15c1efc24c040bd68db06eace3d Mon Sep 17 00:00:00 2001
From: Simon Rettberg
Date: Mon, 13 Mar 2017 11:24:32 +0100
Subject: [cups] Add prestart script that fixed config problems
CUPS < 2.0 requires the to be closed by
a tag, while newer versions allow .
Patch the printers.conf if required.
Also makes sure the permissions of /etc/cups/* are somewhat sane.
---
.../cups/data/etc/systemd/system/cups.service | 1 +
.../opt/openslx/scripts/systemd-cupsd_prestart | 31 ++++++++++++++++++++++
2 files changed, 32 insertions(+)
create mode 100755 core/modules/cups/data/opt/openslx/scripts/systemd-cupsd_prestart
(limited to 'core/modules/cups')
diff --git a/core/modules/cups/data/etc/systemd/system/cups.service b/core/modules/cups/data/etc/systemd/system/cups.service
index 1c1e6305..a634804a 100644
--- a/core/modules/cups/data/etc/systemd/system/cups.service
+++ b/core/modules/cups/data/etc/systemd/system/cups.service
@@ -6,4 +6,5 @@ Before=graphical.target
ConditionFileNotEmpty=/etc/cups/printers.conf
[Service]
+ExecStartPre=-/opt/openslx/scripts/systemd-cupsd_prestart
ExecStart=/usr/sbin/cupsd -f
diff --git a/core/modules/cups/data/opt/openslx/scripts/systemd-cupsd_prestart b/core/modules/cups/data/opt/openslx/scripts/systemd-cupsd_prestart
new file mode 100755
index 00000000..b00f82b2
--- /dev/null
+++ b/core/modules/cups/data/opt/openslx/scripts/systemd-cupsd_prestart
@@ -0,0 +1,31 @@
+#!/bin/ash
+
+CUPSD=$(which cupsd)
+if [ -z "$CUPSD" ]; then
+ echo "Could not find CUPSd binary - doing nothing"
+ exit 0
+fi
+
+VERSION=$(strings -n 8 "$CUPSD" | grep -E '^CUPS v[0-9]\.' | head -n 1)
+if [ -z "$VERSION" ]; then
+ echo "Could not extract CUPS version from $CUPSD - doing nothing"
+ exit 0
+fi
+
+# CUPS before 2.0 required the tag to be closed by , while
+# CUPS >= 2.0 allowed you to use the more logical . Convert the config
+# in case the user supplied new style and we run old cups
+MAJOR=${VERSION:6:1}
+if [ -n "$MAJOR" ] && [ "$MAJOR" -lt 2 ]; then
+ echo "CUPS < 2.0, patching printers.conf"
+ [ -s "/etc/cups/printers.conf" ] && sed -i 's,,,' "/etc/cups/printers.conf"
+fi
+
+# Set proper permissions
+chmod +rx "/etc/cups"
+chmod -R +rX "/etc/cups/ppd"
+chmod 0600 "/etc/cups/printers.conf"
+chown -R root:lp "/etc/cups/printers.conf" "/etc/cups/ppd"
+
+exit 0
+
--
cgit v1.2.3-55-g7522