Home | History | Annotate | Line # | Download | only in mantools
      1  1.1  tron #!/usr/bin/perl
      2  1.1  tron 
      3  1.1  tron # Usage: xpostdef postconf.proto >postconf.proto.new
      4  1.1  tron 
      5  1.1  tron # Update parameter default values in postconf prototype file.
      6  1.1  tron 
      7  1.1  tron $POSTCONF="postconf";
      8  1.1  tron 
      9  1.1  tron # Read all the default parameter values. This also provides us with
     10  1.1  tron # a list of all the parameters that postconf knows about.
     11  1.1  tron 
     12  1.1  tron open(POSTCONF, "$POSTCONF -d|") || die "cannot run $POSTCONF -d: !$\n";
     13  1.1  tron while(<POSTCONF>) {
     14  1.1  tron     chop;
     15  1.1  tron     if (($name, $defval) = split(/\s+=\s+/, $_, 2)) {
     16  1.1  tron 	$defval =~ s/&/\&amp;/g;
     17  1.1  tron 	$defval =~ s/</\&lt;/g;
     18  1.1  tron 	$defval =~ s/>/\&gt;/g;
     19  1.1  tron 	$defval =~ s/\s+$//;
     20  1.1  tron 	$defaults{$name} = $defval;
     21  1.1  tron     } else {
     22  1.1  tron 	die "unexpected $POSTCONF output: $_\n";
     23  1.1  tron     }
     24  1.1  tron }
     25  1.1  tron close(POSTCONF) || die "$POSTCONF failed: $!\n"; 
     26  1.1  tron 
     27  1.1  tron # Censor out default values that are system or version dependent, or
     28  1.1  tron # that don't display well.
     29  1.1  tron 
     30  1.1  tron $censored = <<EOF;
     31  1.1  tron alias_database
     32  1.1  tron alias_maps
     33  1.1  tron command_directory
     34  1.1  tron command_expansion_filter
     35  1.1  tron config_directory
     36  1.1  tron daemon_directory
     37  1.1  tron default_database_type
     38  1.1  tron default_rbl_reply
     39  1.1  tron execution_directory_expansion_filter
     40  1.1  tron export_environment
     41  1.1  tron forward_expansion_filter
     42  1.1  tron forward_path
     43  1.1  tron html_directory
     44  1.1  tron import_environment
     45  1.1  tron mail_release_date
     46  1.1  tron mail_spool_directory
     47  1.1  tron mail_version
     48  1.1  tron mailbox_delivery_lock
     49  1.1  tron mailq_path
     50  1.1  tron manpage_directory
     51  1.1  tron mydomain
     52  1.1  tron myhostname
     53  1.1  tron mynetworks
     54  1.1  tron newaliases_path
     55  1.1  tron parent_domain_matches_subdomains
     56  1.1  tron proxy_read_maps
     57  1.1  tron queue_directory
     58  1.1  tron readme_directory
     59  1.1  tron sendmail_path
     60  1.1  tron smtpd_expansion_filter
     61  1.1  tron tls_random_source
     62  1.1  tron virtual_mailbox_lock
     63  1.1  tron milter_connect_macros
     64  1.1  tron milter_helo_macros
     65  1.1  tron milter_mail_macros
     66  1.1  tron milter_rcpt_macros
     67  1.1  tron milter_data_macros
     68  1.1  tron milter_unknown_command_macros
     69  1.1  tron milter_end_of_data_macros
     70  1.1  tron EOF
     71  1.1  tron 
     72  1.1  tron for $name (split(/\s+/, $censored)) {
     73  1.1  tron     $defaults{$name} = "see \"postconf -d\" output";
     74  1.1  tron }
     75  1.1  tron 
     76  1.1  tron # Process the postconf prototype file, and update default values
     77  1.1  tron # with output from the postconf command. Leave alone any defaults
     78  1.1  tron # that postconf didn't know about. This can happen when conditional
     79  1.1  tron # features have been compile time disabled.
     80  1.1  tron 
     81  1.1  tron $name = $defval = $text = $line = "";
     82  1.1  tron 
     83  1.1  tron while(<>) {
     84  1.1  tron     if (/^%PARAM/) {
     85  1.1  tron 
     86  1.1  tron 	# Print the updated parameter text. Keep the old default if
     87  1.1  tron 	# postconf doesn't have a suitable one.
     88  1.1  tron 
     89  1.1  tron 	if ($name) {
     90  1.1  tron 	    $defval = $defaults{$name} if (defined($defaults{$name}));
     91  1.1  tron 	    print "%PARAM $name $defval\n";
     92  1.1  tron 	}
     93  1.1  tron 	print $text;
     94  1.1  tron 
     95  1.1  tron 	# Reset the parameter name, default, and accumulated text.
     96  1.1  tron 
     97  1.1  tron 	$name = $defval = $text = $line = "";
     98  1.1  tron 
     99  1.1  tron 	# Accumulate the parameter name and default value.
    100  1.1  tron 
    101  1.1  tron 	do {
    102  1.1  tron 	    $_ =~ s/\s+$//;
    103  1.1  tron 	    $line .= " " . $_;
    104  1.1  tron 	} while(($_ = <POSTCONF>) && /^../);
    105  1.1  tron 	($junk, $class, $name, $defval) = split(/\s+/, $line, 4);
    106  1.1  tron     } else {
    107  1.1  tron 
    108  1.1  tron 	# Accumulate the text in the parameter definition.
    109  1.1  tron 
    110  1.1  tron 	$_ =~ s/\s+$/\n/;
    111  1.1  tron 	$text .= $_;
    112  1.1  tron 
    113  1.1  tron     }
    114  1.1  tron }
    115  1.1  tron 
    116  1.1  tron # Fix the last parameter.
    117  1.1  tron 
    118  1.1  tron if ($name && $text) {
    119  1.1  tron     $defval = $defaults{$name} if (defined($defaults{$name}));
    120  1.1  tron     print "%PARAM $name $defval\n$text";
    121  1.1  tron }
    122