#!/usr/bin/perl # redhat-fixes-check 0.01 -- 24 October 2000 # (Maybe should be named rpm-update.) # redhat-fixes-check uses a ftp directory listing (generated with lynx) # of the Red Hat security fixes directory and compares each fixed RPM # with those installed. If needed, it will download RPM and update using it. # This code is provided "as is" and without any express or # implied warranties, including, without limitation, the implied # warranties of merchantibility and fitness for a particular purpose. # Use at your own risk: In no event shall the author be liable # for any direct, incidental or indirect damages. $platform = "i386"; $rpm_query = 'rpm -q'; $rpm_update = 'rpm -Fvh'; $fetch_location = 'ftp://sunsite.ualberta.ca/pub/Mirror/Linux/redhat/ftp.redhat.com/updates/6.2/i386/'; $fetch_command = 'lynx -dump'; $update = 1; # Aug 22 21:41 rpm xchat-1.4.0-2.i386.rpm 616Kb # Sep 13 21:22 rpm xpdf-0.91-1.6x.i386.rpm 1198Kb # xpdf-0.90-4 # package xpdf-0.91-1.6x.i386.rpm is not installed while ($line=<>) { if ($line =~ / (\w+.*\.$platform\.rpm)\ +\d+\w+$/) { $filename = $1; # glibc-devel-2.1.3-21.i386.rpm $filename =~ /([\w-]+)\-(\d.*)\.$platform\.rpm/; $rpm_name = $1; $rpm_version = $2; $filenames{$rpm_name} = $filename; # strip Red Hat version like .6.x or .6x # $rpm_version =~ s/(\d.*)\.6\.?\x/$1/; $rpm_version =~ s/(\d.*)\.6\.?x/$1/; # print "checking $rpm_name version $rpm_version $filename ..."; $result = `$rpm_query $rpm_name 2>&1`; if ($result =~ /package .* is not installed/) { # simply ignore # anyways this error is sent to STDERR so we wouldn't even see it } elsif ($result =~ /^$rpm_name\-(\d.*)$/) { $current_version = $1; #print "current: $current_version -- new: $rpm_version\n"; if ($rpm_version gt $current_version) { print "Need $rpm_name-$rpm_version (old is $current_version)\n"; &fetch_and_install ($rpm_name); } } } } sub fetch_and_install { my $rpm_name = $_[0]; if ( -s "downloads/$filenames{$rpm_name}") { ## appears to already be downloaded print "$filenames{$rpm_name} already downloaded.\n"; } else { print "fetching $filenames{$rpm_name}...\n"; system ("$fetch_command $fetch_location$filenames{$rpm_name} > downloads/$filenames{$rpm_name}"); } if ($update) { print "updating $rpm_name...\n"; system ("$rpm_update downloads/$filenames{$rpm_name}"); } }