lfs-uefi: fix efivar-37 FTBFS
[linux_from_scratch_hints.git] / pfs.txt
blob80f46f4526619f833fcbad145416cb4aef031b6f
1 AUTHOR:         Uli Fahrenberg <uli at math dot auc dot dk>\r
2 AUTHOR:         Original hint by Declan Moriarty <declan dot moriarty at ntlworld dot ie>\r
3 \r
4 DATE:           2003-09-30\r
5 \r
6 LICENSE:        GNU Free Documentation License Version 1.2\r
7 \r
8 SYNOPSIS:       Printing From Scratch\r
9 \r
11 DESCRIPTION:\r
12 Do-it-yourself guide for setting up your computer for printing. Also useful\r
13 for troubleshooting. We start with kernel configuration, and at the end you\r
14 will (hopefully) get your printer to print a ps file.\r
17 PREREQUISITES:\r
18 ghostscript (AFPL, GNU, ESP, whatever; see BLFS book for details)\r
20 Optional: a2ps and psutils (again: See BLFS book for how to install these)\r
23 HINT:\r
24 Setting up a Linux box for printing can be very easy (with a bit of luck). If\r
25 you your setup is simple: One computer and one printer which you want to\r
26 communicate, and that's about it, this hint is for you. If you want to share\r
27 your printer between several computers or anything fancy like this, I cannot\r
28 help you.\r
31 Step 1:\r
33 Check that you have printer support in your kernel, either compiled-in or as a\r
34 module. My config is as follows; you might not need the last two PARPORT_*\r
35 options enabled:\r
37         CONFIG_PARPORT=y\r
38         CONFIG_PARPORT_PC=y\r
39         CONFIG_PARPORT_PC_CML1=y\r
40         CONFIG_PARPORT_SERIAL=y\r
41         CONFIG_PRINTER=y\r
44 Step 2:\r
46 Check if your printer is working and connected:\r
48         echo -en "blah\f\r" > /dev/lp0\r
50 (substitute lp0 with the port your printer is connected to)\r
52 If your printer spits out a piece of paper with the word `blah' on it,\r
53 good. If it doesn't, worry.\r
55 If your printer is an Epson, the above command most probably will not work. In\r
56 this case, the following info contributed by Jeroen Coumans might help:\r
58         Epson printers don't work without first being given a special\r
59         character. The gimp-print util escputil is commonly used for that\r
60         (it's probably possible to do this without first installing\r
61         gimp-print, but I don't know how). This is the command which works for\r
62         me (Stylus C80):\r
64                 escputil -r /dev/usb/lp0 -i\r
66 You might want to install gimp-print anyway (I won't tell you how, though (but\r
67 it appears to be a piece of cake)), as Epson printers are poorly supported by\r
68 Ghostscript. Otherwise, to build just escputil,\r
70         ./configure && make -C lib && make -C src/escputil\r
72 worked for me.\r
75 Step 3:\r
77 Install your favourite version of Ghostscript.\r
80 Step 4:\r
82 Type gs -h at a prompt and select your printer from the pageful of drivers\r
83 that it gives up. If your driver is not shown, go back to step 3 and install\r
84 another version of Ghostscript. AFPL and ESP Ghostscript differ in what\r
85 printers are supported.\r
87 If you don't know what driver to select to get your printer working, go to\r
89         http://www.linuxprinting.org/\r
91 and search their database for your printer. You might be told that you need\r
92 some additional software; HPIJS, pnm2ppa, or others. If you do need some extra\r
93 software, you're on your own. Here we only deal with Ghostscript-supported\r
94 printers. (But read on, the hint might still be of use for you.)\r
97 Step 5:\r
99 Test your setup. Get yourself a ps file (pdf will do, too), and run\r
101         gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=<your-printer-driver> \\r
102         -sOutputFile=/tmp/testit <your-file>\r
104 You'll find some ps files in the Ghostscript examples directory; with me this\r
105 is /usr/share/ghostscript/8.00/examples/. This command should give you a\r
106 (probably rather large) binary file /tmp/testit; if you're lucky (I was),\r
107 running\r
109         file /tmp/testit\r
111 will identify it as printer data. It may also tell you that the paper size does\r
112 not fit what you have in your printer; if this is the case, adding\r
113 -sPAPERSIZE=<your-papersize> to the gs command above will help. The other\r
114 options above mean:\r
116         -q      tells gs not to display anything & saves it looking for X.\r
117    -dBATCH      tells gs to quit after processing - always a good idea.\r
118  -dNOPAUSE      gs will not wait for a key-press after each page.\r
119    -dSAFER      stops gs from  deleting or zapping anything.\r
120  -sDEVICE=      your printer driver. Be exact and case sensitive. gs is\r
121                 stupid. Use the spelling on the info at 'gs -h'.\r
122 -sOutputFile=   write to this output file (congratulations for guessing!)\r
124 If everything looks OK, you can\r
126         cat /tmp/testit > /dev/lp0\r
128 (again, replace lp0 with the port your printer is connected to). This should\r
129 get <your-file> out to <your-printer>.\r
131 Both the commands above might give you some trouble with permissions if you do\r
132 them as an ordinary user. If the gs one does, execute\r
134         chmod 4777 /tmp \r
136 and kick yourself for running a machine unusable for ordinary users. If the\r
137 cat command bails out with some 'Cannot write to /dev/lp0' blah, you can\r
138 either decide that only root should be allowed to access your printer, or you\r
139 can be a little lax on some (minor) security issues and do a\r
141         chmod a+rw /dev/lp0\r
143 If you want to use the lpr script below for printing, you should do the\r
144 latter.\r
147 Step 6 (optional):\r
149 If you got here, you have your printer working. You can leave it at this; what\r
150 you did in step 5 was printing after all. If you want to be slightly more\r
151 fancy, the script below will provide you with an lpr command, to be used\r
152 either by calling\r
154         lpr <some-file>\r
156 or by having lpr as (the last) part of a pipe. This should let you use most of\r
157 your favorite application's `Print' buttons/commands directly.\r
159 Another advantage of the script below is that it does not make use of\r
160 temporary files, thus avoiding a) cluttering /tmp with all kinda crap, and b)\r
161 some security hazards. On the other hand, if you want ordinary users to print,\r
162 you have to give them access to /dev/lp0 (or whatever port your printer is\r
163 connected to), see above.\r
165 Here we have the script; as you can see, there's some adjusting to do for\r
166 you. I have yet to encounter applications that won't print with this script;\r
167 if you do, please notify me.\r
169 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
170 cat > /usr/bin/lpr << "EOF"\r
171 #!/bin/bash\r
173 ####################  Adjust to your needs/desires.\r
174 DEVICE=ljet4\r
175 LP=lp0\r
176 PAPER=a4\r
177 LOCKFILE=/tmp/.${LP}-lock\r
178 ####################  End Adjust\r
180 # Prints file to printer $DEVICE connected at /dev/$LP, \r
181 # using paper size $PAPER.\r
182 # Usage: lpr <ps or pdf file> ( or cat <ps or pdf file> | lpr )\r
184 # Uli Fahrenberg, early 2003. This file is in the public domain.\r
186 if [ -e $LOCKFILE ] ; then\r
187         echo "Error: printer is locked  ($LOCKFILE exists)"\r
188         exit 1\r
189 fi\r
191 FILE=$1\r
192 if ! [ X$FILE = X ] ; then ### We have a filename as an argument.\r
193         if ! [ -r $FILE ] ; then\r
194                 echo "Error: Cannot read file $FILE"\r
195                 exit 1\r
196         fi\r
198         FTYPE=$(file -bL $FILE | awk '{print $1}')\r
199         if ! [ $FTYPE = 'PDF' ] && ! [ $FTYPE = 'PostScript' ] ; then\r
200                 echo "Error: $FILE is not a PS or PDF file."\r
201                 exit 1\r
202         fi\r
204         ### Comment this out if you want lpr to be quiet:\r
205         echo -n "Printing $FILE... "\r
207         (touch $LOCKFILE ; \\r
208         trap 'rm -f $LOCKFILE' EXIT ; \\r
209         gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=$DEVICE \\r
210             -sPAPERSIZE=$PAPER -sOutputFile=- $FILE \\r
211         > /dev/$LP ) &\r
213         ### Without the sleep, some apps delete $FILE\r
214         ###    faster than gs can read it:\r
215         sleep 1\r
216         ### Comment this out if you want lpr to be quiet:\r
217         echo "Done."\r
219 else ### We have no filename argument, so we try stdin\r
220         DATA="$(</dev/stdin)"\r
221         (touch $LOCKFILE ; \\r
222         trap 'rm -f $LOCKFILE' EXIT ; \\r
223         echo "$DATA" \\r
224         | gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=$DEVICE \\r
225             -sPAPERSIZE=$PAPER -sOutputFile=- - \\r
226         > /dev/$LP ) &\r
227 fi\r
228 EOF\r
229 chmod 755 /usr/bin/lpr\r
230 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
233 Step 7 (even more optional):\r
235 So now you can print postscript and pdf files on your printer. If you want to\r
236 print other kinds of files (plain text files, say, e.g. LFS hints...), you\r
237 might find the a2ps (AnyToPS) package handy. Also, for manipulating postscript\r
238 files, the psutils package is a good thing to have installed. Both packages\r
239 are covered in the BLFS book.\r
242 ACKNOWLEDGEMENTS:\r
243 This hint is a reworked edition of the Printing Minority Report, a printing\r
244 hint originally written by Declan Moriarty. He was doing all the ground work\r
245 of sections 1 throuch 5; I was reading and using his hint and cooking up the\r
246 lpr script, and the next thing I knew was that Declan handed over the hint to\r
247 me.\r
249 Bill Maltby and Jeroen Coumans were also contributing some tidbits.\r
251 CHANGELOG:\r
252 [2003-05-24]\r
253 * Adopted hint from Declan.\r
254 [2003-06-29]\r
255 * Submitted pfs.txt version 1.\r
256 [2003-07-01]\r
257 * Inserted `sleep 1' into lpr script, to make gv happy.\r
258 [2003-09-30]\r
259 * Converted to new fancy format.\r