More hacking on improved package updates list
authorJamie Cameron <jcameron@webmin.com>
Tue, 5 Jan 2010 00:07:32 +0000 (16:07 -0800)
committerJamie Cameron <jcameron@webmin.com>
Tue, 5 Jan 2010 00:07:32 +0000 (16:07 -0800)
package-updates/index.cgi
package-updates/lang/en
package-updates/package-updates-lib.pl
package-updates/update.cgi
package-updates/update.pl
package-updates/view.cgi
software/apt-lib.pl
software/yum-lib.pl

index 7c13d98..f05f382 100755 (executable)
@@ -11,7 +11,12 @@ if ($in{'clear'}) {
 
 # See if any security updates exist
 $in{'mode'} ||= 'updates';
-@avail = &list_available(0);
+if ($in{'mode'} eq 'updates') {
+       @avail = &list_possible_updates(0);
+       }
+else {
+       @avail = &list_available(0);
+       }
 ($sec) = grep { $_->{'security'} } @avail;
 
 # Show mode selector (all, updates only, updates and new)
index ddfc655..cb58991 100644 (file)
@@ -48,6 +48,7 @@ index_clear=Show All
 
 update_title=Update Packages
 update_pkg=Now updating $1 ..
+update_pkg2=Now installing $1 ..
 update_done=Installed package $1 $2.
 update_ok=Successfully installed $1 packages.
 update_failed=No packages were installed. Check the messages above for the cause of the error.
index 978916e..5e2061d 100644 (file)
@@ -285,10 +285,19 @@ sub package_install
 {
 my ($name, $system) = @_;
 my @rv;
-my ($pkg) = grep { $_->{'update'} eq $name &&
-                     ($_->{'system'} eq $system || !$system) }
-                   sort { &compare_versions($b, $a) }
-                        &list_available(0);
+my $pkg;
+# First get from list of updates
+($pkg) = grep { $_->{'update'} eq $name &&
+               ($_->{'system'} eq $system || !$system) }
+             sort { &compare_versions($b, $a) }
+                  &list_possible_updates(0);
+if (!$pkg) {
+       # Then try list of all available packages
+       ($pkg) = grep { $_->{'update'} eq $name &&
+                       ($_->{'system'} eq $system || !$system) }
+                     sort { &compare_versions($b, $a) }
+                          &list_available(0);
+       }
 if (!$pkg) {
        print &text('update_efindpkg', $name),"<p>\n";
        return ( );
@@ -363,6 +372,7 @@ if (&supports_updates_available()) {
                            'epoch' => $a->{'epoch'},
                            'oldepoch' => $c->{'epoch'},
                            'security' => $a->{'security'},
+                           'source' => $a->{'source'},
                            'desc' => $c->{'desc'} || $a->{'desc'} });
                }
        }
@@ -389,6 +399,7 @@ else {
                                    'epoch' => $a->{'epoch'},
                                    'oldepoch' => $c->{'epoch'},
                                    'security' => $a->{'security'},
+                                   'source' => $a->{'source'},
                                    'desc' => $c->{'desc'} || $a->{'desc'},
                                    'severity' => 0 });
                        }
