Thursday, January 14, 2016

Airprint with OpenSUSE in my house

Two HP printers:
  • HP Color LaserJet 2600n
  • HP LaserJet CP1525nw
Quick todo List
  • OpenSUSE 13.2
  • CUPS
  • HPLIP
  • Configure CUPS
  • Run hp-setup (looks for a graphical display)
  • Avahi mime files generate
I'm running a VMware ESXi lab so it's an easy decision to install a Linux server that can act as the print server.  Installing OpenSUSE appears to automatically include CUPS during the basic deployment.  I won't go through the OS install here.  I'm going to assume the server is up and running for now and you are familiar with installing additional OpenSUSE applications in YaST.

In YaST, install HPLIP to provide the necessary printer drivers and tools.  To configure CUPS, I make the following changes in /etc/cups/cupsd.conf (add or modify these in the file - the following is just a subset of the cupsd.conf file):

# ServerAlias will prevent host name errors when a client makes a request
ServerAlias *

# By default, localhost is configured for Listen.  I want to manage from anywhere in my network.
Listen *:631

#My server has a static address of 192.168.1.11/24. 
# Restrict access to the server...
<Location />
  Order allow,deny
  Allow 127.0.0.2
  Allow 192.168.1.0/24
</Location>

# Restrict access to the admin pages...
<Location /admin>
  Order allow,deny
  Allow 192.168.1.0/24
</Location>

# Restrict access to configuration files...
<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
  Allow 192.168.1.0/24
</Location>

Save the file and restart CUPS with with the command service cups restart.

I use the CUPS web portal to configure the printer (http://192.168.1.11:631).  HPLIP provides the correct drivers.  For the CP1525nw I'm using the driver HP LaserJet CP1520 Series Postscript.  For the 2600n, I use HP Color LaserJet 2600n hpijs.  You'll see that a proprietary driver is required.  We'll get to that in a moment.  I completed the add process for both printers.

For the proprietary driver, on the server as root, run the command hp-setup.  Select the 2600n in the list of printers and accept the defaults.  Once that was completed, I restarted CUPS from the terminal.  From the CUPS web portal, I printed a test page to both printers.  All should be successful at this point.

We're ready to make the printers Airprint-able.

Create the following two files:

/usr/share/cups/mime/airprint.convs with the content:
image/urf application/pdf 100 imagetoraster

/usr/share/cups/mime/airprint.types with the content:
image/urf urf string(0,UNIRAST<00>)

On your server as root, download and execute airprint-generate.py using the following:
wget https://github.com/tjfontaine/airprint-generate/archive/master.zip
unzip master.zip
cd airprint-generate-master
./airprint-generate.py

When I executed the script, I ended up with two files:
AirPrint-HP_Color_LaserJet_2600n.service
AirPrint-HP_LaserJet_CP1525nw.service

If you view the files in VI, you'll see see they are not formatted.  They're XML files so it's easy to fix.  Open each file in VI and enter the substitute command without quotes:
":1,$s/></>^M</g"  (to get the ^M, you'll need to use the keystrokes ctrl-v ctrl-m) 

The substitution will use place a line feed after each '>'.  You should now see a better formatted file.  Save the file and exit vi.

Copy the two files to /etc/avahi/services/

Restart Avahi with service avahi-daemon restart

You should now see the printers on your devices.  For me, I use the AirPrint advertised printers on our iPads, iPhones and Macs.