--- loncom/build/check-rpms 2002/02/27 01:47:31 1.2 +++ loncom/build/check-rpms 2002/09/05 17:20:46 1.5 @@ -1,8 +1,11 @@ #!/usr/bin/perl # -# check-rpms, version 2.1.0 +# check-rpms, version 2.1.1 # Martin Siegert, SFU, siegert@sfu.ca, Feb 02 # +# documentation and minor patches, +# Scott Harrison sharrison@users.sourceforge.net 2002 + =pod =head1 NAME @@ -87,7 +90,7 @@ use Getopt::Long; my $retval = &GetOptions("verbose|v","lm|list-missing","lq|list-questionable", "dir|d=s","ftp:s","noftp","download|dl","recheck|r", - "nk|no-kernel","update","c=s"); + "nk|no-kernel","update","c=s","rpmuser=s"); =pod @@ -200,6 +203,10 @@ example configuration file is given belo is omitted, I will use the default configuration file I, if it exists. +=item B<--rpmuser> I + +Specifying $RPMUSER on the command line. + =back =head1 EXAMPLES @@ -294,7 +301,7 @@ Example configuration file: # $RPMUSER is the user name that check-rpms switches to for most of # the script when run as root - $RPMUSER = "joe"; + $RPMUSER = "adminjoe"; # $FTPSERVER and $FTPUPDATES are the hostname of a ftp server and the # directory where RPM updates can be found without the directory. @@ -315,6 +322,10 @@ if ( -f $CONF) { $FTPUPDATES = $DEFFTPUPDATES; } +if ($opt_rpmuser) { + $DEFRPMUSER = $opt_rpmuser; +} + # check whether we are running as root if ($< == 0){ if (! $RPMUSER) { @@ -371,7 +382,12 @@ if (defined $opt_ftp || $FTP) { if ($download || $recheck) { if ( ! -d $RPMDIR) { - $retval = system("mkdir -p $RPMDIR; chmod 700 $RPMDIR"); + if ($verbose) { print "Creating $RPMDIR ...\n"; } + if ($< == 0) { + $retval = system("su $RPMUSER -c \'mkdir -p $RPMDIR\'; chmod 700 $RPMDIR"); + } else { + $retval = system("mkdir -p $RPMDIR; chmod 700 $RPMDIR"); + } if ($retval) { die "error: could not create $RPMDIR\n"; } } } @@ -387,7 +403,7 @@ if (defined $opt_update || defined $opt_ $no_kernel=1; } -$PROC = `grep -i athlon /proc/cpuinfo`; +$PROC = `grep -i "athlon\|amd" /proc/cpuinfo`; if ( ! "$PROC" ) { $PROC = `uname -m`; chomp($PROC); @@ -458,6 +474,7 @@ if ($ftp) { $giveup = 0; for (@templist) { ($rpm, $pkg, $pver, $arch) = m/(([^ ]*)-([^- ]+-[^-]+\.(\w+)\.rpm))/; + if (! defined $local_rpm{$pkg}) { next; } if ($remote_rpm{$pkg}) { # problem: there are several versions of the same package. # this means that the package exists for different architectures @@ -540,11 +557,7 @@ for (@local_rpm_list) { push(@q_updates, $rpm); } elsif ( $vcmp < 0 ) { # local version is lower - if ( $qflag ) { - push(@q_updates, $rpm); - } else { - push(@updates, $rpm); - } + push(@updates, $rpm); } } elsif ($list_missing) { print "Package '$pkg' missing from remote repository\n"; @@ -698,7 +711,25 @@ sub pkg_compare($$$) { } my $serial1 = `rpm -qp --queryformat '%{SERIAL}' $RPMDIR/$pkg1`; my $serial2 = `rpm -qp --queryformat '%{SERIAL}' $RPMDIR/$pkg2`; - ($serial2 > $serial1) ? return 1 : return 0; + if ($serial2 > $serial1) { + remove_pkg("$RPMDIR/$pkg1"); + return 1; + } else { + remove_pkg("$RPMDIR/$pkg2"); + return 0; + } +} + +sub remove_pkg($) { + my ($pkg) = @_; + if ($verbose) { + print "Removing $pkg ...\n"; + } + my $status = system("rm -f $pkg"); + if ($status) { + printf STDERR "error: could not remove $pkg. You must remove this file before updating.\n"; + if ($update) { $giveup = 1; } + } } sub mulpkg_msg($$$) {