Update: No need to set the
CUPS-SERVER environment variable in
snapcraft.yaml of application Snaps.
For all the snappers around here, I want to give you a sneak preview, so that you can try out the new interface and also test your application Snaps. This way you do not need to wait for the release of snapd 2.55.
Install the snapd Snap with
cupsinterface: A snapshot of snapd with
cupsinterface is available in the Snap Store, in the Edge channel. So you need to switch your snapd to the edge channel:
sudo snap refresh snapd --edge --amend
Get CUPS Snap source from OpenPrinting GitHub: The CUPS Snap currently in the Snap Store does not support the new
cupsinterface. The change mentioned in the previous post needs to get applied. Therefore download the source of the Snap so that you can modify and rebuild it:
git clone https://github.com/OpenPrinting/cups-snap.git
snapcraft.yaml: Look for the definition of the slots (
slots:) and add the line “
cups-socket-directory: $SNAP_COMMON/run” to the
cups:entry (patch below). DO NOT add “
assumes: [snapd2.55]” as the snapshot of snapd still has a 2.54. … version.
Rebuild the CUPS Snap: To rebuild your modified Snap you need to have
snapcraftinstalled. Then you run the command
Make sure the CUPS Snap from the Snap Store is installed: If it is not done yet, install the CUPS Snap from the Snap Store, to make all its interfaces auto-connected:
sudo snap install --edge cups
Install your modified CUPS Snap on your system: You “upgrade” from the Snap Store’s version. The interfaces stay connected. Use the command
sudo snap install --dangerous cups_0.1.0_amd64.snap
This is the patch for
snapcraft.yaml of the CUPS Snap:
--- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -66,6 +66,7 @@ slots: interface: cups-control cups: interface: cups + cups-socket-directory: $SNAP_COMMON/run apps: cupsd:
Now we have the new CUPS Snap environment up and running, so we can do the first simple test:
Copy the following
name: cups-admin-test-no-control base: core20 # The base snap is the execution environment for this snap version: 0.1.0 summary: CUPS admin and non-admin tasks out of a Snap description: Testing interfaces for the CUPS Snap (no cups-control plugging, so admin tasks should fail) grade: stable confinement: strict apps: lpinfo: command: usr/sbin/lpinfo plugs: [network, cups] lpadmin: command: usr/sbin/lpadmin plugs: [network, avahi-observe, home, cups] lpstat: command: usr/bin/lpstat plugs: [network, avahi-observe, cups] lpoptions: command: usr/bin/lpoptions plugs: [network, home, cups] lp: command: usr/bin/lp plugs: [network, home, cups] cancel: command: usr/bin/cancel plugs: [network, cups] lpmove: command: usr/sbin/lpmove plugs: [network, cups] cupsenable: command: usr/sbin/cupsenable plugs: [network, cups] cupsdisable: command: usr/sbin/cupsdisable plugs: [network, cups] cupsaccept: command: usr/sbin/cupsaccept plugs: [network, cups] cupsreject: command: usr/sbin/cupsreject plugs: [network, cups] accept: command: usr/sbin/cupsaccept plugs: [network, cups] reject: command: usr/sbin/cupsreject plugs: [network, cups] cupsctl: command: usr/sbin/cupsctl plugs: [network, cups] parts: cups-client: plugin: dump source: . stage-packages: - cups-client - libcups2 prime: - usr/bin/* - usr/sbin/* - usr/lib/*
Put it into a new, empty directory, build, install it, and connect the interfaces:
snapcraft snap sudo snap install --dangerous cups-admin-test-no-control_0.1.0_amd64.snap sudo snap connect cups-admin-test-no-control:avahi-observe sudo snap connect cups-admin-test-no-control:cups cups:cups
The Snap simply puts together the command line tools of CUPS, exactly the ones of the CUPS package which comes with Ubuntu 20.04 LTS, what
core20 is based on. Some commands are administrative, like
lpinfo and others are not, like
snapcraft.yaml you see how easy it is to use the interface. If one of the contained applications (
apps: section) wants to print or otherwise non-administratively access CUPS (for example to list print queues and/or jobs) you only need to add
cups to the application’s list of
plugs:. If you have an own Snap with an application which prints but not a printer setup tool, simply replace
cups-control in the
Now let us execute some of the commands in this Snap:
$ cups-admin-test-no-control.lpstat -H /var/cups/cups.sock $ cups-admin-test-no-control.lpstat -v device for printer_on_snap: ... $ cups-admin-test-no-control.lpinfo -v lpinfo: Forbidden $ cups-admin-test-no-control.lpadmin -x printer_on_snap lpadmin: Forbidden $ cups-admin-test-no-control.lpstat -v device for printer_on_snap: ... $
You see that you get a
Forbidden on administrative commands and the others work normally. Also the Snap’s commands are talking to the snapped CUPS (
cups-admin-test-no-control.lpstat -H gives
/var/cups/cups.sock and not
/run/cups/cups.sock). You only see your system’s CUPS queues because the CUPS Snap is running in proxy mode.
If you use the
cups-control interface instead of
cups for the
plugs:, your Snap will talk directly to your system’s CUPS and the administrative commands will work.
Now you could try out one of your application Snaps, like a GUI application where one can print via a print dialog. If you do the changes correctly and manually connect your Snap’s
cups interface with
cups:cups, the print dialog should work normally, listing the available print queues and allowing you to set options and print the job.
Do not try this with a printer setup tool like system-config-printer, as a result it will show you the current print queues but you will not be able to modify them or add new one. Such applications have to continue using
Also do never use the
cups interface for one application in your Snap and the
cups-control interface in another. As you will request manual permission for your Snap to auto-connect
cups-control anyway, use
cups-control for all the applications. Or create two Snaps, one containing only the non-administrative applications and another one only the administrative ones.
Please post your experiences and questions here in this thread.