Topic: CUPS Howto

Preamble

This HOWTO will show you how to complete a basic install of CUPS, the Common UNIX Printing System, a local printer and network printing - the server will be running FreeBSD.

First - choose the right printer; visit www.linuxprinting.org

Believe it or not, your choice of printer will determine whether or not you can use it on UNIX with CUPS. Certain printer manufacturers have been very supportive of the open source community, others have not. A website has been created that lists all printers which function with CUPS and also to what extent, it's www.linuxprinting.org. Speak with your money!

Visit the site and choose a printer (if you haven't already bought one) that is classed as working "perfectly". I bought an Epson Stylus CX5200 based upon this website - here's what the database says about the Epson CX5200 : http://www.linuxprinting.org/show_print … lus_CX5200

So you've got the printer - let's get it to work.

Install CUPS - and supporting applications

I'm a great fan of the ports collection on FreeBSD - and why ignore the fact that someone else has made the effort to make sure you can install the software you want/need? Change into the "cups" directory of ports, change to "root" and install the application:

cd /usr/ports/print/cups 
su 
Password: ******** 
make install clean

In my experience of CUPS, there are a number of useful drivers/applications which are often required to get certain printers working. So, we'll install them too. Again, the ports system is our friend, so run the command "make install clean" in the following directories too:

/usr/ports/print/gimp-print 
/usr/ports/print/hpijs 
/usr/ports/print/ghostscript-gnu 
/usr/ports/lang/perl5 
/usr/ports/print/pnm2ppa

A quick visit back to linuxprinting.org

Linuxprinting.org has another feature that makes it extra special - it has a database of the "PPD"s that CUPS uses as printer configuration files. So - next you need to go back to the website, select your printer from the database and choose the option to "download PPD".

In the case of my CX5200, the PPD is called 'Epson-Stylus_CX5200-gimp-print-ijs.ppd'. This file needs to be placed in the CUPS "model" directory. This directory stores all PPD files. In FreeBSD this directory is /usr/local/share/cups/model:

chown root:wheel Epson-Stylus_CX5200-gimp-print-ijs.ppd 
chmod 644 Epson-Stylus_CX5200-gimp-print-ijs.ppd 
mv Epson-Stylus_CX5200-gimp-print-ijs.ppd /usr/local/share/cups/model

Getting "foomatic"

The Foomatic filter script is called by CUPS with various inputs; inputs include both the PPD filename and the various options selected by the user. foomatic-rip opens the PPD, extracts all options and their possible settings and also the command line to execute Ghostscript with the appropriate driver. It parses the PostScript print file for option settings. It also massages the standard CUPS option types into the more generic printer/driver-specific format used by the database. Therefore, we need to install it. You need to obtain these two files:

http://www.linuxprinting.org/foomatic-rip
http://www.linuxprinting.org/foomatic-gswrapper


These files need to be moved to the right location with the right modes applied:

mv foomatic-rip /usr/local/bin 
mv foomatic-gswrapper /usr/local/bin 
cd /usr/local/bin 
chmod 755 foomatic-rip foomatic-gswrapper

Next, you need to ensure that both file's first line points correctly to Perl. This can be done with the command "whereis perl". In my case, Perl is found in /usr/bin/perl, so the first line should look like:

#!/usr/bin/perl

Finally, foomatic must be reachable by CUPS, this is achieved by placing a softlink in CUPS's "filter" directory. On my FreeBSD machine, this is found as /usr/local/libexec/cups/filter:

ln -s /usr/local/bin/foomatic-rip /usr/local/libexec/cups/filter/foomatic-rip

Hide the BSD lp commands

CUPS will have installed its own versions of the commands "LP" "lpr" "lpq" "lprm". These will cause a BIG conflict with the BSD installed versions of these commands. Therefore, we must remove/hide the BSD commands so that only the CUPS commands are used.

On my FreeBSD box, the BSD commands are in "/usr/bin" whereas the CUPS commands are in "/usr/local/bin", this means we can simply backup the BSD ones as follows:

mv /usr/bin/lp /usr/bin/lp.bak 
mv /usr/bin/lpr /usr/bin/lpr.bak 
mv /usr/bin/lprm /usr/bin/lprm.bak 
mv /usr/bin/lpq /usr/bin/lpq.bak

NB: You will have to redo this step EVERY time you rebuild world in FreeBSD.

Configuring the printer

I've only found one reservation with CUPS - USB printers must be plugged in and switched on BEFORE CUPS is started, otherwise it cannot be configured. Once configured it doesn't matter though. So, if your printer is a USB printer, you MUST plug it in and turn it on before proceeding.

The startup script needs to be renamed in FreeBSD so that CUPS will start at (nonexistent) reboots:

mv /usr/local/etc/rc.d/cups.sh.sample /usr/local/etc/rc.d/cups.sh

The server can now be started with the following command:

/usr/local/etc/rc.d/cups.sh start

The server can be configured with the aid of a web browser - simply point it at: http://localhost:631/admin

This brings up the main CUPS admin interface.

Select "Add Printer" - and when asked to log in, use your system "root" username and password.

You will be asked for three pieces of information - "Name" "Location" and "Description". The "Name" is what will be used to uniquely identify the printer on the system. The "Location" and "Description" are for your convenience. Here's what I used:

Name: CX5200
Location: Local printer
Description: Epson Stylus CX5200

Next, you will be asked which "Device" - this will usually be either "/dev/lpt0" or "/dev/upt0" which are either the LPT port or USB port. Simply select whichever applies.

If you cannot see the USB port, stop CUPS, restart CUPS and restart the configuration process, ensuring the printer is turned on.

The next window will be fairly self explanatory - you will need to select the "Make" of printer you have. This is "EPSON" in my case.

Again, the next window will be self explanatory - you now need to select the "Model" of printer. This should be fairly obvious and in my case it was "Epson Stylus CX5200 Foomatic/gimp-print-ijs (recommended)"

Your printer is now configured!!! You may wish to "Configure" the printer to change default printing options or paper size, etc.

Configuring network printing - server side

Up until now, we have had no need to change the default CUPS config file "cupsd.conf". However, CUPS requires two features to be set to facilitate network printing

1) The "broadcast" option which broadcasts what printers are available to the network
2) The access privilege to the directories, that allows other boxes to use the local printer

