summaryrefslogtreecommitdiffstats
path: root/perl-install/devices.pm
Commit message (Expand)AuthorAgeFilesLines
* create udev nodes configuration file in /etc/udev/devices.d/ instead of conf....Olivier Blin2007-04-301-3/+2
* do not try to configure dvd devices during install since /dev is wiped out at...Olivier Blin2007-04-301-1/+1
* re-sync after the big svn lossPascal Rigaux2007-04-251-32/+18
* add some useful devices for live systems buildOlivier Blin2005-11-221-0/+6
* enable creation of /dev/dm-x devices (not used at the moment)Pascal Rigaux2005-06-201-16/+22
* - move functions using /proc/partitions out of fsedit to fs::proc_partitionsPascal Rigaux2005-06-101-12/+0
* drop old unused codePascal Rigaux2005-06-031-44/+0
* MERGE: don't be so i586 centricGwenolé Beauchesne2005-03-171-1/+1
* move mdkinst.clp on hard drive ASAPPascal Rigaux2005-01-031-0/+11
* move device mapper initialisation out of lvm.pm into devices.pm (since it wil...Pascal Rigaux2004-12-291-0/+12
* better english (writing style rather than spoken one)Thierry Vignaud2004-12-131-2/+2
* we don't use /tmp for devices anymorePascal Rigaux2004-11-251-2/+1
* remove some unneeded ";", add some for normalization (as told by perl_checker)Pascal Rigaux2004-11-181-2/+2
* module aes is now named aes-i586 (bugzilla #11588)Pascal Rigaux2004-09-221-1/+1
* - add field {part_number} for partitionsPascal Rigaux2004-09-201-0/+13
* increase the number of loopbacks (needed for mandrakemove where the default (...Pascal Rigaux2004-06-151-1/+1
* - new getSCSI_26() not using /proc/scsi/scsiPascal Rigaux2004-04-301-1/+1
* get rid of the chloop code (not used anymore)Pascal Rigaux2004-04-081-6/+2
* nicer debug error messagePascal Rigaux2004-03-081-4/+3
* one now need cryptoloop and aes when using encryption (kernel 2.6)Pascal Rigaux2004-03-031-0/+2
* add input/micePascal Rigaux2004-02-121-0/+2
* lvm2 uses urandomPascal Rigaux2004-01-131-0/+1
* *** empty log message ***Guillaume Cottenceau2003-12-011-1/+0
* chloop supportGuillaume Cottenceau2003-12-011-2/+7
* (from_devfs)Thierry Vignaud2003-06-241-1/+3
* - move read_proc_partitions_raw() from fsedit.pm to devices.pmThierry Vignaud2003-06-241-2/+18
* perl_checker adaptations + fixesPascal Rigaux2003-04-241-1/+1
* new perl_checker compliancePascal Rigaux2003-04-171-4/+4
* add "vcsa" (for brltty)Pascal Rigaux2003-02-041-0/+1
* remove unused variables or rename them with an underscore (eg: $o becomes $_o)Pascal Rigaux2002-12-041-2/+2
* do not use "local my $F, ...", use "local(my $F, ...) insteadPascal Rigaux2002-12-031-1/+1
* do not use "local *F"Pascal Rigaux2002-12-031-15/+12
* perl_checker adaptationsPascal Rigaux2002-11-271-29/+29
* - add/remove spaces to make perl_checker happyPascal Rigaux2002-11-141-1/+1
* add/remove spaces to make perl_checker happyPascal Rigaux2002-11-131-1/+1
* add or remove spaces where need to please perl_checkerPascal Rigaux2002-11-111-22/+22
* add /dev/ubd/0, /dev/ubd/1... support (thanks to Brian Murrell)Pascal Rigaux2002-11-051-0/+1
* allow creation of "/dev/null" devicePascal Rigaux2002-08-291-0/+1
* use mkdir_p instead of mkdirPascal Rigaux2002-08-281-1/+1
* new devfsd use input/mice rather than input/mouse0 since severalThierry Vignaud2002-08-211-1/+1
* make new perl_checker happy (and that's not easy!)Pascal Rigaux2002-07-311-1/+1
* add functions to_devfs and from_devfs. These only work for devices entriesPascal Rigaux2002-07-191-0/+35
* use c::total_sectors() instead of BLKGETSIZEPascal Rigaux2002-07-071-2/+3
* (find_free_loop): fixPascal Rigaux2002-03-061-6/+4
* (devices::make): following a good advice from Andrej Borsenkow, return thePascal Rigaux2002-02-231-1/+3
* devices::make doesn't mknod with devfsPascal Rigaux2002-02-231-0/+5
* add atibm (thanks to Robin Pollard)Pascal Rigaux2002-02-221-0/+1
* i prefer /(.*?)(\d+)$/ to /(.*\D)(\d+)$/Pascal Rigaux2002-02-121-1/+1
* Fixes on device auto-detection:Till Kamppeter2002-02-121-1/+1
* encrypted filesystem handling:Pascal Rigaux2002-01-151-7/+28
ead1 DESCRIPTION Use the source. =cut #-##################################################################################### use diagnostics; use strict; #-##################################################################################### =head2 Exported variable =cut #-##################################################################################### use vars qw(%thedb %printer_type %printer_type_inv @papersize_type %fields $spooldir @entries_db_short @entry_db_description %descr_to_db %db_to_descr); #-##################################################################################### =head2 Imports =cut #-##################################################################################### use Data::Dumper; #-##################################################################################### =head2 pixel imports =cut use commands; #-##################################################################################### #-##################################################################################### =head2 Examples and types =over 4 =item * an entry in the 'printerdb' file, which describes each type of supported printer: StartEntry: DeskJet550 GSDriver: cdj550 Description: {HP DeskJet 550C/560C/6xxC series} About: { \ This driver supports the HP inkjet printers which have \ color capability using both black and color cartridges \ simultaneously. Known to work with the 682C and the 694C. \ Other 600 and 800 series printers may work \ if they have this feature. \ If your printer seems to be saturating the paper with ink, \ try added an extra GS option of '-dDepletion=2'. \ Ghostscript supports several optional parameters for \ this driver: see the document 'devices.doc' \ in the ghostscript directory under /usr/doc. \ } Resolution: {300} {300} {} BitsPerPixel: {3} {Normal color printing with color cartridge} BitsPerPixel: {8} {Floyd-Steinberg B & W printing for better greys} BitsPerPixel: {24} {Floyd-Steinberg Color printing (best, but slow)} BitsPerPixel: {32} {Sometimes provides better output than 24} EndEntry Example of data-struct: my %ex_printerdb_entry = ( ENTRY => "DeskJet550", #-Human-readable name of the entry GSDRIVER => "cdj550", #-gs driver used by this printer DESCR => "HP DeskJet 550C/560C/6xxC series", #-Single line description of printer ABOUT => " This driver supports the HP inkjet printers which have color capability using both black and color cartridges ...", #-Lengthy description of printer RESOLUTION => [ #-List of resolutions supported { XDPI => 300, YDPI => 300, DESCR => "commentaire", }, ], BITSPERPIXEL => [ #-List of color depths supported { DEPTH => 3, DESCR => "Normal color printing with color cartridge", }, ], ) ; =item * A printcap entry only represents a subset of possible options available Sufficient for the simple configuration we are interested in there is also some text in the template (.in) file in the spooldir # /etc/printcap # # Please don't edit this file directly unless you know what you are doing # Be warned that the control-panel printtool requires a very strict forma # Look at the printcap(5) man page for more info. # # This file can be edited with the printtool in the control-panel. ##PRINTTOOL3## LOCAL uniprint NAxNA letter {} U_NECPrinwriter2X necp2x6 1 lpname:\ :sd=/var/spool/lpd/lpnamespool:\ :mx#45:\ :sh:\ :lp=/dev/device:\ :if=/var/spool/lpd/lpnamespool/filter: ##PRINTTOOL3## REMOTE st800 360x180 a4 {} EpsonStylus800 Default 1 remote:\ :sd=/var/spool/lpd/remotespool:\ :mx#47:\ :sh:\ :rm=remotehost:\ :rp=remotequeue:\ :if=/var/spool/lpd/remotespool/filter: ##PRINTTOOL3## SMB la75plus 180x180 letter {} DECLA75P Default {} smb:\ :sd=/var/spool/lpd/smbspool:\ :mx#46:\ :sh:\ :if=/var/spool/lpd/smbspool/filter:\ :af=/var/spool/lpd/smbspool/acct:\ :lp=/dev/null: ##PRINTTOOL3## NCP ap3250 180x180 letter {} EpsonAP3250 Default {} ncp:\ :sd=/var/spool/lpd/ncpspool:\ :mx#46:\ :sh:\ :if=/var/spool/lpd/ncpspool/filter:\ :af=/var/spool/lpd/ncpspool/acct:\ :lp=/dev/null: Example of data-struct: my %ex_printcap_entry = ( QUEUE => "lpname", #-Queue name, can have multi separated by '|' #-if you want something different from the default SPOOLDIR => "/var/spool/lpd/lpnamespool/", #-Spool directory IF => "/var/spool/lpd/lpnamespool/filter", #-input filter #- commentaire inserer dans le printcap pour que printtool retrouve ses petits DBENTRY => "DeskJet670", #-entry in printer database for this printer RESOLUTION => "NAxNA", #-ghostscript resolution to use PAPERSIZE => "letter", #-Papersize BITSPERPIXEL => "necp2x6", #-ghostscript color option CRLF => 1 , #-Whether or not to do CR/LF xlation TYPE => "LOCAL", #- LOCAL DEVICE => "/dev/device", #-Print device #- REMOTE (lpd) printers only REMOTEHOST => "remotehost", #-Remote host (not used for all entries) REMOTEQUEUE => "remotequeue", #-Queue on the remote machine #-SMB (LAN Manager) only #- in spooldir/.config #-share='\\hostname\printername' #-hostip=1.2.3.4 #-user='user' #-password='passowrd' #-workgroup='AS3' SMBHOST => "hostname", #-Server name (NMB name, can have spaces) SMBHOSTIP => "1.2.3.4", #-Can optional specify and IP address for host SMBSHARE => "printername", #-Name of share on the SMB server SMBUSER => "user", #-User to log in as on SMB server SMBPASSWD => "passowrd", #-Corresponding password SMBWORKGROUP => "AS3", #-SMB workgroup name AF => "/var/spool/lpd/smbspool/acct", #-accounting filter (needed for smbprint) #- NCP (NetWare) only #- in spooldir/.config #-server=printerservername #-queue=queuename #-user=user #-password=pass NCPHOST => "printerservername", #-Server name (NCP name) NCPQUEUE => "queuename", #-Queue on server NCPUSER => "user", #-User to log in as on NCP server NCPPASSWD => "pass", #-Corresponding password ) ; =cut #-##################################################################################### =head2 Intern constant =cut #-##################################################################################### #-if we are in an panoramix 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" => "LOCAL", "Remote lpd" => "REMOTE", "SMB/Windows 95/NT" => "SMB", "NetWare" => "NCP", ); %printer_type_inv = reverse %printer_type; %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]; } #-***************************************************************************** #- read function #-***************************************************************************** #------------------------------------------------------------------------------ #- Read the printer database from dbpath into memory #------------------------------------------------------------------------------ sub read_printer_db(;$) { my $dbpath = $prefix . ($_[0] || $PRINTER_DB_FILE); %thedb and return; local *DBPATH; #-don't have to do close open DBPATH, $dbpath or die "An error has occurred on $dbpath : $!"; while (<DBPATH>) { if (/^StartEntry:\s(\w*)/) { my $entryname = $1; my $entry; $entry->{ENTRY} = $entryname; 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*{(.*)}/ and do { $entry->{ABOUT} = $1; last SWITCH }; /About:\s*{(.*)/ and do { my $string = "$1\n"; while (<DBPATH>) { /(.*)}/ and do { $entry->{ABOUT} = $string; last SWITCH }; $string .= $_; } }; /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; } } $thedb{$entryname} = $entry; } } @entries_db_short = sort keys %printer::thedb; @entry_db_description = map { $printer::thedb{$_}{DESCR} } @entries_db_short; %descr_to_db = map { $printer::thedb{$_}{DESCR}, $_ } @entries_db_short; %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"; unless (-d $complete_path) { mkdir "$complete_path", 0755 or die "An error has occurred - can't create $complete_path : $!"; } #-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, $outpufile, %toreplace) = @_; my ($in, $out) = ("$prefix/$inputfile", "$prefix/$outpufile"); local *OUT; local *IN; #-TODO my $oldmask = umask 0755; open IN , $in or die "Can't open $in $!"; if ($::testing) { *OUT = *STDOUT } else { open OUT, ">$out" or die "Can't open $out $!"; } while (<IN>) { if (/@@@(.*)@@@/) { my $r = $toreplace{$1}; s/@@@(.*)@@@/$r/g; } print OUT; } } #------------------------------------------------------------------------------ #-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($master_filter, $complete_path) }; $@ and die "Can't copy $master_filter to $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! # Look at the printcap(5) man page for more info. # # This file can be edited with the printtool in the control-panel. # "; sub configure_queue($) { my ($entry) = @_; $entry->{SPOOLDIR} ||= "$spooldir"; $entry->{IF} ||= "$spooldir/$entry->{QUEUE}/filter"; $entry->{AF} ||= "$spooldir/$entry->{QUEUE}/acct"; 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"; ($filein, $file) = &$get_name_file("general.cfg"); $fieldname{ascps_trans} = ($dbentry->{GSDRIVER} eq "POSTSCRIPT") ? "NO" : "YES"; $fieldname{desiredto} = ($entry->{GSDRIVER} eq "TEXT") ? "ps" : "asc"; $fieldname{papersize} = $entry->{PAPERSIZES} ? $entry->{PAPERSIZES} : "letter"; $fieldname{printertype} = $entry->{TYPE}; create_config_file($filein, $file, %fieldname); #- successfully created general.cfg, now do postscript.cfg ($filein, $file) = &$get_name_file("postscript.cfg"); %fieldname = (); $fieldname{gsdevice} = $dbentry->{GSDRIVER}; $fieldname{papersize} = $entry->{PAPERSIZES} ? $entry->{PAPERSIZES} : "letter"; $fieldname{resolution} = ($entry->{RESOLUTION} eq "Default") ? "Default" : ""; $fieldname{color} = do { if ($dbentry->{GSDRIVER} eq "uniprint") { ($entry->{BITSPERPIXEL} eq "Default") ? "-dBitsPerPixel=Default" : ""; } else { $entry->{BITSPERPIXEL}; } }; $fieldname{reversepages} = "NO"; $fieldname{extragsoptions} = ""; $fieldname{pssendeof} = ($dbentry->{GSDRIVER} eq "POSTSCRIPT") ? "NO" : "YES"; $fieldname{nup} = "1"; $fieldname{rtlftmar} = "18"; $fieldname{topbotmar} = "18"; create_config_file($filein, $file, %fieldname); #- finally, make textonly.cfg ($filein, $file) = &$get_name_file("textonly.cfg"); %fieldname = (); $fieldname{textonlyoptions} = ""; $fieldname{crlftrans} = $entry->{CRLF} ? "YES" : ""; $fieldname{textsendeof} = "1"; 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"; } 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"; } copy_master_filter($queue_path); #-now the printcap file local *PRINTCAP; if ($::testing) { *PRINTCAP = *STDOUT; } else { open PRINTCAP, ">$prefix/etc/printcap" or die "Can't open printcap file $!"; } print PRINTCAP $intro_printcap_test; printf PRINTCAP "##PRINTTOOL3## %s %s %s %s %s %s %s \n", $entry->{TYPE}, $dbentry->{GSDRIVER}, $entry->{RESOLUTION}, $entry->{PAPERSIZE}, "{}", $dbentry->{ENTRY}, $entry->{BITSPERPIXEL}, $entry->{CRLF} ? "1" : ""; print PRINTCAP "$entry->{QUEUE}:\\\n"; print PRINTCAP "\t:sd=$entry->{SPOOLDIR}:\\\n"; print PRINTCAP "\t:mx#0:\\\n\t:sh:\\\n"; if ($entry->{TYPE} eq "LOCAL") { print PRINTCAP "\t:lp=$entry->{DEVICE}:\\\n"; } elsif ($entry->{TYPE} eq "REMOTE") { print PRINTCAP "\t:rm=$entry->{REMOTEHOST}:\\\n"; print PRINTCAP "\t:rp=$entry->{REMOTEQUEUE}:\\\n"; } else { #- (pcentry->Type == (PRINTER_SMB | PRINTER_NCP)) print PRINTCAP "\t:lp=/dev/null:\\\n"; print PRINTCAP "\t:af=$entry->{SPOOLDIR}/acct\\\n"; } #- cheating to get the input filter! print PRINTCAP "\t:if=$entry->{SPOOLDIR}/filter:\n"; } #------------------------------------------------------------------------------ #- interface function #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ #- fonction de test #------------------------------------------------------------------------------ sub test { $::testing = 1; $printer::prefix=""; read_printer_db(); print "the dump\n"; print Dumper(%thedb); # #eval { printer::create_spool_dir("/tmp/titi/", ".") }; #print $@; #eval { printer::copy_master_filter("/tmp/titi/", ".") }; #print $@; # # #eval { printer::create_config_file("files/postscript.cfg.in", "files/postscript.cfg","./", # ( # gsdevice => "titi", # resolution => "tata", # )); # }; #print $@; # # # #printer::configure_queue(\%printer::ex_printcap_entry, "/"); } #-###################################################################################### #- Wonderful perl :( #-###################################################################################### 1; # =head1 AUTHOR pad. =cut