AirPrint emulation on Entware with fewer hiccups : HOWTO - davygravy/AirPrint-on-Entware GitHub Wiki

AirPrint emulation on Entware/Entware-NG with fewer hiccups

This intends to be a predictable, no-surprises, quick-starting, no-mess, no-fuss and relatively painless way to get AirPrint emulation working on a capable Entware/Entware-NG equipped router or other devices. I’ve tested on my TomatoUSB/Merlin armv7 and mipselsf-k2.6 routers.

Thanks and acknowledgements to ryzhovau, zyxmon and others from the Entware project. Their Entware project fills an important niche for those of us who want to get a bit more functionality out of our routers and other embedded devices.

Problem: When trying to set up AirPrint emulation on a router or other such device, CUPS and some of the other packages seem to be missing a few capabilities and components. In particular, CUPS needs avahi/bonjour support built in, which due to understandable upstream policies, is not likely to happen. The vanilla Entware packages are great, but the maintainers are pretty much locked into the OpenWRT upstream content. So when we ask for changes to CUPS like avahi support, they can’t really custom-tailor that for us.

Solution: Re-roll the packages with fixes and some additions. Note: Security Comment: Make sure you read up on securing CUPS on your device. Don’t assume that the default cupsd.conf file included meets your security needs.


Instructions:

  1. Assumptions and requirements:

    • An Entware*-compatible device with 2 USB ports. This How-to assumes TomatoUSB or Merlin, but it might work on DD-WRT with some changes.

    • Device has one of the following freshly installed:

      • Entware [ arm7-k2.6 and mipselsf-k3.4 only ]

      • Entware-ng [ mipselsf; ie. really mipselsf-k2.6 ]

      • Entware-backports [ Entware-reloaded for older mipsel Broadcom routers ]

    • at least 500MB of space on the /opt partition; recommedation : 2GB

    • SWAP! You will most likely need to enable swap space, especially if your router has less than 256MB of RAM. If free shows that you have less than 128000 free kb of memory, then you will almost certainly need to turn on swap. The more complex the printing job, the more memory your system will need; recommendation : 500MB minumum.

    • If you have an older mipsel router (like a Belkin ShareMax N300, for instance), you need to seriously consider lowering the resolution of your prints. See the Troubleshooting section regarding slow printing.

    • IP address of your router is 'myrouter_ip', and its hostname is 'myrouter'.

    • correct user/group added to your router for avahi, and if you have TomatoUSB, you’ve patched /etc/passwd. [ see Avahi and CUPS user setup on Entware ]

    • a USB-attached printer that is already connected by p910nd and registered as some /dev/lp0 (or similar) device, tested and known working.

    • realization of the limitations of your router/device and its CPU. Don’t expect it to be instantaneous: Broadcom and ARM router CPU’s are not desktop/laptop CPU’s, so know that it might take 15 seconds or more to print an email, for instance.

    • read and heed the Troubleshooting section at the end, especially if you have a router with less than 256MB of RAM.

    • If you need more security, then read the CUPS man pages and make it more secure.

    • Be familiar and aware of the user structure and layout on your device’s firmware. For instance, MerlinWRT firmware does not have a root user, but rather admin.

    • Read and follow the directions say, not what they seem to say after a quick glance…​ This is said respectfully…​there are a lot of steps to this, but I’ve tested it out on 4 different routers and it worked each time. YMMV.

    • If you find a typo, please post an "Issue" so that it can be fixed. Thanks.

  2. Install some base packages, some necessary and others that can just make things easier (like sftp if you need to transfer some files in):

    opkg update
    opkg install wget terminfo zlib libjpeg libexpat dbus avahi-daemon avahi-utils file nano htop libbz2 openssh-sftp-server  -t /opt/tmp

Note that if you are running MerlinWRT, you will not normally have a "root" user, so you’ll have to run dbus with another user, such as nobody. To do this, edit /opt/share/dbus-1/system.conf and find the following line:

<!-- Run as special user -->
<user>root</user>

and change it to:

<!-- Run as special user -->
<user>nobody</user>
  1. Choose your variant and download the airprint-support-<variant>.tar.gz tarball to /opt/tmp and untar.

