Handle hostnames with upper-case letters
[webmin.git] / install-module.pl
1 #!/usr/local/bin/perl
2 # install-module.pl
3 # Install a single module file
4
5 # Check arguments
6 $nodeps = 0;
7 if ($ARGV[0] eq "--nodeps") {
8         shift(@ARGV);
9         $nodeps = 1;
10         }
11 while($ARGV[0] eq "--acl") {
12         shift(@ARGV);
13         push(@grant, shift(@ARGV));
14         }
15 if (@ARGV > 2 || !@ARGV) {
16         die "usage: install-module.pl [--nodeps] [--acl user]* <module.wbm> [config_directory]";
17         }
18 $file = $ARGV[0];
19 $config = $ARGV[1] ? $ARGV[1] : "/etc/webmin";
20 -r $file || die "$file does not exist";
21 open(CONF, "$config/miniserv.conf") ||
22         die "Failed to read $config/miniserv.conf - maybe $config is not a Webmin config directory";
23 while(<CONF>) {
24         s/\r|\n//g;
25         if (/^root=(.*)/) {
26                 $root = $1;
27                 }
28         }
29 close(CONF);
30 -d $root || die "Webmin directory $root does not exist";
31 chop($var = `cat $config/var-path`);
32
33 if ($file !~ /^\//) {
34         chop($pwd = `pwd`);
35         $file = "$pwd/$file";
36         }
37
38 # Set up webmin environment
39 $ENV{'WEBMIN_CONFIG'} = $config;
40 $ENV{'WEBMIN_VAR'} = $var;
41 $no_acl_check++;
42 chdir($root);
43 $0 = "$root/install-module.pl";
44 eval "use WebminCore;";
45 &init_config();
46
47 # Install it, using the standard function
48 &foreign_require("webmin", "webmin-lib.pl");
49 if (@grant) {
50         $newusers = \@grant;
51         }
52 else {
53         $newusers = &webmin::get_newmodule_users();
54         $newusers ||= [ "root", "admin" ];
55         }
56 $rv = &webmin::install_webmin_module($file, 0, $nodeps, $newusers);
57 if (ref($rv)) {
58         for($i=0; $i<@{$rv->[0]}; $i++) {
59                 printf "Installed %s in %s (%d kb)\n",
60                         $rv->[0]->[$i],
61                         $rv->[1]->[$i],
62                         $rv->[2]->[$i];
63                 }
64         }
65 else {
66         $rv =~ s/<[^>]+>//g;
67         print STDERR "Install failed : $rv\n";
68         }
69