Friday, March 21, 2014

Cups 1.7.5, 2.0, or 2.1 on Raspberry Pi Raspbian

In my attempt to turn the raspberry pi into a wireless printer server for my usb connected Canon s530d printer (yes, i'm well overdue for a 21st century printer upgrade, just wanted to see if I could make it work), I have concluded that cups and a bunch of other requirements need to be installed.  To accomplish this, the prerequisite list is long and compiling is time consuming, so patience must be a prerequisite to these prerequisites.  I chose to compile all of these from scratch instead of apt-get all of them because the raspbian and ubuntu-based distros have versions of cups that are highly outdated.  As of writing this I believe they are still on 1.5.3, not good.  To stay up-to-date, you should go with my route to ensure you are running the latest cups software.
A great source for looking up the proper way to install the programs is linuxfromscratch.org.

Update 12/23/2014
cups 1.7 is no longer maintained.
choose either cups 2.0 or 2.1 

Few disclaimers:
*** Needs adequate power ***
Some printers are power hungry (like mine) and the pi will incidentally freeze without warning due to too much current drawl through the host USB port.  I have been working just fine with plugging in a pair of iphone usb chargers totaling approximately 2 amps joint by a usb y-cable.  This one exactly http://www.amazon.com/gp/product/B0047AALS0/ref=wms_ohs_product?ie=UTF8&psc=1

*** Will not work with all printers ***
My Canon s530d requires experimental gutenprint drivers so I have included those steps below

*** Lengthy compile times ***
 Seriously, if you are compiling all of the sources below, you're gonna have a lot of down time.  It usually takes me about 2-3 hours from the first step to the last for a full installation.

Download the following sources:
qpdf  "git clone https://github.com/qpdf/qpdf.git"
poppler "wget http://poppler.freedesktop.org/poppler-0.24.5.tar.xz"
cups-filters "http://www.openprinting.org/download/cups-filters/cups-filters-1.0.54.tar.bz2"
cups "https://www.cups.org/software/1.7.5/cups-1.7.4-source.tar.bz2" or "git clone -b branch-1.7 http://www.cups.org/cups.git cups-1.7" or "git clone http://www.cups.org/cups.git cups-2.0" or
"git clone http://www.cups.org/cups.git cups-2.1"
ghostscript - "git clone http://git.ghostscript.com/ghostpdl.git"
foomatic-db - "wget http://www.openprinting.org/download/foomatic/foomatic-db-current.tar.gz"
gutenprint - "http://sourceforge.net/projects/gimp-print/files/gutenprint-5.2/5.2.10/gutenprint-5.2.10.tar.bz2"

Bonus! Google Cloud Print!
Cloud Print "git clone git://github.com/simoncadman/CUPS-Cloud-Print.git"

To start off:
So the process goes smoothly, remove all references to cups, ghostscript, foomatic, cups-filters, and gutenprint in the apt package manager and file system.  To do this I normally use apt-get remove cups* and "locate cups" on the command line to find the files and remove the files manually.  That way I am not accidentally ruining my system by removing files that should not be removed.

The process is nearly the same with all of the installs (with a few excepts on a few of them) and using sudo before every command is highly recommended
  • autoconf
  • ./configure
  • make
  • sudo make install

Initial cleanup:
Find unnecessary  preinstalled packages by running the following:
dpkg --get-selections | grep -v deinstall | grep cups
dpkg --get-selections | grep -v deinstall | grep poppler
dpkg --get-selections | grep -v deinstall | grep ghostscript
dpkg --get-selections | grep -v deinstall | grep foomatic-db

or you could simply run this:
dpkg --get-selections | grep -v deinstall | egrep '^(cups|poppler|ghostscript|foomatic-db)' | awk '{print $1 }' | tr '\n ' ' ''' | xargs sudo apt-get remove 


Remove all preinstalled packages that look like this:
cups-*
poppler-*

So the compiler doesn't find any precompiled libraries find any files that have the reference of libcups* and libpoppler*, then remove them.

For me, I had to do the following:
sudo rm  /usr/lib/arm-linux-gnueabihf/libcups*
sudo rm  /usr/lib/arm-linux-gnueabihf/libpoppler*
sudo find . -name cups* -not -path "./home/pi/*" -exec rm -rf {} \;

--------------------------------------------------------------------------------------------------------------

1. QPDF
cd qpdf
autoconf
./configure --enable-doc-maintenance
make (at the end of the make you should see a summary of what is available, resolve any dependencies as you wish like docbooks)
sudo make install

there should be no errors, if there are it is most likely dependency issues.  Also, this part has the longest compile time.

--------------------------------------------------------------------------------------------------------------

2. POPPLER
cd poppler
./autogen.sh
./configure --enable-libcurl
make
sudo make install

once again, resolve dependencies as necessary.  At the end of the poppler configure you should see a summary that resembles the following code.  Make sure you have cairo output, libjpeg, libpng, libtiff, and libopenjpeg checked off with yes.  You have to have at least those checked for cups-filters to install properly.


Building poppler with support for:
  font configuration: fontconfig
  splash output:      yes
  cairo output:       yes
  qt4 wrapper:        yes
  qt5 wrapper:        no
  glib wrapper:       yes
    introspection:    no
  cpp wrapper:        yes
  use gtk-doc:        no
  use libjpeg:        yes
  use libpng:         yes
  use libtiff:        yes
  use zlib:           yes
  use libcurl:        yes
  use libopenjpeg:    yes
  use cms:            yes
      with lcms2
  command line utils: yes
  test data dir:      /home/pi/Projects/poppler-0.24.5/./../test


--------------------------------------------------------------------------------------------------------------

3. CUPS
Just follow these instructions http://www.linuxfromscratch.org/blfs/view/svn/pst/cups.html
They did a good job, and i'd basically be copy and pasting.  You don't have to do the patch so here are the instructions without it.
For <username> , insert an admin user you would like to have control over the printer settings.  I used my default "pi" user.  You can add as many as you would like.

useradd -c "Print Service User" -d /var/spool/cups -g lp -s /bin/false -u 9 lp
groupadd -g 19 lpadmin
usermod -a -G lpadmin <username>

cd cups-1.7.5
or
cd cups-2.0*

./configure
make
sudo make install
echo "ServerName /var/run/cups/cups.sock" > /etc/cups/client.conf

--------------------------------------------------------------------------------------------------------------

4. GHOSTSCRIPT
cd ghostpdl/gs
sudo apt-get install libxt-dev
./autogen.sh
./configure
make
sudo make install
sudo make install-so

--------------------------------------------------------------------------------------------------------------

5.CUPS-FILTERS
cd cups-filters-1.0.54
autoconf
./configure
make
sudo make install

--------------------------------------------------------------------------------------------------------------


****This step is optional and is dependent upon the requirements of your printer driver****6. FOOMATIC-DB
cd ghostpdl
sudo apt-get install libxt-dev
./configure
make
sudo make install

--------------------------------------------------------------------------------------------------------------

****This step is optional and is dependent upon the requirements of your printer driver**** 
7. GUTENPRINT
cd gutenprint-5.2.10
sudo apt-get install texlive-fonts-extra doxygen
./configure
make
sudo make install

--------------------------------------------------------------------------------------------------------------

8. Google Cloud Print
cd CUPS-Cloud-Print
./configure
make install

--------------------------------------------------------------------------------------------------------------

Add the following at the top of /etc/init.d/cups by sudo vim /etc/init.d/cups
then run "sudo update-rc.d"

### BEGIN INIT INFO
# Provides:          cups
# Required-Start:    $syslog $remote_fs
# Required-Stop:     $syslog $remote_fs
# Should-Start:      $network avahi
# Should-Stop:       $network
# X-Start-Before:    samba
# X-Stop-After:      samba
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: CUPS Printing spooler and server
### END INIT INFO

this prevents the following loop message when trying to install other packages and invoking update-rc.d:
"insserv: Starting cups depends on plymouth and therefore on system facility `$all' which can not be true!"

--- 
The installation should be finished with no errors, now we have to fix some issues with cups because the new cups-filters uses newer methods for test banners.
Follow the instructions to fix this here: http://www.bsmdevelopment.com/Reference/Tech_20130002.html

Easiest way to get to the web interface without editing the conf file for cups is use lynx and do the following:

apt-get install lynx
lynx http://localhost:631
Use the arrows to navigate to the administration word, type "y" to enable the cookie, and a new page should populate.  In the middle of the page you should see "Allow remote adminstration".  Navigate with the "down" arrow to the bottom and press enter on the desired highlighted box.  It will ask for authentication, use the root or current username and password as long as it is part of the lpadmin group described in the CUPS link.

sudo cupsctl --remote-admin

Trial and error resolutions:

If you receive the error:
syntax error near unexpected token `win32-dll' trying to run ./configure
for qpdf or poppler, run the command:
aclocal
then
autoreconf -i
try ./configure again and you should be good to go
___________________________________________________________________

If you receive the error
libqpdf/SecureRandomDataProvider.cc:92:4: error: #error "Don't know how to generate secure random numbers on this platform.  See random number generation in the top-level README" 
trying to configure qpdf, configure using:
./configure --enable-insecure-random
___________________________________________________________________

If you receive the error:
/home/pi/Projects/cups-filters-1.0.48/filter/pdftoraster.cxx:1807: undefined reference to `GfxColorSpace::setDisplayProfile(void*)'
Make sure you have libopenjpeg-dev installed.  Configure, recompile, and install poppler again.  Then cups-filters again.
___________________________________________________________________

If you receive an error that contains anything with an undefined reference to pwg* like pwgMediaForLegacy
The compiler is linking to an older library which means you may have a previous version of cups or a cups library installed.
When I received this error I had to remove all cups libraries in the following folder:
/usr/lib/arm-linux-gnueabihf/
to find all references to the libraries for your computer, use locate to find installation files don't appear to be in the correct or "ls -l" a folder to check the date and see if it's rather old.  The files I had removed had the date of October 13th, 2013.  They definitely should not be there and should be removed.
apt-get remove cups*
rm /usr/lib/arm-linux-gnueabihf/"cups libraries"
and you should be good to go
___________________________________________________________________

If you receive the error "Error: Success" (or something along those lines) when trying to automatically find the driver for the printer or "lpinfo -m" doesn't populate any drivers, most likely the foomatic drivers are conflicting with the gutenprint drivers.
To fix it, locate every "foomatic" reference and "sudo rm -r" it.
Reinstall the cups-filters and gutenprint drivers and run "lpinfo -m" if any drivers populate you should be good to go.
OR
you could change the permissions of the foomatic driver database by "chmod 644 /usr/lib/cups/driver/foomatic-db-driver"
___________________________________________________________________

If you receive the following error in your error page under the administrative menu:
no profiles specified in PPD
Then you need to install ghostscript.  See step 4.

9 comments:

  1. Hi Jimmy,

    I'm trying to build `cups-filters` as you have described, but I got an error message:

    "./.libs/libcupsfilters.so: undefined reference to `pwgMediaForLegacy'"

    Can you help me with this?

    Regards,
    Giacomo

    ReplyDelete
  2. Certainly, this was a tricky one for me.
    The compiler was linking libscupsfilter.so to a library installed in /usr/lib/arm-linux-gnueabihf/
    apt-get remove "cups programs that look like this cups-* or libcups-* "
    and
    apt-get remove "poppler programs that look like this poppler-* or libpoppler-* "
    locate any and all references to libcups* as well as libpoppler* and remove them.
    Then
    ./configure && sudo make && sudo make install
    again

    I really hope this helps! I've updated the post to reflect this.

    ReplyDelete
  3. You can use this command to `apt-get remove` all packages in one go

    $ sudo apt-get remove `dpkg --get-selections | grep -v deinstall | egrep '^(cups|poppler|ghostscript|foomatic-db)' | awk '{ print $1 }' | tr '\n' ' '`

    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
    bc cmap-adobe-japan1 hplip-data libart-2.0-2 libcupscgi1 libcupsfilters1 libcupsmime1 libcupsppdc1 libgutenprint2 libsane-hpaio libslp1 python-imaging python-pexpect python-renderpm python-reportlab
    python-reportlab-accel ssl-cert
    Use 'apt-get autoremove' to remove them.
    The following packages will be REMOVED:
    cups-bsd cups-client cups-common foomatic-db-compressed-ppds foomatic-db-engine ghostscript ghostscript-cups libgs9 poppler-data poppler-utils printer-driver-c2050 printer-driver-pnm2ppa
    printer-driver-ptouch printer-driver-sag-gdi
    0 upgraded, 0 newly installed, 14 to remove and 55 not upgraded.
    After this operation, 28.8 MB disk space will be freed.
    Do you want to continue [Y/n]?

    ReplyDelete
    Replies
    1. Yes, there are many ways to skin this cat but that certainly is a more efficient use then my repetitive lines.
      I'm going to add it in the blog. Thanks!

      Delete
  4. I receive an error using this command:
    "git pull http://git.ghostscript.com/ghostpdl.git"

    fatal: Not a git repository (or any of the parent directories): .git

    ReplyDelete
    Replies
    1. try "git clone git://git.ghostscript.com/ghostpdl.git"
      It should work out

      Delete
    2. oops! Sorry about that, typo. I'll fix that right now, should definitely be git clone

      Delete
  5. Easiest way to get to the web interface without editing the conf file for cups is:
    sudo cupsctl --remote-any

    ReplyDelete
    Replies
    1. Excellent! thanks for tip. I'll change the writeup immediately.

      Delete