summaryrefslogtreecommitdiffstats
path: root/core/modules/cups
diff options
context:
space:
mode:
authorSimon Rettberg2017-03-13 11:24:32 +0100
committerSimon Rettberg2017-03-13 11:24:32 +0100
commite2f6fe704223e15c1efc24c040bd68db06eace3d (patch)
tree487ed6920280b20a667b2ca79a1d56e4b05bb67b /core/modules/cups
parentSeems some files were given an extra shebang with c79dec3ba517967c09ef398b20d... (diff)
downloadmltk-e2f6fe704223e15c1efc24c040bd68db06eace3d.tar.gz
mltk-e2f6fe704223e15c1efc24c040bd68db06eace3d.tar.xz
mltk-e2f6fe704223e15c1efc24c040bd68db06eace3d.zip
[cups] Add prestart script that fixed config problems
CUPS < 2.0 requires the <DefaultPrinter> to be closed by a </Printer> tag, while newer versions allow </DefaultPrinter>. Patch the printers.conf if required. Also makes sure the permissions of /etc/cups/* are somewhat sane.
Diffstat (limited to 'core/modules/cups')
-rw-r--r--core/modules/cups/data/etc/systemd/system/cups.service1
-rwxr-xr-xcore/modules/cups/data/opt/openslx/scripts/systemd-cupsd_prestart31
2 files changed, 32 insertions, 0 deletions
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 <DefaultPrinter> tag to be closed by </Printer>, while
+# CUPS >= 2.0 allowed you to use the more logical </DefaultPrinter>. 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,</DefaultPrinter>,</Printer>,' "/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
+