3 # Copy the appropriate config file for each module into the webmin config
4 # directory. If it is already there, merge in new directives. Called with
5 # <osname> <osversion> <install dir> <config dir> <module>+
7 @ARGV >= 4 || die "usage: copyconfig.pl <os>[/real-os] <version>[/real-version] <webmin-dir> <config-dir> [module ...]";
12 ($os, $real_os) = split(/\//, $os);
13 ($ver, $real_ver) = split(/\//, $ver);
19 foreach $f (readdir(DIR)) {
20 if (readlink("$wadir/$f")) {
21 @st = stat("$wadir/$f");
22 push(@{$clone{$st[1]}}, $f);
27 # For each module, copy its config to itself and all clones
28 @mods = @ARGV[4..$#ARGV];
30 # Find any range-number config files. Search first by real OS type
31 # (ie Ubuntu 6.1), then by internal OS code (ie. debian-linux 3.1)
32 $srcdir = "$wadir/$m";
33 $rangefile = $real_rangefile = undef;
34 foreach $ov ([ $real_os, $real_ver, \$real_rangefile ],
35 [ $os, $ver, \$rangefile ]) {
36 my ($o, $v, $rf) = @$ov;
37 opendir(DIR, $srcdir);
38 while($f = readdir(DIR)) {
39 if ($f =~ /^config\-\Q$o\E\-([0-9\.]+)\-([0-9\.]+)$/ &&
40 $v >= $1 && $v <= $2) {
43 elsif ($f =~ /^config\-\Q$o\E\-([0-9\.]+)\-(\*|ALL)$/ &&
47 elsif ($f =~ /^config\-\Q$o\E\-(\*|ALL)\-([0-9\.]+)$/ &&
55 # Find the best-matching config file. Search first by real OS type,
56 # then by internal OS code
58 # Check for real OS match by name and version, version range, or
60 if (-r "$srcdir/config-$real_os-$real_ver") {
61 $conf = "$srcdir/config-$real_os-$real_ver";
63 elsif ($real_rangefile) {
64 $conf = $real_rangefile;
66 elsif (-r "$srcdir/config-$real_os") {
67 $conf = "$srcdir/config-$real_os";
70 # Check for OS code match by name and version, version range, or name
71 elsif (-r "$srcdir/config-$os-$ver") {
72 $conf = "$srcdir/config-$os-$ver";
77 elsif (-r "$srcdir/config-$os") {
78 $conf = "$srcdir/config-$os";
81 # Check for config for an entire OS class, like *-linux
82 elsif ($os =~ /^(\S+)-(\S+)$/ && -r "$srcdir/config-ALL-$2") {
83 $conf = "$srcdir/config-ALL-$2";
85 elsif ($os =~ /^(\S+)-(\S+)$/ && -r "$srcdir/config-*-$2") {
86 $conf = "$srcdir/config-*-$2";
89 # Use default config file, if it exists
90 elsif (-r "$srcdir/config") {
91 $conf = "$srcdir/config";
98 @copyto = ( @{$clone{$st[1]}}, $m );
99 foreach $c (@copyto) {
100 if (!-d "$confdir/$c") {
101 # New module .. need to create config dir
102 mkdir("$confdir/$c", 0755);
105 undef(%oldconf); undef(%newconf);
106 &read_file("$confdir/$c/config", \%oldconf);
107 &read_file($conf, \%newconf);
108 foreach $k (keys %oldconf) {
109 $newconf{$k} = $oldconf{$k};
111 &write_file("$confdir/$c/config", \%newconf);
114 print join(" ", @newmods),"\n";
116 # read_file(file, array)
117 # Fill an associative array with name=value pairs from a file
122 open(ARFILE, $_[0]) || return 0;
125 if (!/^#/ && /^([^=]+)=(.*)$/) { $$arr{$1} = $2; }
131 # write_file(file, array)
132 # Write out the contents of an associative array as name=value lines
137 open(ARFILE, "> $_[0]");
138 foreach $k (keys %$arr) {
139 print ARFILE "$k=$$arr{$k}\n";