Handle hostnames with upper-case letters
[webmin.git] / package-updates / update.pl
1 #!/usr/local/bin/perl
2 # Check for and install updates
3
4 $no_acl_check++;
5 require './package-updates-lib.pl';
6
7 if ($ARGV[0] eq "--debug" || $ARGV[0] eq "-debug") {
8         $debug = 1;
9         }
10
11 # See what needs doing
12 @todo = &list_possible_updates();
13 foreach $a (@todo) {
14         $a->{'level'} = $a->{'security'} ? 1 : 2;
15         }
16
17 # Install packages that are needed
18 $tellcount = 0;
19 %already = ( );
20 foreach $t (@todo) {
21         next if ($already{$t->{'update'}});
22         if ($t->{'level'} <= $config{'sched_action'}) {
23                 # Can install
24                 $body .= "An update to $t->{'name'} from $t->{'oldversion'} to $t->{'version'} is needed.\n";
25                 ($out, $done) = &capture_function_output(
26                                   \&package_install, $t->{'update'});
27                 if (@$done) {
28                         $body .= "This update has been successfully installed.\n\n";
29                         }
30                 else {
31                         $body .= "However, this update could not be installed! Try the update manually\nusing the Package Updates module.\n\n";
32                         }
33                 foreach $p (@$done) {
34                         $already{$p}++;
35                         }
36                 }
37         else {
38                 # Just tell the user about it
39                 $body .= "An update to $t->{'name'} from $t->{'oldversion'} to $t->{'version'} is available.\n\n";
40                 $tellcount++;
41                 }
42         }
43
44 if ($tellcount) {
45         # Add link to Webmin
46         &get_miniserv_config(\%miniserv);
47         $proto = $miniserv{'ssl'} ? 'https' : 'http';
48         $port = $miniserv{'port'};
49         $url = $proto."://".&get_system_hostname().":".$port."/$module_name/";
50         $body .= "Updates can be installed at $url\n\n";
51         }
52
53 # Email the admin
54 if ($config{'sched_email'} && $body) {
55         &foreign_require("mailboxes", "mailboxes-lib.pl");
56         my $from = &mailboxes::get_from_address();
57         my $mail = { 'headers' =>
58                         [ [ 'From', $from ],
59                           [ 'To', $config{'sched_email'} ],
60                           [ 'Subject', "Package updates on ".
61                                        &get_system_hostname() ] ],
62                         'attach' =>
63                         [ { 'headers' => [ [ 'Content-type', 'text/plain' ] ],
64                             'data' => $body } ] };
65         &mailboxes::send_mail($mail, undef, 1, 0);
66         if ($debug) {
67                 print STDERR $body;
68                 }
69         }
70