Skip to content

Instantly share code, notes, and snippets.

@simonhaenisch
Last active July 16, 2023 19:03
Show Gist options
  • Save simonhaenisch/73d38bd113ec752d1688454293443fcf to your computer and use it in GitHub Desktop.
Save simonhaenisch/73d38bd113ec752d1688454293443fcf to your computer and use it in GitHub Desktop.
Raspberry Pi, Arch Linux, CUPS, Avahi, AirPrint, USB Printer (Samsung SCX)

AirPrint on a USB printer via a Raspberry Pi

  1. Boot into Arch Linux, e. g. from a USB flash installation media.
  2. Follow the installation instructions at https://archlinuxarm.org/platforms/armv6/raspberry-pi.
  3. Log in as alarm with default password alarm (can be an ssh session, i. e. ssh alarm@<ip>).
  4. Switch to super user (default password root) and maybe change the password.
su
passwd
  1. Optional: Create a wifi profile using wifi-menu and then set it to auto-connect on boot with netctl enable <profile-name> (list profiles with ls /etc/netctl).
  2. Change the hostname.
echo rpi-airprint > /etc/hostname
  1. Set timezone.
timedatectl set-timezone Europe/Berlin
  1. Init pacman-key and populate.
pacman-key --init
pacman-key --populate archlinuxarm
  1. Do a full system upgrade.
pacman -Syu
  1. Install some packages.
pacman -S ntp \ # network time protocol
          avahi \ # "Bonjour", see https://www.avahi.org/
          nss-mdns \ # resolve `.local` host names, see http://0pointer.de/lennart/projects/nss-mdns/#overview
          usb-utils \ # for `lsusb`
          cups \ # obviously
          splix \ # this has drivers for a lot of printers, like the Samsung SCX series
          ghostscript \ # tbh not sure whether this is required
          gsfonts # maybe also not required
  1. Enable some services so that they auto-launch on boot.
systemctl enable dhcpcd
systemctl enable ntpd
systemctl enable avahi-daemon
systemctl enable cups.service
  1. Update current time.
ntpd -gq
  1. Configure nss-mdns by opening /etc/nsswitch.conf and changing the hosts: line to include mdns_minimal [NOTFOUND=return] before resolve and dns (see https://wiki.archlinux.org/index.php/avahi#Hostname_resolution).
  2. Reboot.
reboot now
  1. Now you can use the hostname to ssh into the Raspberry (at least if you're on macOS).
ssh [email protected]
  1. Connect the printer via USB and turn it on. You can check whether it's connected with lsusb.
  2. Configure CUPS so that the web interface is accessible on the network (i. e. http://rpi-airprint.local:631) and all printers are shared.
cupsctl --remote-admin --remote-any --share-printers
  1. Add the printer to CUPS (see https://wiki.archlinux.org/index.php/CUPS).
lpinfo -v # list the devices => find the uri
lpinfo -m # list the models => find the driver

# create a new queue
lpadmin -p Samsung_SCX-4300 \ # queue name
        -E \ # enable
        -v usb://Samsung/SCX-4300%20Series?serial=1457BFGQ605469H.&interface=1 \ # uri
        -m drv:///splix-samsung.drv/scx4300.ppd # model
  1. Optional: set as default printer and print test page.
lpoptions -d Samsung_SCX-4300
lpr /usr/share/cups/data/testprint
  1. Determine the printer type (enum) as hex.
ipptool -tv ipp://localhost:631/printers/Samsung_SCX-4300 get-printer-attributes.test \
  | grep printer-type \ # gets us sth like `printer-type (enum) = 12356`
  | tr -dc '0-9' \ # only take the digits
  | xargs printf '0x%x\n' # convert to hex
  1. Create an Avahi service file, e. g. /etc/avahi/services/samsung-scx-4300-airprint.service with the following content.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">Samsung SCX-4300 @ %h</name> <!-- replace with your printer name -->
  <service>
    <type>_ipp._tcp</type>
    <subtype>_universal._sub._ipp._tcp</subtype>
    <port>631</port>
    <txt-record>txtvers=1</txt-record>
    <txt-record>qtotal=1</txt-record>
    <txt-record>Transparent=T</txt-record>
    <txt-record>URF=none</txt-record>
    <txt-record>rp=printers/Samsung_SCX-4300</txt-record> <!-- replace with your queue name -->
    <txt-record>note=Office</txt-record> <!-- this shows up as "Location" -->
    <txt-record>product=(GPL Ghostscript)</txt-record>
    <txt-record>printer-state=3</txt-record> <!-- I think 3 means "idle" but not sure -->
    <txt-record>printer-type=0x3044</txt-record> <!-- Whatever hex value the previous step printed -->
    <txt-record>pdl=application/octet-stream,application/pdf,application/postscript,application/vnd.cups-raster,image/gif,image/jpeg,image/png,image/tiff,image/urf,text/html,text/plain,application/vnd.adobe-reader-postscript,application/vnd.cups-pdf</txt-record>
  </service>
</service-group>
  1. Might need to systemctl restart cups.service or avahi-daemon but it should all work now.

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment