mkogg.py: Fix 'self.get_mp4_metadata(self, source)'
[blog.git] / posts / Adding_a_network_printer_with_lpadmin.mdwn
1 Configuring [CUPS][] printers can be a bit of a pain, due to
2 differences in URIs and drivers depending on the printers make and
3 model.  Many distributions have administrative GUIs that make printer
4 management easier, and you can usually interact with CUPS through your
5 browser at `http://localhost:631/admin`, but I prefer using the
6 command line to get a better feel for the underlying system.
7
8 CUPS has excellent [documentation][].  I found the sections on
9 [command line and printing options][options] and [configuring network
10 printers][network] particularly informative.  Combined with some
11 additional browsing and trial and error, here is the procedure to add
12 a new default network printer, in this case an HP LaserJet 4240 at
13 123.45.67.89 with [lpadmin][].
14
15 The basic template for adding and enabling a new printer is
16
17     lpadmin -p printer-name -v device-uri -m model -L location -E
18
19 For `printer-name` and `location`, just pick something that makes
20 sense to you.  `device-uri` will include some extra fluff around your
21 printer's IP address.  Consult the [table][] in the CUPS docs for
22 ideas or search the net for ideas.  For my LaserJet, the URI is
23 `socket://123.45.67.89`.  You can list all device types that CUPS
24 knows about with [lpinfo][]:
25
26     $ lpinfo -v
27     …
28     network socket
29     …
30
31 Finally, you'll need to figure out which `model` (driver) to use.
32 `lpinfo` leys you search through available drivers by make and model:
33
34     $ lpinfo --make-and-model 'LaserJet 4240' -m
35     gutenprint.5.2://hp-lj_4240/expert HP LaserJet 4240 - CUPS+Gutenprint v5.2.5
36     gutenprint.5.2://hp-lj_4240/simple HP LaserJet 4240 - CUPS+Gutenprint v5.2.5 Simplified
37     foomatic:HP-LaserJet_4240-Postscript.ppd HP LaserJet 4240 Foomatic/Postscript
38     drv:///hpijs.drv/hp-laserjet_4240-hpijs-pcl3.ppd HP LaserJet 4240 hpijs pcl3, 3.10.2
39     lsb/usr/hplip/HP/hp-laserjet_4240-ps.ppd HP LaserJet 4240 Postscript (recommended)
40
41 Choices, choices… I've heard good things about [Gutenprint][], so
42 we'll use that.  Not that I ask a lot of a print driver, so perhaps it
43 would be better to use the recommended ppd file.  Just pick something.
44 If it doesn't work, you can reconfigure with a better driver later.
45
46 On my [[Gentoo]] system, the `lpinfo` call failed with
47
48     lpinfo: client-error-not-found
49
50 To fix this, I had to emerge `net-print/gutenprint`.
51
52 Putting it all together, add and enable the new printer:
53
54     # lpadmin -E -p afmlab -v socket://123.45.67.89 -m gutenprint.5.2://hp-lj_4240/expert -L "LaserJet 4240, Disque 927" -E
55
56 Note the two `-E` options.  The first one (before `-p`) forces
57 encryption when connecting to the server.  The last one enables the
58 destination and starts accepting jobs.
59
60 You'll probably also want to make the new printer the default:
61
62     # lpadmin -d afmlab
63
64 The CUPS daemon will eventually (i.e. after a few seconds) flush these
65 configuration changes into `/etc/cups/printers.conf` if you prefer
66 editing text files to the command line or GUI tools ;).
67
68 If you want to add a printer to your local CUPS server that is already
69 configured from another CUPS server (e.g. printing from your laptop
70 (local CUPS) to a USB printer plugged into your desktop (another
71 CUPS)), you can just drop the model info:
72
73     # lpadmin -E -p afmlab -v http://my-desktop:631/printers/afmlab -L "LaserJet 4240, Disque 927" -E
74
75 where `my-desktop` should be the domain name or IP address of the
76 remote CUPS server.
77
78 [CUPS]: http://www.cups.org/
79 [documentation]: http://www.cups.org/documentation.php
80 [options]: http://www.cups.org/documentation.php/doc-1.4/options.html
81 [network]: http://www.cups.org/documentation.php/doc-1.4/network.html
82 [lpadmin]: http://www.cups.org/documentation.php/doc-1.4/man-lpadmin.html
83 [table]: http://www.cups.org/documentation.php/doc-1.4/network.html#TABLE1
84 [lpadmin]: http://www.cups.org/documentation.php/doc-1.4/man-lpadmin.html
85 [lpinfo]: http://www.cups.org/documentation.php/doc-1.4/man-lpinfo.html
86 [Gutenprint]: http://gimp-print.sourceforge.net/
87
88 [[!tag tags/linux]]