index ad1be6b..22d4dfc 100755 (executable)
@@ -81,10 +81,11 @@ else {
                }
        else {
                # Do it
+               $msg = $in{'mode'} eq 'new' ? 'update_pkg2' : 'update_pkg';
                foreach my $ps (@pkgs) {
                        ($p, $s) = split(/\//, $ps);
                        next if ($donedep{$p});
-                       print &text('update_pkg', "<tt>$p</tt>"),"<br>\n";
+                       print &text($msg, "<tt>$p</tt>"),"<br>\n";
                        print "<ul>\n";
                        @pgot = &package_install($p, $s);
                        foreach $g (@pgot) {
index e229950..3524a32 100755 (executable)
@@ -9,19 +9,9 @@ if ($ARGV[0] eq "--debug" || $ARGV[0] eq "-debug") {
        }
 
 # See what needs doing
-@current = &list_current(1);
-@avail = &list_available(0);
-foreach $c (sort { $a->{'name'} cmp $b->{'name'} } @current) {
-       ($a) = grep { $_->{'name'} eq $c->{'name'} &&
-                     $_->{'system'} eq $c->{'system'} } @avail;
-       if ($a->{'version'} && &compare_versions($a, $c) > 0) {
-               # An update is available
-               push(@todo, { 'name' => $c->{'name'},
-                             'update' => $a->{'update'},
-                             'oldversion' => $c->{'version'},
-                             'version' => $a->{'version'},
-                             'level' => $a->{'security'} ? 1 : 2 });
-               }
+@todo = &list_possible_updates();
+foreach $a (@todo) {
+       $a->{'level'} = $a->{'security'} ? 1 : 2;
        }
 
 # Install packages that are needed
index 20d26d9..5ac2648 100755 (executable)
@@ -6,7 +6,8 @@ require './package-updates-lib.pl';
 &ReadParse();
 
 # Get the package
-@avail = &list_available(0);
+@avail = $in{'mode'} eq 'updates' ? &list_possible_updates(0)
+                                 : &list_available(0);
 ($a) = grep { $_->{'name'} eq $in{'name'} &&
              $_->{'system'} eq $in{'system'} } @avail;
 @current = &list_current(0);
@@ -48,7 +49,9 @@ if ($a) {
        }
 
 # Source, if available
-print &ui_table_row($text{'view_source'}, ucfirst($a->{'source'}));
+if ($a->{'source'}) {
+       print &ui_table_row($text{'view_source'}, ucfirst($a->{'source'}));
+       }
 
 # Change log, if possible
 if ($a) {
index 0d7f63f..0722467 100755 (executable)
@@ -189,4 +189,80 @@ close(DUMP);
 return @rv;
 }
 
+# update_system_updates()
+# Returns a list of available package updates
+sub update_system_updates
+{
+if (&has_command("apt-show-versions")) {
+       # This awesome command can give us all updates in one hit
+       local @rv;
+       &open_execute_command(PKGS,
+               "LANG='' LC_ALL='' apt-show-versions", 1, 1);
+       while(<PKGS>) {
+               if (/^(\S+)\/(\S+)\s+upgradeable\s+from\s+(\S+)\s+to\s+(\S+)/) {
+                       local $pkg = { 'name' => $1,
+                                      'source' => $2,
+                                      'version' => $4 };
+                       if ($pkg->{'version'} =~ s/^(\S+)://) {
+                               $pkg->{'epoch'} = $1;
+                               }
+                       push(@rv, $pkg);
+                       }
+               }
+       close(PKGS);
+       return @rv;
+       }
+else {
+       # Need to manually compose by calling dpkg and apt-cache showpkg ..
+       local %packages;
+       local $n = &list_packages();
+       local %currentmap;
+       for(my $i=0; $i<$n; $i++) {
+               local $pkg = { 'name' => $packages{$i,'name'},
+                              'oldversion' => $packages{$i,'version'},
+                              'desc' => $packages{$i,'desc'},
+                              'oldepoch' => $packages{$i,'epoch'} };
+               $currentmap{$pkg->{'name'}} ||= $pkg;
+               }
+       local @rv;
+       local @names = keys %currentmap;
+       while(scalar(@names)) {
+               local @somenames;
+               if (scalar(@names) > 100) {
+                       # Do 100 at a time
+                       @somenames = @names[0..99];
+                       @names = @names[100..$#names];
+                       }
+               else {
+                       # Do the rest
+                       @somenames = @names;
+                       @names = ( );
+                       }
+               &open_execute_command(PKGS,
+                       "LANG='' LC_ALL='' apt-cache showpkg ".
+                       join(" ", @somenames), 1, 1);
+               local $pkg = undef;
+               while(<PKGS>) {
+                       s/\r|\n//g;
+                       if (/^\s*Package:\s*(\S+)/) {
+                               $pkg = $currentmap{$1};
+                               }
+                       elsif (/^Versions:\s*$/ && $pkg && !$pkg->{'version'}) {
+                               # Newest version is on next line
+                               local $ver = <PKGS>;
+                               $ver =~ s/\s.*\r?\n//;
+                               local $epoch;
+                               if ($ver =~ s/^(\d+)://) {
+                                       $epoch = $1;
+                                       }
+                               $pkg->{'version'} = $ver;
+                               $pkg->{'epoch'} = $epoch;
+                               push(@rv, $pkg);
+                               }
+                       }
+               close(PKGS);
+               }
+       return @rv;
+       }
+}
 
index f0bc12b..3de2eec 100755 (executable)
@@ -233,7 +233,6 @@ while(<PKG>) {
                               'arch' => $2,
                               'version' => $3,
                               'source' => $4 };
-               $pkg->{'version'} = $1;
                if ($pkg->{'version'} =~ s/^(\S+)://) {
                        $pkg->{'epoch'} = $1;
                        }