This file is indexed.

/usr/sbin/foomatic-preferred-driver is in foomatic-db-engine 4.0.8-2ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/usr/bin/perl

# This is foomatic-preferred driver, it reads the printer database
# overview and puts default driver entries (<driver>..</driver>) into
# every printer's XML database entry.

use Foomatic::Defaults;
use Foomatic::DB qw/get_overview/;
use Data::Dumper;
use strict;
# Needs "get_overview" to be added to the "@EXPORT_OK" list of DB.pm!

# Read out the program name with which we were called, but discard the path
$0 =~ m!/([^/]+)\s*$!;
my $progname = $1;
my $debug = 0;

my $db = new Foomatic::DB;

# Get the printer overview list as a Perl data structure
$db->get_overview();
print "DB " . Dumper($db ) if $debug;

my $printer;
for $printer (@{$db->{'overview'}}) {
    # Skip printers without XML file. Here we cannot set a recommended
    # driver
    next if $printer->{'noxmlentry'};
    print "$printer->{'make'} $printer->{'model'} ($printer->{'id'})";
    if ($printer->{'driver'}) { # We have already a default driver
	# Check whether this driver is one which supports the printer
	# If yes, this printer has a correct default driver so we do not
	# need to set a new default driver
	my $found = 0;
	for my $d (@{$printer->{'drivers'}}) {
	    if ($d eq $printer->{'driver'}) {
		$found = 1;
		last;
	    }
	}
	if ($found) {
	    print " (Keeping old default driver): $printer->{'driver'}\n";
	    next;
	} else {
	    print " (Default driver wrong)\n";
	}
    } else {
	print " (No default driver defined)\n";
    }
    if ($printer->{'functionality'} eq 'F') {
	# If the printer is a "Paperweight", do not correct the
	# default driver, remove the wrong setting and skip the 
	# printer
	$printer->{'driver'} = "";
	print ": --> Skipping \"Paperweight\"\n";
    } else {
	#Sort drivers appropriate to ranking list
	my @sorted = sort sortdrivers @{$printer->{'drivers'}};
	print ": @sorted --> $sorted[0]\n";
	$printer->{'driver'} = $sorted[0];
    }
    open PRINTERENTRY, "< $libdir/db/source/printer/$printer->{'id'}.xml" || die "   Database entry for the printer $printer->{'make'} $printer->{'model'} ($printer->{'id'}) cannot be read!\n";
    my  @printerentryfield = <PRINTERENTRY>;
    close PRINTERENTRY;
	
    my $printerentry = join ('', @printerentryfield);
    if ($printerentry =~ m!<driver>(.*)</driver>!s) {
	$printerentry =~ 
	  s!<driver>(.+)</driver>!<driver>$printer->{'driver'}</driver>!sg;
    } elsif ($printerentry =~ m=(<!\-\-unknown preferred "driver"\-\->)=s){
	$printerentry =~ 
	  s=(<!\-\-unknown preferred "driver"\-\->)=\n  <driver>$printer->{'driver'}</driver>=sg;
    } elsif ($printerentry =~ m!<unverified\s*/>!s) {
	$printerentry =~
	  s!<unverified\s*/>!<unverified />\n  <driver>$printer->{'driver'}</driver>!sg;
    } elsif ($printerentry =~ m!</functionality>!s) {
	$printerentry =~
	  s!</functionality>!</functionality>\n  <driver>$printer->{'driver'}</driver>!sg;
    } else {
	$printerentry =~
	  s!</model>!</model>\n  <driver>$printer->{'driver'}</driver>!sg;
    }
    open PRINTERENTRY, "> $libdir/db/source/printer/$printer->{'id'}.xml" || die "   Database entry for the printer $printer->{'make'} $printer->{'model'} ($printer->{'id'}) cannot be written!\n";
    print PRINTERENTRY $printerentry;
    close PRINTERENTRY;
}

exit 0;