First find "cupsd.conf" and open it for editing, on my FreeBSD it's in /usr/local/etc/cups/cupsd.conf.

1) To set the "broadcast" option, you need to edit the "BrowseAddress" option. You can set it to work based on IP address ranges, for example 10.0.0.* network ranges would be:

BrowseAddress 10.0.0.255

However, there is a special "Local" option for local network connections which I comfortably use, as follows:

BrowseAddress @LOCAL

2) To set the access privileges you must find the "<Location />" section and add the IP addresses / range that you wish to allow to print. For a 10.0.0.* Network this would be:

<Location /> 
Order Deny,Allow 
Deny From All 
Allow From 127.0.0.1 
Allow From 10.0.0.* 
</Location>

However, if you only wanted to allow PCs with IP addresses 10.0.0.2 and 10.0.0.3, it would be:

<Location /> 
Order Deny,Allow 
Deny From All 
Allow From 127.0.0.1 
Allow From 10.0.0.2 
Allow From 10.0.0.3 
</Location>

Configuring network printing - client side

Believe it or not, the client need only have CUPS installed. As long as its IP address (or range) is in the server's "<Location />" list, and the server is "broadcasting" to the correct IP range then the client can use that printer. This means different OS's (especially UNIX variants) can print to printers on different systems via CUPS.

Servers printing on client local printers

You may have a workstation system with a local printer attached and configured with CUPS, and a production server that you would like to print to the workstation printer. This follows the above example in the same way, however, the workstation is then classed as the "server side" and the production server as the "client side".

"UBER" means I don't drink the coffee... I chew the beans instead
             -- Copyright BSDnexus

Re: CUPS Howto

Instead of manually downloading and installing the foomatic-rip stuff, you can just install the print/foomatic-filters port.  That includes foomatic-rip, foomatic-gswrapper, and more.  This will also setup all the symlinks and everything for you.

And for a large collection of printer drivers, you can install the print/foomatic-db port.

Also, if you don't want to remove/rename the base lp* stuff, just change your path to put /usr/local/* ahead of /usr/*.

Last edited by phoenix (2005-03-30 00:05:13)

Re: CUPS Howto

Thanx for the update phoenix smile

"UBER" means I don't drink the coffee... I chew the beans instead
             -- Copyright BSDnexus

Re: CUPS Howto

Your link to the how to doesn't resolve so not sure what method you are using to install, is it portinstall/portmaster, make install or pkg_add?

"An educator never says what he himself thinks, but only that which he thinks it is good for those whom he is educating to hear."
-Nietzsche