Feedname points to the variant name:

  • Entware armv7-k2.6 → armv7

  • Entware mipselsf-k3.4 → mipselsf

  • Entware-ng → mipselsf-k2.6-EntNG

  • Entware-backports → mipselsf-k2.6-EntBP

    cd /opt/tmp
    ### ARMV7 ONLY
    wget-ssl --no-check-certificate  https://github.com/davygravy/AirPrint-on-Entware/blob/master/airprint-support-armv7.tar.gz?raw=true  -O  airprint-support-armv7.tar.gz
    ### Newer MIPSELSF routers with a 3.4 kernel ONLY
    wget-ssl --no-check-certificate  https://github.com/davygravy/AirPrint-on-Entware/blob/master/airprint-support-mipselsf.tar.gz?raw=true  -O airprint-support-mipselsf.tar.gz
    ### Older MIPSELSF Routers with Entware-NG and a 2.6 kernel ONLY
    wget-ssl --no-check-certificate  https://github.com/davygravy/AirPrint-on-Entware/blob/master/airprint-support-mipselsf-k2.6-EntNG.tar.gz?raw=true -O airprint-support-mipselsf-k2.6-EntNG.tar.gz
    ### Older MIPSELSF Routers with Entware-backports and a 2.6 kernel ONLY
    wget-ssl --no-check-certificate  https://github.com/davygravy/AirPrint-on-Entware/blob/master/airprint-support-mipselsf-k2.6-EntBP.tar.gz?raw=true -O airprint-support-mipselsf-k2.6-EntBP.tar.gz
    ### substitute in YOUR variant's name according to your choice above...
    tar xzvf airprint-support-<variant>.tar.gz
    cd airprint-support-<variant>
  1. Install components:

For armv7 :

opkg --force-checksum install cups_2.2.10-3_armv7-2.6.ipk libcups_2.2.10-3_armv7-2.6.ipk cups-filters_1.22.1-2_armv7-2.6.ipk liberation-fonts_2.00.1-1_armv7-2.6.ipk ghostscript -t /opt/tmp

For mipselsf :

opkg --force-checksum install cups_2.2.10-3_mipsel-3.4.ipk libcups_2.2.10-3_mipsel-3.4.ipk cups-filters_1.22.1-2_mipsel-3.4.ipk  liberation-fonts_2.00.1-1_mipsel-3.4.ipk ghostscript -t /opt/tmp

For mipselsf-k2.6-EntNG (older legacy routers using Entware-ng and kernel 2.6):

opkg install --force-checksum cups_2.2.6-3_mipselsf.ipk cups-bsd_2.2.6-3_mipselsf.ipk cups-client_2.2.6-3_mipselsf.ipk cups-ppdc_2.2.6-3_mipselsf.ipk cups-locales_2.2.6-3_mipselsf.ipk cups-filters_1.22.1-2_mipselsf.ipk libcups_2.2.6-3_mipselsf.ipk libcupsimage_2.2.6-3_mipselsf.ipk libcupscgi_2.2.6-3_mipselsf.ipk libcupsmime_2.2.6-3_mipselsf.ipk libcupsppdc_2.2.6-3_mipselsf.ipk  qpdf_8.4.0-1_mipselsf.ipk liberation-fonts ghostscript_9.26-2_mipselsf.ipk -t /opt/tmp

For mipselsf-k2.6-EntBP (older legacy routers using Entware-backports and kernel 2.6):

opkg install --force-checksum cups_2.2.10-3_mipselsf.ipk libcups_2.2.10-3_mipselsf.ipk cups-filters ghostscript -t /opt/tmp
  1. Install additional AirPrint support packages (if you have printer that is not HP, you may want to install the gutenprint package as well):

All variants=Everyone

opkg install python-cups python-lxml nano -t /opt/tmp

If you have an HP Printer and Entware/Entware-Backports:

opkg install hplip-full -t /opt 

If you have an HP Printer and Entware-NG:

wget-ssl --no-check-certificate  https://github.com/davygravy/AirPrint-on-Entware/blob/master/hplip_3.18.12-1_mipselsf.ipk?raw=true -O hplip_3.18.12-1_mipselsf.ipk
opkg install --force-checksum hplip_3.18.12-1_mipselsf.ipk -t /opt/tmp

If you have a Non-HP printer (maybe this will work…​ check your docs of your printer)

opkg install gutenprint -t /opt 
6. Restart all services. Start htop and look to see that cupsd, avahi-daemon and dbus are all running. If all is OK, then press "q" to quit htop.
   /opt/etc/init.d/rc.unslung stop;  sleep 5;  /opt/etc/init.d/rc.unslung start
   htop
   q