sub sortdrivers ($$) {
 
    # All sorting done case-sensitive and characters which are not a letter
    # or number are taken out!!
 
    # List of driver names in a ranking which driver should be preferred
    # against other drivers.
    # The terms must fit to the beginning of the line, terms which must fit
    # exactly must have '\$' in the end.
    my @drivers =      (
			# Laser printers (except winprinters)
			"epl5800", # Additional functionality for Epson
			"epl2050", # Laser printers
			"epl2050p",
			"hl1250", # Special Brother drivers should be preferred
			"hl1240", # for Brother printers
                        "Postscript", # Tray selection, 1200+ dpi, color laser
			"alc2000", # Epson color lasers print in color 
			"alc8500", # with these drivers from Epson
			"cljet5\$", # color laser PCL
			"cljet5c",
			"pxlcolor", # 1200 dpi color laser PCL
			"pxlmono", # 1200 dpi, faster than "lj5gray"
			"epl5900", # This driver has a bug, "pxlmono" works
				   # correctly 
			"lj5gray", # 1200 dpi
			"lj5mono",
			"ljet4\$", # HP laser drivers, the newer, the better
			"ljet4d",
			"lj4dithp",
			"lj4dith\$",
			"hl7x0", # Brother driver, proprietary language,
				 # to prefer when there is also PCL
				 # emulation
			"ljet3d",
			"ljet3\$",
			"ljet2p",
			"ljetplus",
			"laserjet",
			# HP PPA inkjets, when a printer is supported by one
			# of these drivers, it is for sure not supported by
			# any other driver.
			"pnm2ppa", # color
			"pbm2ppa", # bw
			# Lexmark 3200, the Gutenprint support for this
			# printer is broken
			"lxm3200-tweaked",
			"lxm3200\$",
			"lxm3200c",
			"lxm3200m",
			"lxm3200p",
			# Canon BJC-8200, these UPPs are probably better
			# than Gutenprint
			"bj8pa06n.upp",
			"bj8oh06n.upp",
			"bj8ts06n.upp",
			"bj8gc12f.upp",
			"bj8hg12f.upp",
			"bj8pp12f.upp",
			# HP and compatible inkjets
			"hplip", # HP drivers, with Duplex and 1200 dpi
			"cdj970", # Duplex support
			"DJ", # HP drivers, but no duplex
			"chp2200", # HP driver
			"gutenprint-ijs", # IJS plug-in driver of Gutenprint
			"gutenprint", # Tray selection on laser, best 
				      # quality on inkjets (for HP HP's
				      # driver is better)
			"gimp-print-ijs", # Old Gimp-Print driver
			"gimp-print",
			"stp", # Predecessor of Gimp-Print/Gutenprint
			"cdj1600", # Relatively good drivers for HP inkjets
			"cdj890",  # not covered by Gutenprint or the HP
			"cdj880",  # drivers
			"cdj850",
			"cdj670",
			"pcl3", # When nothing else works ...
			"hpdj", # Predecessor of pcl3
			"sharp.upp", # Gets Sharp inkjets to work without
			             # a lot of hassle
			"cdj550\$",
			"cdj550.upp",
			"cdj500",
			"djet500", # Somewhat old-fashioned
			"deskjet",
			# Canon inkjets
			"s400a1.upp", # New printer, UPPs are probably 
			"s400b1.upp", # better than "bjc600"/"bjc800"
			"bjc800", # More flexible than the Uniprint drivers
			"bjc600",
			"bj200",
			"bj10e",
			"bjc6000a1.upp",
			"bjc6000b1.upp",
			"bjc610a0.upp",
			"bjc610a1.upp",
			"bjc610a2.upp",
			"bjc610a3.upp",
			"bjc610a4.upp",
			"bjc610a5.upp",
			"bjc610a6.upp",
			"bjc610a7.upp",
			"bjc610a8.upp",
			"bjc610b1.upp",
			"bjc610b2.upp",
			"bjc610b3.upp",
			"bjc610b4.upp",
			"bjc610b6.upp",
			"bjc610b7.upp",
			"bjc610b8.upp",
			# Epson inkjets
			"st640ih.upp",
			"st640ihg.upp",
			"st640p.upp",
			"st640pg.upp",
			"st640pl.upp",
			"st640plg.upp",
			"stc640p.upp",
			"Stp720p.upp",
			"Stp720pl.upp",
			"Stp870p.upp",
			"Stp870pl.upp",
			"stcolor",
			"st800",
			"PM760p.upp",
			"PM760pl.upp",
			"PM820p.upp",
			"PM820pl.upp",
			"Stc670p.upp",
			"Stc670pl.upp",
			"Stc680p.upp",
			"Stc680pl.upp",
			"Stc760p.upp",
			"Stc760pl.upp",
			"Stc777p.upp",
			"Stc777pl.upp",
			"stc1520h.upp",
			"stc800ih.upp",
			"stc800p.upp",
			"stc800pl.upp",
			"stc740ih.upp",
			"stc740p.upp",
			"stc740pl.upp",
			"stc600ih.upp",
			"stc600p.upp",
			"stc600pl.upp",
			"stc500p.upp",
			"stc500ph.upp",
			"stc300.upp",
			"stc300bm.upp",
			"stc300bl.upp",
			"stc2.upp",
			"stc2_h.upp",
			"stc2s_h.upp",
			"stc.upp",
			"stc_h.upp",
			"stc_l.upp",
			"stcany.upp",
			# Lexmark inkjets
			"lz11",
			"cZ11somsom",
			"cZ11",
			"lx5000",
			"lex7000",
			"lex5700",
			"lx5700m",
			"pbm2l7k",
			# Thermo sublimation printers
			"ppmtomd", # The successor of "ppmtocpva"
			"ppmtocpva",
			"md5k",
			"md2k",
			# Others
			"t4693d8",
			"t4693d4",
			"t4693d2",
			"necp2x.upp",
			"necp2x6.upp",
			"declj250", # More adjustable options
			"lj250",
			"pj", # More adjustable options
			"paintjet",
			"pjxl", # More adjustable options
			"pjetxl",
			"pjxl300",
			"iwhi",
			"iwlo",
			"necp6",  # in most cases the NEC PinWriter P6 (+)
			"epsonc", # is used without colour add-on.
			"epson",
			"eps9high",
			"eps9mid",
			"lq850",
			"cjet",
			"lbp8",
			"oki182",
			"ibmpro",
			"gdi",
			"pbmtozjs",
			# Japanese printer drivers
			"rpdl",
			"pr201",
			"pr150",
			"picty180",
			"npdl",
			"ml600",
			"mj8000c",
			"mj700v2c",
			"mj6000c",
			"mj500c",
			"md50Mono",
			"md50Eco",
			"md1xMono",
			"lp2000",
			"lj4dithp",
			"lips4v",
			"lips4",
			"lips2p",
			"lbp320",
			"lbp310",
			"jj100",
			"fmpr",
			"fmlbp",
			"filter800_3300",
			"filter800",
			"filter770",
			"filter760",
			"escpage",
			"dj505j",
			"bjc880j",
			"bjc800j",
			"bj10vh",
			"bj10v",
			"bj10",
			"sj48",
			# Omni is in experimental state, so other drivers
			# give probably better output
			"omni"
			);

    my $first = $_[0];
    my $second = $_[1];
    # The driver names to compare are absolutely equal ->
    #    Bug in database ==> ignore
    if ($first eq $second) {return 0};

    # Check whether they are in the @standardopts list
    my $i;
    for ($i = 0; $i <= $#drivers; $i++) {
        my $firstinlist = ($first =~ /^$drivers[$i]/);
        my $secondinlist = ($second =~ /^$drivers[$i]/);
        if (($firstinlist) && (!$secondinlist)) {return -1};
        if (($secondinlist) && (!$firstinlist)) {return 1};
    }

    # No preference found, stop here
    die "No preference found between $first and $second!\n";
}