#!/usr/pkg/bin/perl -w use strict; no strict "vars"; my $printcap="/etc/printcap"; my $filterdir="/usr/pkg/libexec/magicfilter/"; my $force=0; my $m=0; if ($#ARGV >= 0) { $force=($ARGV[0] eq "--force"); if ($force) { $m++; } } if ($m <= $#ARGV) { $printcap=$ARGV[$m]; } sub input { my($message)=$_[0]; my($defanswer)=$_[1]; my($reply); printf "%-45s [%-15s]: ",$message,$defanswer; $reply=; chop($reply); if ($reply eq "") { $reply=$defanswer; } return $reply; } sub yninput { my($message)=$_[0]; my($defanswer)=$_[1]; my($reply); printf "%s? (y/n) [%s]: ",$message,$defanswer; $reply=; chop($reply); if ($reply eq "") { $reply=$defanswer; } return $reply; } sub readfilters { my($i); if ( ! -e $filterdir ) { print<) { chop; s/$filterdir\/(.*)-filter/$1/g; $filters[$i]=$_; $i++; } close(FILTERS); foreach $entry (@filters) { $entry =~ s/-filter//g; } return sort(@filters); } if ( -e $printcap && !$force) { print< 72-length($filter)) { print "\n"; $l=0; } print "$filter "; } print "\n\n"; $ifilter[$p]=&input("The input filter to be used", $ifilter[$p]); if ($dev[$p] !~ /\/dev\//) { $remflags[$p]=":rm=$dev[$p]:rp=$short[$p]:lpr_bounce"; $dev[$p]=""; } elsif ($dev[$p] =~ /\/dev\/ttyS/) { $serflags[$p]=":bf=2400:fc=0:fs=1"; } $spooldir[$p]="/var/spool/lpd/$short[$p]"; print "\n"; } } } while ($full[$p] !~ /done\s*/); if ($p > 0) { if ($p == 1) { $d=0; } do { format top= Printer configuration Default printer (alias \`lp\') is marked with an asterisk. Printer name Short name Spool dir Device Input filter ------------------------------------------------------------------------------- . format STDOUT= @<<<<<<<<<<<< @<<<<<<<<< @<<<<<<<<<<<<<<<<<<< @<<<<<<<<< @<<<<<<<<<<<<<<<<<<@<< $full, $short, $spooldir, $dev, $ifilter, $a . for($i=0;$i<$p;$i++) { $full=$full[$i]; $short=$short[$i]; $spooldir=$spooldir[$i]; $dev=$dev[$i]; $ifilter=$ifilter[$i]; $a= ($remflags[$i] ne "") ? "R" : ""; $a= $a . (($i == $d) ? "*" : ""); write; } $ans="n"; $-=0; print "\n"; if ($p > 1) { $ans=&yninput("Do you want to change the default printer","n"); if ($ans =~ /y(es)?/) { $def=&input("New default printer (type its short name)",""); $d=0; while (($d < $p) && ($short[$d] !~ /$def/)) { $d++; } if ($d == $p) { $d = 0; } $short[$d]=$def; } } } while ($ans =~ /y(es)?/); $ok=&yninput("Is this ok","y"); } else { $ok="yes"; } } print "\n"; if ($p > 0) { if ( -x "/usr/bin/paperconf" ) { open(PAPERSIZE, "/usr/bin/paperconf -N|"); $papersize=; chop($papersize); close(PAPERSIZE); } $pagelength=66; if ($papersize =~ /A4/) { $pagelength=72; } print "Paper size is $papersize, page length is $pagelength lines.\n"; # Stop running daemons: if ($> == 0) { if ( -x "/etc/init.d/lpd" ) { system("/etc/init.d/lpd stop"); } if ( -x "/etc/init.d/lprng" ) { system("/etc/init.d/lprng stop"); } } open(PRINTCAP,">$printcap") || die "Can't write $printcap: $!"; print PRINTCAP < == 0) { if ( -x "/etc/init.d/lpd" ) { system("/etc/init.d/lpd start"); } if ( -x "/etc/init.d/lprng" ) { system("/etc/init.d/lprng start"); } } } else { print< to continue."; $dummy=; } exit 0;