383b55351b919b7fd11d252252f3585f07b158ad
[userv-utils] / ipif / udptunnel-reconf.pl
1 #!/usr/bin/perl
2
3 #$sharedir= '/usr/local/share/userv/udptunnelconf';
4 $sharedir= '/home/ian/things/userv-utils/udptunnelconf';
5 $confdir= '/etc/udptunnel';
6
7 sub badusage () { die "usage: udptunnel-reconf [<directory>]\n"; }
8 $debug=0;
9
10 while ($ARGV[0] =~ m/^-/) {
11 $_= shift @ARGV;
12 last if m/^--$/;
13 if (m/^-d$/) { $debug++; next; }
14 badusage();
15 }
16
17 if (@ARGV) { $confdir= shift @ARGV; }
18 #badusage() if @ARGV;
19
20 chdir $confdir or die "$0: $confdir: $!\n";
21
22 sub run_m4 ($$$) {
23 my ($wanted, $site, $variable) = @_;
24 $x= "m4 -P -DWANTED=$wanted -DWHVARIABLE=V_$variable -DV_global=global ".
25 "-DV_site=$site ".
26 "-DV_defaults=$sharedir/defaults $sharedir/config.m4";
27 print STDERR $x,"\n" if $debug>=2;
28 open X, "$x |"
29 or die $!;
30 undef $/;
31 $m4out= <X>;
32 $/= "\n";
33 close X; $? and exit -1;
34 $m4out =~ s/^\s+//;
35 $m4out =~ s/\n+/\n/g;
36 $m4out =~ s/\s+$//;
37 print STDERR "$wanted/$variable($site) -> \`$m4out'\n" if $debug>=1;
38 return $m4out;
39 }
40
41 sub check_junk ($$) {
42 my ($emsg, $site) = @_;
43 $j= run_m4('JUNK',$site,'');
44 $j =~ s/^\# //g;
45 die "$0: $emsg: $j\n" if length $j;
46 }
47
48 check_junk("error in config",'');
49
50 @actives= split /\s+/, run_m4('ACTIVES','','');
51 @passives= split /\s+/, run_m4('PASSIVES','','');
52
53 foreach $site (@actives, @passives) {
54 check_junk("error in config for site $site",$site);
55 }
56
57 $_= run_m4('VARIABLE','greenend','command');
58 s/\\\n/ /g;
59 s/\s+/\n/g;
60 print $_,"\n" or die $!;