7. Check that you can connect to the CUPS webif via browser. Using Firefox, Chrome, or another browser, open the following URL http://myrouter_ip:631 . You should see the standard CUPS webinterface. If so, click on the Admin tab, and you’ll see something similar to the image below:
CUPS Admin Webif
  1. Click the Add Printer button. Choose (probably) AppSocket/HP JetDirect. Enter your router’s loopback address and port 9100, looking something like:

    socket://127.0.0.1:9100
  2. Give it a Name, a Description, and a Location, AND check Share This Printer. Press Continue and wait patiently.

  3. Choose the "Make" of your printer, press Continue and after a some moments of processing, the window will reload. Chose your printer model, e.g. "HP Color Photosmart c4400 series hpcups (eng)". Press Add Printer and wait patiently.

  4. Set default options for your printer. Hint: "Black-only Grayscale", "Plain Paper" and "Fast Draft" are great for printing emails, pdf documents, etc. Remember that your router has a very basic CPU that is not designed for image processing. Simpler, lower-resolution output will make your printing go much faster. Photos or rich graphics may take a long time…​ or even overwhelm it. Also, under *Printers>Administration: choose your printer as the "Set as Server Default" option.

  5. Under the Maintenance tab, chose "Print Test Page". After 10-90 seconds or so a generic CUPS printer test page should print out. You may want to monitor your router’s CPU and memory load with top or htop while attempting to print this test page. If you have an older router with less than 128MB RAM, then read the troubleshooting section on "Slow Printing". Don’t go to the next step until you are sure that you can print the test page.

  6. cd into the directory with files that you downloaded:

    cd airprint-support-<variant>

…​or you can down load the python script called airprint-generate.py from TJFontaine’s Github repo. Make it executable, and then execute it. It will create an avahi-service file and place it in /opt/etc/avahi/services/, and it will prepend "Airprint-" to the name you gave to your printer earlier in this process. The command will take at perhaps 15 seconds, and should be non-verbose (generate no visible text output). Check that it worked by listing the contents of /opt/etc/avahi/services and scan for AirPrint- files. If your printer’s name is "Drukkerij", then that ls command should yield output that mentions "AirPrint-Drukkerij".

chmod +x airprint-generate.py
python airprint-generate.py -d /opt/etc/avahi/services/
ls /opt/etc/avahi/services/ | grep AirPrint
  1. Restart avahi, cups and dbus.

    /opt/etc/init.d/rc.unslung stop;  sleep 5;  /opt/etc/init.d/rc.unslung start
  2. You should now be able to print emails, text documents, and simple pdfs directly from your iPhone or iPad. Test, and troubleshoot if necessary.

  3. Troubleshooting:

    • python-lxml package not found?

      • This particular package may be optional. It reformats xml files to be human readable, so some users may not find it to be essential. Leave it out if you don’t need it. At the time of writing this comment, it was available in all feeds except the Entware-backports feed.

    • No output?

      • Make sure that Step #12 worked! If printing a test page through CUPS via p910nd isn’t working, then you aren’t close yet. You may want to try to use lp to print some simple text as a test. For instance echo testing | lp .

      • Reboot your router.

      • Watch top or htop to see if ghostscript is processing the job when you print via AirPrint.

      • Set CUPS to save debug info to the error log. Check /opt/var/log/cups/error_log to see what is happening.

        • See this kind of error?: error while loading shared libraries: libpoppler.so.65: cannot open shared object file: No such file or directory If so, you may be able to fix this by creating a symlink to the actual library, with the required name.

        • CUPS says "Filter failed" is perhaps one of the least helpful diagnostic messages ever designed. It could be a driver problem, your router running out of memory/RAM, or quite a few other things.

    • Prints, but sslllowwwwllly?

      • Change your printer defaults to Fast Draft

      • In the case that your router/device is a older mipsel device without a lot of RAM, you can edit the PPD for your printer. You will probably be able to find your printer’s PPD in /opt/etc/cups/ppd/. You can attempt to edit it, and cut the resolution in 1/2 or 1/4. In my HPC4480.ppd file, I replaced the original resolution (dpi) values :

        *OutputMode Normal/Normal: "<</OutputType(0)/HWResolution[600 600]>>setpagedevice"
        *OutputMode Draft/Draft: "<</OutputType(-1)/HWResolution[300 300]>>setpagedevice"
        *OutputMode Best/Best: "<</OutputType(1)/HWResolution[600 600]>>setpagedevice"
        *OutputMode Photo/High-Resolution Photo: "<</OutputType(2)/HWResolution[1200 1200]>>setpagedevice"
        *OutputMode FastDraft/Fast Draft: "<</OutputType(-2)/HWResolution[300 300]>>setpagedevice"
        with resolution that is 1/4 (or 1/2) of the values above:
        *OutputMode Normal/Normal: "<</OutputType(0)/HWResolution[150 150]>>setpagedevice"
        *OutputMode Draft/Draft: "<</OutputType(-1)/HWResolution[75 75]>>setpagedevice"
        *OutputMode Best/Best: "<</OutputType(1)/HWResolution[300 300]>>setpagedevice"
        *OutputMode Photo/High-Resolution Photo: "<</OutputType(2)/HWResolution[300 300]>>setpagedevice"
        *OutputMode FastDraft/Fast Draft: "<</OutputType(-2)/HWResolution[75 75]>>setpagedevice"
        This can make both text and graphics more pixelated. So I find it is fine for emails and the like, but not so good for pictures where you want to see details. The tradeoff is that now jobs are printed nearly instantaneously.
⚠️ **GitHub.com Fallback** ⚠️