summaryrefslogtreecommitdiffstats
path: root/perl-install/Xconfig/main.pm
blob: b3d291c07a2cfde5e29dc2ee593733a20d1b1ae2 (plain)
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
package Xconfig::main; # $Id$

use diagnostics;
use strict;

use Xconfig::monitor;
use Xconfig::card;
use Xconfig::resolution_and_depth;
use Xconfig::various;
use Xconfig::screen;
use Xconfig::test;
use common;
use any;


sub configure_monitor {
    my ($in, $raw_X) = @_;

    Xconfig::monitor::configure($in, $raw_X) or return;
    $raw_X->write;
    'config_changed';
}

sub configure_resolution {
    my ($in, $raw_X) = @_;

    my $card = Xconfig::card::from_raw_X($raw_X);
    my $monitor = Xconfig::monitor::from_raw_X($raw_X);
    Xconfig::resolution_and_depth::configure($in, $raw_X, $card, $monitor) or return;
    $raw_X->write;
    'config_changed';
}


sub configure_everything_auto_install {
    my ($raw_X, $do_pkgs, $old_X, $options) = @_;
    my $X = {};
    $X->{monitor} = Xconfig::monitor::configure_auto_install($raw_X, $old_X) or return;
    $options->{VideoRam_probed} = $X->{monitor}{VideoRam_probed};
    $X->{card} = Xconfig::card::configure_auto_install($raw_X, $do_pkgs, $old_X, $options) or return;
    Xconfig::screen::configure($raw_X, $X->{card}) or return;
    $X->{resolution} = Xconfig::resolution_and_depth::configure_auto_install($raw_X, $X->{card}, $X->{monitor}, $old_X);

    &write($raw_X, $X);

    Xconfig::various::runlevel(exists $old_X->{xdm} && !$old_X->{xdm} ? 3 : 5);
}

sub configure_everything {
    my ($in, $raw_X, $do_pkgs, $auto, $options) = @_;
    my $X = {};
    my $ok = 1;
    $ok &&= $X->{monitor} = Xconfig::monitor::configure($in, $raw_X, $auto);
    $options->{VideoRam_probed} = $X->{monitor}{VideoRam_probed};
    $ok &&= $X->{card} = Xconfig::card::configure($in, $raw_X, $do_pkgs, $auto, $options);
    $ok &&= Xconfig::screen::configure($raw_X, $X->{card});
    $ok &&= $X->{resolution} = Xconfig::resolution_and_depth::configure($in, $raw_X, $X->{card}, $X->{monitor});
    $ok &&= Xconfig::test::test($in, $raw_X, $X->{card}, $auto, 'skip_badcard');

    if (!$ok) {
	($ok) = configure_chooser_raw($in, $raw_X, $do_pkgs, $options, $X, 1);
    }
    $X->{various} ||= Xconfig::various::various($in, $X->{card}, $options, $auto);

    $ok = may_write($in, $raw_X, $X, $ok);
    
    $ok && 'config_changed';
}

