/usr/sbin/foomatic-printermap-to-gutenprint-xml is in foomatic-db-engine 4.0.11-0ubuntu1.
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 | #!/usr/bin/perl
# This script updates the printer list of the driver XML file of
# Gutenprint (db/source/driver/gutenprint.xml in foomatic-db package)
# according to the file src/foomatic/foomatic-printermap of the source
# tarball of Gutenprint 5.0.x or later.
#
# Remarks:
#
# - Manually added printer entries will not be removed. They drop out
# to the beginning of the printer list during the update. The same
# happens to printers which are removed from the new foomatic-printermap
#
# - All printers of foomatic-printermap are put to the end of the list,
# the order of foomatic-printermap is preserved.
#
# - The user will be informed by screen messages if the new
# foomatic-printermap contains new printers which were neither in the
# previous foomatic-printermap nor under the manually added printers.
#
# - A printer which was added manually before and is in foomatic-printermap
# now will be removed from the list of manually added printers and added
# to the list of printers from foomatic-printermap.
#use strict;
# Read out the program name with which we were called, but discard the path
$0 =~ m!/([^/]+)\s*$!;
my $progname = $1;
my $debug = 0;
my ($opt_f, $opt_g, $opt_h);
use Getopt::Std;
getopts("f:g:h") or $opt_h = 1;
if ($opt_h) {
print "
foomatic-printermap-to-gutenprint-xml [ -f <foomatic-printermap> ] \
[ -g <gutenprint.xml> ]
-f <foomatic-printermap>: File src/foomatic/foomatic-printermap of
Gutenprint source tarball (4.2.x or later). Default
is foomatic-printermap in the current directory
-g <gutenprint.xml>: File gutenprint.xml whose printer list should be
updated. Default is the gutenprint.xml of the
Foomatic database currently in use.
This program updates the printer list of the driver XML file of
Gutenprint (db/source/driver/gutenprint.xml in foomatic-db package)
according to the file src/foomatic/foomatic-printermap of the source
tarball of Gutenprint 5.0.x or later.
";
exit 0;
}
# Determine gutenprint.xml file
my $gutenprintxmlfile = $opt_g;
if (!$gutenprintxmlfile) {
use Foomatic::Defaults;
$gutenprintxmlfile = "$libdir/db/source/driver/gutenprint.xml";
}
# Determine foomatic-printermap file
my $foomaticprintermapfile = $opt_f;
if (!$foomaticprintermapfile) {
$foomaticprintermapfile = "./foomatic-printermap";
}
# Read list of printer IDs from Gutenprint's foomatic-printermap
open PM, "< $foomaticprintermapfile" or
die "Cannot read $foomaticprintermapfile!\n";
my @printermap = <PM>;
close PM;
(s/^\s*\S+\s+\S+\s+(\S+)\s*$/$1/) foreach @printermap;
#print $#printermap;
# Read gutenprint.xml
open GPX, "< $gutenprintxmlfile" or
die "Cannot read $gutenprintxmlfile!\n";
my $gutenprintxml = join("", <GPX>);
close GPX;
# Remove printer list
#$gutenprintxml =~ s!(<\s*printers\s*>).*(\n\s*<\s*/\s*printers\s*>)!$1$2!s;
# Mark beginning of printer list from foomatic-printermap before deleting
# these printer entries
$gutenprintxml =~ s:\n <!-- The following printers are listed in the current foomatic-printermap -->:XXXXXXXXXX:s;
# Remove only those printers which are in foomatic-printermap. We
# re-add them in the next step, this way we have all printers of
# foomatic-printermap together and in the order of
# foomatic-printermap, and we have all manually added printers in the
# beginning of the list, before the printers of foomatic-printermap
# are listed.
print STDERR "Removing old printer entries ";
foreach my $printer (@printermap) {
print STDERR ".";
$gutenprintxml =~ s:\s*<\!\-\-[^<>]*?\-\->\s*<printer>\s*<id>\s*$printer\s*</id>.*?</printer>::s or
$gutenprintxml =~ s:\s*<printer>\s*<id>\s*$printer\s*</id>.*?</printer>::s or
print STDERR "\n\nNew printer: $printer\n\n";
}
print STDERR "\n\n";
# Insert comment to mark the part of the list set up manually
$gutenprintxml =~ s:(\n\s*<\s*printers\s*>)\n\s*<!--\s*Manually inserted printer entries\s*-->:$1:s;
$gutenprintxml =~ s:(\n\s*<\s*printers\s*>):$1\n <!-- Manually inserted printer entries -->:s;
# Insert comment to mark the part of the list generated from
# foomatic-printermap
$gutenprintxml =~ s:\n <!-- The following printers were deleted in the current foomatic-printermap -->::s;
$gutenprintxml =~ s:\n <!-- The following printers are listed in the current foomatic-printermap -->::s;
$gutenprintxml =~ s:XXXXXXXXXX:\n <!-- The following printers were deleted in the current foomatic-printermap -->:s;
$gutenprintxml =~ s:(\n\s*<\s*/\s*printers\s*>):\n <!-- The following printers are listed in the current foomatic-printermap -->$1:s;
# Insert printers of foomatic-printermap to the end of the list
print STDERR "Inserting printer entries of foomatic-printermap ";
foreach my $printer (@printermap) {
print STDERR ".";
$gutenprintxml =~ s:(\n\s*<\s*/\s*printers\s*>):\n <printer>\n <id>$printer</id>\n </printer>$1:s;
}
print STDERR "\n\n";
open GPX, "> $gutenprintxmlfile" or
die "Cannot write $gutenprintxmlfile!\n";
print GPX $gutenprintxml;
close GPX;
exit 0;
|