Handle hostnames with upper-case letters
[webmin.git] / thirdparty.pl
1 # thirdparty.pl
2 # Checks for modules available in an old install of webmin that are
3 # not included in this new install, and offers to copy them across.
4 # Also re-creates clones of existing modules in the new install
5
6 ($newdir, $olddir, $copythird) = @ARGV;
7
8 # find missing modules
9 opendir(DIR, $olddir);
10 while($m = readdir(DIR)) {
11         next if ($m =~ /^\./);
12         if (-r "$olddir/$m/module.info" && !-r "$newdir/$m/module.info") {
13                 if (-l "$olddir/$m") {
14                         # Found a clone - recreate it
15                         $clone = readlink("$olddir/$m");
16                         symlink($clone, "$newdir/$m");
17                         }
18                 else {
19                         # Found a candidate for copying
20                         local %minfo;
21                         &read_file("$olddir/$m/module.info", \%minfo);
22                         push(@missing, $m);
23                         push(@missdesc, $minfo{'desc'});
24                         }
25                 }
26         elsif (-r "$olddir/$m/theme.info" && !-r "$newdir/$m/theme.info") {
27                 # Found a theme for copying
28                 local %tinfo;
29                 &read_file("$olddir/$m/theme.info", \%tinfo);
30                 push(@missing, $m);
31                 push(@missdesc, $tinfo{'desc'});
32                 }
33         }
34 closedir(DIR);
35
36 if (@missing) {
37         # Tell the user, and ask whether to copy
38         if (!$copythird) {
39                 print "The following third party modules were found in your old Webmin\n";
40                 print "installation in $olddir :\n";
41                 for($i=0; $i<@missing; $i++) {
42                         printf "  %-12.12s %s\n", $missing[$i], $missdesc[$i];
43                         }
44                 print "Copy to new Webmin installation (y/n): ";
45                 chop($resp = <STDIN>);
46                 $copythird = $resp =~ /^y/i;
47                 }
48         if ($copythird) {
49                 foreach $m (@missing) {
50                         system("cp -rp $olddir/$m $newdir");
51                         }
52                 }
53         }
54
55 # read_file(file, array)
56 # Fill an associative array with name=value pairs from a file
57 sub read_file
58 {
59 local($arr);
60 $arr = $_[1];
61 open(ARFILE, $_[0]) || return 0;
62 while(<ARFILE>) {
63         chop;
64         if (!/^#/ && /^([^=]+)=(.*)$/) { $$arr{$1} = $2; }
65         }
66 close(ARFILE);
67 return 1;
68 }
69