sub configure_chooser_raw {
    my ($in, $raw_X, $do_pkgs, $options, $X, $modified) = @_;

    my %texts;

    my $update_texts = sub {
	$texts{card} = $X->{card} && $X->{card}{BoardName} || N("Custom");
	$texts{monitor} = $X->{monitor} && $X->{monitor}{ModelName} || N("Custom");
	$texts{resolution} = Xconfig::resolution_and_depth::to_string($X->{resolution});

	$texts{$_} =~ s/(.{20}).*/$1.../ foreach keys %texts; #- ensure not too long
    };
    $update_texts->();

    my $may_set = sub {
	my ($field, $val) = @_;
	if ($val) {
	    $X->{$field} = $val;
	    $X->{"modified_$field"} = 1;
	    $modified = 1;
	    $update_texts->();

	    if (member($field, 'card', 'monitor')) {
		Xconfig::screen::configure($raw_X, $X->{card});
		$raw_X->set_resolution($X->{resolution}) if $X->{resolution};
	    }
	}
    };

    my $ok;
    $in->ask_from_({ ok => '' }, 
		   [
		    { label => N("Graphic Card"), val => \$texts{card}, icon => "eth_card_mini", clicked => sub { 
			  $may_set->('card', Xconfig::card::configure($in, $raw_X, $do_pkgs, 0, $options));
		      } },
		    { label => N("Monitor"), val => \$texts{monitor}, icon => "ic82-systemeplus-40", clicked => sub { 
			  $may_set->('monitor', Xconfig::monitor::configure($in, $raw_X));
		      } },
		    { label => N("Resolution"), val => \$texts{resolution}, icon => "X", disabled => sub { !$X->{card} || !$X->{monitor} },
		      clicked => sub {
			  $may_set->('resolution', Xconfig::resolution_and_depth::configure($in, $raw_X, $X->{card}, $X->{monitor}));
		      } },
		        if_(Xconfig::card::check_bad_card($X->{card}) || $::isStandalone,
		     { val => N("Test"), icon => "warning", disabled => sub { !$X->{card} || !$X->{monitor} },
		       clicked => sub { 
			  $ok = Xconfig::test::test($in, $raw_X, $X->{card}, 'auto', 0);
		      } },
			),
		    { val => N("Options"), icon => "ic82-tape-40", clicked => sub {
			  Xconfig::various::various($in, $X->{card}, $options);
			  $X->{various} = 'done';
		      } },
		    { val => $::isInstall ? N("Ok") : N("Quit"), icon => "exit", clicked_may_quit => sub { 1 } },
		   ]);
    $ok, $modified;
}

sub configure_chooser {
    my ($in, $raw_X, $do_pkgs, $options) = @_;

    my $X = {
	card => scalar eval { Xconfig::card::from_raw_X($raw_X) },
	monitor => $raw_X->get_monitors && Xconfig::monitor::from_raw_X($raw_X),
	resolution => scalar eval { $raw_X->get_resolution },
    };
    my ($ok, $modified) = configure_chooser_raw($in, $raw_X, $do_pkgs, $options, $X);

    $modified and may_write($in, $raw_X, $X, $ok) or return;

    'config_changed';
}

