Friday 29 December 2006

Using an NSLU2 as a USB print server

(Update 3.ix.2011: This article is ancient.  I now run debian on my
slug rather than unslung and it is no longer serving as my print
server.  This article is kept for posterity)

I've configured my NSLU2 as a USB print server using CUPS.

My NSLU2 "Slug" is running OpenDebianSlug, and followed the
instructions at
[http://www.nslu2-linux.org/wiki/DebianSlug/Printing](http://www.nslu2-linux.org/wiki/DebianSlug/Printing)
for instructions on how to install the `usblp` module and CUPS.  To
summarise, as `root`

    wget http://ipkg.nslu2-linux.org/feeds/openslug/cross/2.7-beta/kernel-module-usblp_XXXX.ipk
    dpkg --force-all i kernel-module-usblp_XXXX.ipk
    depmod -a
    apt-get install cupsys hotplug

I then configured my printer as `printer` using the `links` text-based
browser on the slug itself.

In windows, I set up an IPP printer to print to my CUPS printer.

The set up works fine, except for one major flaw.  If I send a job to
the printer while it is switched off, CUPS can't print and so stops
`printer`.  When the printer is switched back on, `printer` still
accepts print jobs, but it is stopped.  The only way to get the
printer going again is to Start the printer, for example via the web
interface on port 631.

I found a solution by adapting the script found on
[http://www.trustix.org/wiki/index.php/Configure_CUPS](http://www.trustix.org/wiki/index.php/Configure_CUPS).
I created a file `/etc/hotplug/usb/usblp` with the following contents:

    #!/bin/sh
    #
    #
    # Arguments :
    # -----------
    # ACTION=[add|remove]
    # DEVICE=/proc/bus/usb/BBB/DDD
    # TYPE=usb 

    if [ "$ACTION" = "add" -a "$TYPE" = "usb" ]; then
      /sbin/modprobe printer
      for i in `/usr/bin/lpstat -v |awk '$4 ~ /usb:/ {print $3;}'|sed -e 's/://g'`;do
        /usr/bin/enable $i
        /usr/sbin/accept $i
      done
    fi

What this does is Start `printer` (that's what `/usr/bin/enable` does)
whenever it detects a hotplug `add` event.  I had to install
`cupsys-client`:

    apt-get install cupsys-client

to get the command `/usr/bin/enable`.