CAPS Universe documentation  1.0.4
All you need to know to be successful
The Printer Driver Launcher and udev

'udev' Setup

Since all printer drivers needs to be triggered when the corresponding printing device gets attached to the host, some help from udev is required. The following udev rule file needs to be in place:

/
└── usr
    └── lib
        └── udev
            └── rules.d
                └── 99-caps.rules
Note
This is an example only. It depends on your UDEV Rules configuration, where this file is installed to.

This udev rule file matches if a USB based printer gets attached to the host and just starts a corresponding systemd service unit (e.g. caps-printer@.service).

# starts the 'caps-printer@.service' unit whenever a USB printer device occurs
# Everything between the @ and the .service will be used to form the %i or %I parameter
#
ACTION=="add", SUBSYSTEM=="usbmisc", ENV{DEVNAME}=="* /usb/lp*", TAG+="systemd", PROGRAM="/usr/bin/systemd-escape -p --template=caps-printer@.service $env{DEVNAME}", ENV{SYSTEMD_WANTS}+="%c"

How does it work:

  • ACTION=="add": run this line only, if the device is added to the system
  • SUBSYSTEM=="usbmisc": USB printers belongs to the usbmisc subsystem, sorts out other USB devices
  • ENV{DEVNAME}=="* /usb/lp*": the device node must match to this expression /dev/usb/lp0 would be the device node for the first printer in your system

If one of these expression doesn't match, the device addition is ignored. If all of these expressions match, the remaining part of the line is processed:

  • TAG+="systemd": systemd should handle this event
  • PROGRAM="…": this starts a templated service unit and forwards the device node encoded to it. /dev/usb/lp0 needs to be encoded to dev-usb-lp0 to make it work.