sub may_write {
    my ($in, $raw_X, $X, $ok) = @_;

    $ok ||= $in->ask_yesorno('', N("Keep the changes?
The current configuration is:

%s", Xconfig::various::info($raw_X, $X->{card})), 1);

    &write($raw_X, $X) if $ok;
    $ok;
}

sub write {
    my ($raw_X, $X) = @_;
    export_to_install_X($X);
    $raw_X->write;
    Xconfig::various::check_XF86Config_symlink();
    symlinkf "../..$X->{card}{prog}", "$::prefix/etc/X11/X" if $X->{card}{server} !~ /Xpmac/;
}


sub export_to_install_X {
    my ($X) = @_;

    $::isInstall or return;

    $::o->{X}{resolution_wanted} = $X->{resolution}{X};
    $::o->{X}{default_depth} = $X->{resolution}{Depth};
    $::o->{X}{bios_vga_mode} = $X->{resolution}{bios};
    $::o->{X}{monitor} = $X->{monitor} if $X->{monitor}{manually_chosen} && $X->{monitor}{vendor} ne "Plug'n Play";
    $::o->{X}{card} = $X->{monitor} if $X->{card}{manually_chosen};
    $::o->{X}{Xinerama} = 1 if $X->{card}{Xinerama};
}


#- most usefull XFree86-4.0.1 server options. Default values is the first ones.
our @options_serverflags = (
			'DontZap'                 => [ "Off", "On" ],
			'DontZoom'                => [ "Off", "On" ],
			'DisableVidModeExtension' => [ "Off", "On" ],
			'AllowNonLocalXvidtune'   => [ "Off", "On" ],
			'DisableModInDev'         => [ "Off", "On" ],
			'AllowNonLocalModInDev'   => [ "Off", "On" ],
			'AllowMouseOpenFail'      => [ "False", "True" ],
			'VTSysReq'                => [ "Off", "On" ],
			'BlankTime'               => [ "10", "5", "3", "15", "30" ],
			'StandByTime'             => [ "20", "10", "6", "30", "60" ],
			'SuspendTime'             => [ "30", "15", "9", "45", "90" ],
			'OffTime'                 => [ "40", "20", "12", "60", "120" ],
			'Pixmap'                  => [ "32", "24" ],
			'PC98'                    => [ "auto-detected", "False", "True" ],
			'NoPM'                    => [ "False", "True" ],
);

1;
f we are in an DrakX config my $prefix = ""; #-location of the printer database in an installed system my $PRINTER_DB_FILE = "/usr/lib/rhs/rhs-printfilters/printerdb"; my $PRINTER_FILTER_DIR = "/usr/lib/rhs/rhs-printfilters"; #-##################################################################################### =head2 Exported constant =cut #-##################################################################################### %printer_type = ( __("Local printer") => "LOCAL", __("Remote lpd") => "REMOTE", __("SMB/Windows 95/98/NT") => "SMB", __("NetWare") => "NCP", ); %printer_type_inv = reverse %printer_type; $printer_type_default = "Local printer"; %fields = ( STANDARD => [qw(QUEUE SPOOLDIR IF)], SPEC => [qw(DBENTRY RESOLUTION PAPERSIZE BITSPERPIXEL CRLF)], LOCAL => [qw(DEVICE)], REMOTE => [qw(REMOTEHOST REMOTEQUEUE)], SMB => [qw(SMBHOST SMBHOSTIP SMBSHARE SMBUSER SMBPASSWD SMBWORKGROUP AF)], NCP => [qw(NCPHOST NCPQUEUE NCPUSER NCPPASSWD)], ); @papersize_type = qw(letter legal ledger a3 a4); $spooldir = "/var/spool/lpd"; #-##################################################################################### =head2 Functions =cut #-##################################################################################### sub set_prefix($) { $prefix = $_[0]; } sub default_queue($) { (split '\|', $_[0])[0] } sub copy_printer_params($$) { my ($from, $to) = @_; map { $to->{$_} = $from->{$_} } grep { $_ ne 'configured' } keys %$from; #- avoid cycles. } sub getinfo($) { my ($prefix) = @_; my $printer = {}; set_prefix($prefix); read_configured_queue($printer); add2hash($printer, { want => 0, complete => 0, str_type => $printer::printer_type_default, QUEUE => "lp", SPOOLDIR => "/var/spool/lpd/lp", DBENTRY => "PostScript", PAPERSIZE => "", ASCII_TO_PS => undef, CRLF => undef, NUP => 1, RTLFTMAR => 18, TOPBOTMAR => 18, AUTOSENDEOF => 1, DEVICE => "/dev/lp0", REMOTEHOST => "", REMOTEQUEUE => "", NCPHOST => "", #-"printerservername", NCPQUEUE => "", #-"queuename", NCPUSER => "", #-"user", NCPPASSWD => "", #-"pass", SMBHOST => "", #-"hostname", SMBHOSTIP => "", #-"1.2.3.4", SMBSHARE => "", #-"printername", SMBUSER => "", #-"user", SMBPASSWD => "", #-"passowrd", SMBWORKGROUP => "", #-"AS3", }); $printer; } #-***************************************************************************** #- read function #-***************************************************************************** #------------------------------------------------------------------------------ #- Read the printer database from dbpath into memory #------------------------------------------------------------------------------ sub read_printer_db(;$) { my $dbpath = $prefix . ($_[0] || $PRINTER_DB_FILE); scalar(keys %thedb) > 4 and return; #- try reparse if using only ppa, POSTSCRIPT, TEXT. my %available_devices; #- keep only available devices in our database. local *AVAIL; open AVAIL, ($::testing ? "$prefix" : "chroot $prefix/ ") . "/usr/bin/gs --help |"; foreach (<AVAIL>) { if (/^Available devices:/ ... /^\S/) { @available_devices{split /\s+/, $_} = () if /^\s+/; } } close AVAIL; $available_devices{ppa} = undef; #- if -x "$prefix/usr/bin/pbm2ppa" && -x "$prefix/usr/bin/pnm2ppa"; delete $available_devices{''}; @available_devices{qw/POSTSCRIPT TEXT/} = (); #- these are always available. local $_; #- use of while (<... local *DBPATH; #- don't have to do close ... and don't modify globals at least open DBPATH, $dbpath or die "An error has occurred on $dbpath : $!"; while (<DBPATH>) { if (/^StartEntry:\s(\w*)/) { my $entry = { ENTRY => $1 }; WHILE : while (<DBPATH>) { SWITCH: { /GSDriver:\s*(\w*)/ and do { $entry->{GSDRIVER} = $1; last SWITCH }; /Description:\s*{(.*)}/ and do { $entry->{DESCR} = $1; last SWITCH }; /About:\s*{\s*(.*?)\s*}/ and do { $entry->{ABOUT} = $1; last SWITCH }; /About:\s*{\s*(.*?)\s*\\\s*$/ and do { my $string = $1; while (<DBPATH>) { $string =~ /\S$/ and $string .= ' '; /^\s*(.*?)\s*\\\s*$/ and $string .= $1; /^\s*(.*?)\s*}\s*$/ and do { $entry->{ABOUT} = $string . $1; last SWITCH }; } }; /Resolution:\s*{(.*)}\s*{(.*)}\s*{(.*)}/ and do { push @{$entry->{RESOLUTION} ||= []}, { XDPI => $1, YDPI => $2, DESCR => $3 }; last SWITCH }; /BitsPerPixel:\s*{(.*)}\s*{(.*)}/ and do { push @{$entry->{BITSPERPIXEL} ||= []}, {DEPTH => $1, DESCR => $2}; last SWITCH }; /EndEntry/ and last WHILE; } } if (exists $available_devices{$entry->{GSDRIVER}}) { $thedb{$entry->{ENTRY}} = $entry; $thedb_gsdriver{$entry->{GSDRIVER}} = $entry; } } } @entries_db_short = sort keys %printer::thedb; %descr_to_db = map { $printer::thedb{$_}{DESCR}, $_ } @entries_db_short; %descr_to_help = map { $printer::thedb{$_}{DESCR}, $printer::thedb{$_}{ABOUT} } @entries_db_short; @entry_db_description = keys %descr_to_db; %db_to_descr = reverse %descr_to_db; } #-****************************************************************************** #- write functions #-****************************************************************************** #------------------------------------------------------------------------------ #- given the path queue_path, we create all the required spool directory #------------------------------------------------------------------------------ sub create_spool_dir($) { my ($queue_path) = @_; my $complete_path = "$prefix/$queue_path"; commands::mkdir_("-p", $complete_path); unless ($::testing) { #-redhat want that "drwxr-xr-x root lp" my $gid_lp = (getpwnam("lp"))[3]; chown 0, $gid_lp, $complete_path or die "An error has occurred - can't chgrp $complete_path to lp $!"; } } #------------------------------------------------------------------------------ #-given the input spec file 'input', and the target output file 'output' #-we set the fields specified by fieldname to the values in fieldval #-nval is the number of fields to set #-Doesnt currently catch error exec'ing sed yet #------------------------------------------------------------------------------ sub create_config_file($$%) { my ($inputfile, $outputfile, %toreplace) = @_; template2file("$prefix/$inputfile", "$prefix/$outputfile", %toreplace); eval { commands::chown_("root.lp", "$prefix/$outputfile") }; } #------------------------------------------------------------------------------ #-copy master filter to the spool dir #------------------------------------------------------------------------------ sub copy_master_filter($) { my ($queue_path) = @_; my $complete_path = "$prefix/$queue_path/filter"; my $master_filter = "$prefix/$PRINTER_FILTER_DIR/master-filter"; eval { commands::cp('-f', $master_filter, $complete_path) }; $@ and die "Can't copy $master_filter to $complete_path $!"; eval { commands::chown_("root.lp", $complete_path); }; } #------------------------------------------------------------------------------ #- given a PrintCap Entry, create the spool dir and special #- rhs-printfilters related config files which are required #------------------------------------------------------------------------------ my $intro_printcap_test = " # # Please don't edit this file directly unless you know what you are doing! # Look at the printcap(5) man page for more info. # Be warned that the control-panel printtool requires a very strict format! # # This file can be edited with printerdrake or printtool. # "; sub read_configured_queue($) { my ($printer) = @_; my $current = undef; my $flush_current = sub { if ($current) { add2hash($printer->{configured}{$current->{QUEUE}} ||= {}, $current); $current = undef; } }; #- read /etc/printcap file. local *PRINTCAP; open PRINTCAP, "$prefix/etc/printcap" or die "Can't open $prefix/etc/printcap file: $!"; foreach (<PRINTCAP>) { chomp; my $p = '(?:\{(.*?)\}|(\S+))'; if (/^##PRINTTOOL3##\s+$p\s+$p\s+$p\s+$p\s+$p\s+$p\s+$p(?:\s+$p)?/) { &$flush_current; $current = { TYPE => $1 || $2, GSDRIVER => $3 || $4, RESOLUTION => $5 || $6, PAPERSIZE => $7 || $8, #- ignored $9 || $10, DBENTRY => $11 || $12, BITSPERPIXEL => $13 || $14, CRLF => $15 || $16, }; } elsif (/^\s*$/) { &$flush_current } elsif (/^([^:]*):\\/) { $current->{QUEUE} = $1 } if (/^\s+:(?:[^:]*:)*sd=([^:]*):/) { $current->{SPOOLDIR} = $1 } if (/^\s+:(?:[^:]*:)*lp=([^:]*):\\/) { $current->{DEVICE} = $1 } if (/^\s+:(?:[^:]*:)*rm=([^:]*):\\/) { $current->{REMOTEHOST} = $1 } if (/^\s+:(?:[^:]*:)*rp=([^:]*):\\/) { $current->{REMOTEQUEUE} = $1 } if (/^\s+:(?:[^:]*:)*af=([^:]*):\\/) { $current->{AF} = $1 } if (/^\s+:(?:[^:]*:)*if=([^:]*):\\/) { $current->{IF} = $1 } } close PRINTCAP; &$flush_current; #- parse general.cfg for any configured queue. foreach (values %{$printer->{configured}}) { my $entry = $_; local *F; open F, "$prefix$entry->{SPOOLDIR}/general.cfg" or next; foreach (<F>) { chomp; if (/^\s*(?:export\s+)?PRINTER_TYPE=(.*?)\s*$/) { $entry->{TYPE} = $1 unless defined $entry->{TYPE} } elsif (/^\s*(?:export\s+)?ASCII_TO_PS=(.*?)\s*$/) { $entry->{ASCII_TO_PS} = $1 eq 'YES' unless defined $entry->{ASCII_TO_PS} } elsif (/^\s*(?:export\s+)?PAPER_SIZE=(.*?)\s*$/) { $entry->{PAPERSIZE} = $1 unless defined $entry->{PAPERSIZE} } } close F; } #- parse postscript.cfg for any configured queue. foreach (values %{$printer->{configured}}) { my $entry = $_; local *F; open F, "$prefix$entry->{SPOOLDIR}/postscript.cfg" or next; foreach (<F>) { chomp; if (/^\s*(?:export\s+)?GSDEVICE=(.*?)\s*$/) { $entry->{GSDRIVER} = $1 unless defined $entry->{GSDRIVER} } elsif (/^\s*(?:export\s+)?RESOLUTION=(.*?)\s*$/) { $entry->{RESOLUTION} = $1 unless defined $entry->{RESOLUTION} } elsif (/^\s*(?:export\s+)?COLOR=-dBitsPerPixel=(.*?)\s*$/) { $entry->{COLOR} = $1 unless defined $entry->{COLOR} } elsif (/^\s*(?:export\s+)?COLOR=(.*?)\s*$/) { $entry->{COLOR} = $1 ? $1 : 'Default' unless defined $entry->{COLOR} } elsif (/^\s*(?:export\s+)?PAPERSIZE=(.*?)\s*$/) { $entry->{PAPERSIZE} = $1 unless defined $entry->{PAPERSIZE} } elsif (/^\s*(?:export\s+)?EXTRA_GS_OPTIONS=(.*?)\s*$/) { $entry->{EXTRA_GS_OPTIONS} = $1 unless defined $entry->{EXTRA_GS_OPTIONS}; $entry->{EXTRA_GS_OPTIONS} =~ s/^\"(.*)\"/$1/ } elsif (/^\s*(?:export\s+)?REVERSE_ORDER=(.*?)\s*$/) { $entry->{REVERSE_ORDER} = $1 unless defined $entry->{REVERSE_ORDER} } elsif (/^\s*(?:export\s+)?PS_SEND_EOF=(.*?)\s*$/) { $entry->{AUTOSENDEOF} = $1 eq 'YES' && $entry->{DBENTRY} eq 'PostScript' unless defined $entry->{AUTOSENDEOF} } elsif (/^\s*(?:export\s+)?NUP=(.*?)\s*$/) { $entry->{NUP} = $1 unless defined $entry->{NUP} } elsif (/^\s*(?:export\s+)?RTLFTMAR=(.*?)\s*$/) { $entry->{RTLFTMAR} = $1 unless defined $entry->{RTLFTMAR} } elsif (/^\s*(?:export\s+)?TOPBOTMAR=(.*?)\s*$/) { $entry->{TOPBOTMAR} = $1 unless defined $entry->{TOPBOTMAR} } } close F; } #- parse textonly.cfg for any configured queue. foreach (values %{$printer->{configured}}) { my $entry = $_; local *F; open F, "$prefix$entry->{SPOOLDIR}/textonly.cfg" or next; foreach (<F>) { chomp; if (/^\s*(?:export\s+)?TEXTONLYOPTIONS=(.*?)\s*$/) { $entry->{TEXTONLYOPTIONS} = $1 unless defined $entry->{TEXTONLYOPTIONS}; $entry->{TEXTONLYOPTIONS} =~ s/^\"(.*)\"/$1/ } elsif (/^\s*(?:export\s+)?CRLFTRANS=(.*?)\s*$/) { $entry->{CRLF} = $1 eq 'YES' unless defined $entry->{CRLF} } elsif (/^\s*(?:export\s+)?TEXT_SEND_EOF=(.*?)\s*$/) { $entry->{AUTOSENDEOF} = $1 eq 'YES' && $entry->{DBENTRY} ne 'PostScript' unless defined $entry->{AUTOSENDEOF} } } close F; } #- get extra parameters for SMB or NCP type queue. foreach (values %{$printer->{configured}}) { my $entry = $_; if ($entry->{TYPE} eq 'SMB') { my $config_file = "$prefix$entry->{SPOOLDIR}/.config"; local *F; open F, "$config_file" or next; #die "Can't open $config_file $!"; foreach (<F>) { chomp; if (/^\s*share='\\\\(.*?)\\(.*?)'/) { $entry->{SMBHOST} = $1; $entry->{SMBSHARE} = $2; } elsif (/^\s*hostip=(.*)/) { $entry->{SMBHOSTIP} = $1; } elsif (/^\s*user='(.*)'/) { $entry->{SMBUSER} = $1; } elsif (/^\s*password='(.*)'/) { $entry->{SMBPASSWD} = $1; } elsif (/^\s*workgroup='(.*)'/) { $entry->{SMBWORKGROUP} = $1; } } close F; } elsif ($entry->{TYPE} eq 'NCP') { my $config_file = "$prefix$entry->{SPOOLDIR}/.config"; local *F; open F, "$config_file" or next; #die "Can't open $config_file $!"; foreach (<F>) { chomp; if (/^\s*server=(.*)/) { $entry->{NCPHOST} = $1; } elsif (/^\s*user='(.*)'/) { $entry->{NCPUSER} = $1; } elsif (/^\s*password='(.*)'/) { $entry->{NCPPASSWD} = $1; } elsif (/^\s*queue='(.*)'/) { $entry->{NCPQUEUE} = $1; } } close F; } } } sub configure_queue($) { my ($entry) = @_; my $queue_path = "$entry->{SPOOLDIR}"; create_spool_dir($queue_path); my $get_name_file = sub { my ($name) = @_; ("$PRINTER_FILTER_DIR/$name.in", "$entry->{SPOOLDIR}/$name") }; my ($filein, $file); my %fieldname = (); my $dbentry = $thedb{($entry->{DBENTRY})} or die "no dbentry"; #- make general.cfg ($filein, $file) = &$get_name_file("general.cfg"); $fieldname{ascps_trans} = $entry->{ASCII_TO_PS} || $dbentry->{GSDRIVER} eq 'ppa' ? "YES" : "NO"; $fieldname{desiredto} = $dbentry->{GSDRIVER} ne "TEXT" ? "ps" : "asc"; $fieldname{papersize} = $entry->{PAPERSIZE} ? $entry->{PAPERSIZE} : "letter"; $fieldname{printertype} = $entry->{TYPE}; create_config_file($filein, $file, %fieldname); #- now do postscript.cfg ($filein, $file) = &$get_name_file("postscript.cfg"); %fieldname = (); $fieldname{gsdevice} = $dbentry->{GSDRIVER}; $fieldname{papersize} = $entry->{PAPERSIZE} ? $entry->{PAPERSIZE} : "letter"; $fieldname{resolution} = $entry->{RESOLUTION}; $fieldname{color} = $entry->{BITSPERPIXEL} ne "Default" && (($dbentry->{GSDRIVER} ne "uniprint" && "-dBitsPerPixel=") . $entry->{BITSPERPIXEL}); $fieldname{reversepages} = $entry->{REVERSE_ORDER} ? "YES" : ""; $fieldname{extragsoptions} = "\"$entry->{EXTRA_GS_OPTIONS}\""; $fieldname{pssendeof} = $entry->{AUTOSENDEOF} ? ($dbentry->{GSDRIVER} eq "POSTSCRIPT" ? "YES" : "NO") : "NO"; $fieldname{nup} = $entry->{NUP}; $fieldname{rtlftmar} = $entry->{RTLFTMAR}; $fieldname{topbotmar} = $entry->{TOPBOTMAR}; create_config_file($filein, $file, %fieldname); #- finally, make textonly.cfg ($filein, $file) = &$get_name_file("textonly.cfg"); %fieldname = (); $fieldname{textonlyoptions} = "\"$entry->{TEXTONLYOPTIONS}\""; $fieldname{crlftrans} = $entry->{CRLF} ? "YES" : ""; $fieldname{textsendeof} = $entry->{AUTOSENDEOF} ? ($dbentry->{GSDRIVER} eq "POSTSCRIPT" ? "NO" : "YES") : "NO"; create_config_file($filein, $file, %fieldname); if ($entry->{TYPE} eq "SMB") { #- simple config file required if SMB printer my $config_file = "$prefix$queue_path/.config"; local *F; open F, ">$config_file" or die "Can't create $config_file $!"; print F "share='\\\\$entry->{SMBHOST}\\$entry->{SMBSHARE}'\n"; print F "hostip=$entry->{SMBHOSTIP}\n"; print F "user='$entry->{SMBUSER}'\n"; print F "password='$entry->{SMBPASSWD}'\n"; print F "workgroup='$entry->{SMBWORKGROUP}'\n"; close F; eval { chmod 0640, $config_file; commands::chown_("root.lp", $config_file) }; } elsif ($entry->{TYPE} eq "NCP") { #- same for NCP printer my $config_file = "$prefix$queue_path/.config"; local *F; open F, ">$config_file" or die "Can't create $config_file $!"; print F "server=$entry->{NCPHOST}\n"; print F "queue=$entry->{NCPQUEUE}\n"; print F "user=$entry->{NCPUSER}\n"; print F "password=$entry->{NCPPASSWD}\n"; close F; eval { chmod 0640, $config_file; commands::chown_("root.lp", $config_file) }; } copy_master_filter($queue_path); #-now the printcap file, note this one contains all the printer (use configured for that). local *PRINTCAP; open PRINTCAP, ">$prefix/etc/printcap" or die "Can't open printcap file $!"; print PRINTCAP $intro_printcap_test; foreach (values %{$entry->{configured}}) { $_->{DBENTRY} = $thedb_gsdriver{$_->{GSDRIVER}}{ENTRY} unless defined $_->{DBENTRY}; my $db_ = $thedb{$_->{DBENTRY}} or next; #die "no dbentry"; $_->{SPOOLDIR} ||= "$spooldir/" . default_queue($_->{QUEUE}); $_->{IF} ||= "$_->{SPOOLDIR}/filter"; $_->{AF} ||= "$_->{SPOOLDIR}/acct"; printf PRINTCAP "##PRINTTOOL3## %s %s %s %s %s %s %s%s\n", $_->{TYPE} || '{}', $db_->{GSDRIVER} || '{}', $_->{RESOLUTION} || '{}', $_->{PAPERSIZE} || '{}', '{}', $db_->{ENTRY} || '{}', $_->{BITSPERPIXEL} || '{}', $_->{CRLF} ? " 1" : ""; print PRINTCAP "$_->{QUEUE}:\\\n"; print PRINTCAP "\t:sd=$_->{SPOOLDIR}:\\\n"; print PRINTCAP "\t:mx#0:\\\n\t:sh:\\\n"; if ($_->{TYPE} eq "LOCAL") { print PRINTCAP "\t:lp=$_->{DEVICE}:\\\n"; } elsif ($_->{TYPE} eq "REMOTE") { print PRINTCAP "\t:rm=$_->{REMOTEHOST}:\\\n"; print PRINTCAP "\t:rp=$_->{REMOTEQUEUE}:\\\n"; } else { #- (pcentry->Type == (PRINTER_SMB | PRINTER_NCP)) print PRINTCAP "\t:lp=/dev/null:\\\n"; print PRINTCAP "\t:af=$_->{AF}\\\n"; } #- cheating to get the input filter! print PRINTCAP "\t:if=$_->{IF}:\n"; print PRINTCAP "\n"; } eval { commands::chown_("root.lp", "$prefix/etc/printcap") }; my $useUSB = 0; foreach (values %{$entry->{configured}}) { $useUSB ||= $_->{DEVICE} =~ /usb/; } if ($useUSB) { my $f = "$prefix/etc/sysconfig/usb"; my %usb = getVarsFromSh($f); $usb{PRINTER} = "yes"; setVarsInSh($f, \%usb); } } sub restart_queue($) { my ($queue) = @_; #- restart lpd after cleaning the queue. foreach (("/var/spool/lpd/$queue/lock", "/var/spool/lpd/lpd.lock")) { my $pidlpd = (cat_("$prefix$_"))[0]; kill 'TERM', $pidlpd if $pidlpd; unlink "$prefix$_"; } require run_program; run_program::rooted($prefix, "lprm", "-P$queue", "-"); sleep 1; run_program::rooted($prefix, "lpd"); sleep 1; } sub print_pages($@) { my ($queue, @pages) = @_; require run_program; foreach (@pages) { run_program::rooted($prefix, "lpr", "-P$queue", $_); } sleep 5; #- allow lpr to send pages. local *F; open F, "chroot $prefix/ /usr/bin/lpq -P$queue |"; my @lpq_output = grep { !/^no entries/ && !(/^Rank\s+Owner/ .. /^\s*$/) } <F>; close F; @lpq_output; } #------------------------------------------------------------------------------ #- interface function