Diff for /loncom/build/check-rpms between versions 1.2 and 1.6

version 1.2, 2002/02/27 01:47:31 version 1.6, 2002/11/04 02:52:39
Line 1 Line 1
 #!/usr/bin/perl  #!/usr/bin/perl
 #  #
 # check-rpms, version 2.1.0  # check-rpms, version 2.1.1
 # Martin Siegert, SFU, siegert@sfu.ca, Feb 02  # Martin Siegert, SFU, siegert@sfu.ca, Feb 02
 #  #
   # documentation and minor patches,
   # Scott Harrison sharrison@users.sourceforge.net 2002
   
 =pod  =pod
   
 =head1 NAME  =head1 NAME
Line 87  use Getopt::Long; Line 90  use Getopt::Long;
   
 my $retval = &GetOptions("verbose|v","lm|list-missing","lq|list-questionable",  my $retval = &GetOptions("verbose|v","lm|list-missing","lq|list-questionable",
                          "dir|d=s","ftp:s","noftp","download|dl","recheck|r",                           "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  =pod
   
Line 200  example configuration file is given belo Line 203  example configuration file is given belo
 is omitted, I<check-rpms> will use the default configuration  is omitted, I<check-rpms> will use the default configuration
 file I</usr/local/etc/check-rpms.conf>, if it exists.  file I</usr/local/etc/check-rpms.conf>, if it exists.
   
   =item B<--rpmuser> I<user name>
   
   Specifying $RPMUSER on the command line.
   
 =back  =back
   
 =head1 EXAMPLES  =head1 EXAMPLES
Line 294  Example configuration file: Line 301  Example configuration file:
   
  # $RPMUSER is the user name that check-rpms switches to for most of   # $RPMUSER is the user name that check-rpms switches to for most of
  # the script when run as root   # the script when run as root
  $RPMUSER = "joe";   $RPMUSER = "adminjoe";
   
  # $FTPSERVER and $FTPUPDATES are the hostname of a ftp server and the   # $FTPSERVER and $FTPUPDATES are the hostname of a ftp server and the
  # directory where RPM updates can be found without the <arch> directory.   # directory where RPM updates can be found without the <arch> directory.
Line 315  if ( -f $CONF) { Line 322  if ( -f $CONF) {
    $FTPUPDATES = $DEFFTPUPDATES;     $FTPUPDATES = $DEFFTPUPDATES;
 }  }
   
   if ($opt_rpmuser) {
      $DEFRPMUSER = $opt_rpmuser;
   }
   
 # check whether we are running as root  # check whether we are running as root
 if ($< == 0){  if ($< == 0){
    if (! $RPMUSER) {     if (! $RPMUSER) {
Line 371  if (defined $opt_ftp || $FTP) { Line 382  if (defined $opt_ftp || $FTP) {
   
    if ($download || $recheck) {     if ($download || $recheck) {
        if ( ! -d $RPMDIR) {         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"; }            if ($retval) { die "error: could not create $RPMDIR\n"; }
       }        }
    }     }
Line 379  if (defined $opt_ftp || $FTP) { Line 395  if (defined $opt_ftp || $FTP) {
    die "Either $RPMDIR does not exist or it does not contain any packages.\n";     die "Either $RPMDIR does not exist or it does not contain any packages.\n";
 }  }
   
   my $FTPSERVER_auth = $FTPSERVER;
   $FTPSERVER_auth =~ s/^(\w+)\:(\w+)\@/-u $1 -p $2 /;
   
 if ($recheck) {  if ($recheck) {
    $questionable=1;     $questionable=1;
 }  }
Line 387  if (defined $opt_update || defined $opt_ Line 406  if (defined $opt_update || defined $opt_
     $no_kernel=1;      $no_kernel=1;
 }  }
   
 $PROC = `grep -i athlon /proc/cpuinfo`;  $PROC = `grep -i "athlon\|amd" /proc/cpuinfo`;
 if ( ! "$PROC" ) {  if ( ! "$PROC" ) {
     $PROC = `uname -m`;      $PROC = `uname -m`;
     chomp($PROC);      chomp($PROC);
Line 458  if ($ftp) { Line 477  if ($ftp) {
 $giveup = 0;  $giveup = 0;
 for (@templist) {  for (@templist) {
    ($rpm, $pkg, $pver, $arch) = m/(([^ ]*)-([^- ]+-[^-]+\.(\w+)\.rpm))/;     ($rpm, $pkg, $pver, $arch) = m/(([^ ]*)-([^- ]+-[^-]+\.(\w+)\.rpm))/;
      if (! defined $local_rpm{$pkg}) { next; }
    if ($remote_rpm{$pkg}) {     if ($remote_rpm{$pkg}) {
       # problem: there are several versions of the same package.        # problem: there are several versions of the same package.
       # this means that the package exists for different architectures        # this means that the package exists for different architectures
Line 540  for (@local_rpm_list) { Line 560  for (@local_rpm_list) {
             push(@q_updates, $rpm);              push(@q_updates, $rpm);
         } elsif ( $vcmp < 0 ) {          } elsif ( $vcmp < 0 ) {
             # local version is lower              # local version is lower
             if ( $qflag ) {              push(@updates, $rpm);
                push(@q_updates, $rpm);  
             } else {  
                push(@updates, $rpm);  
             }  
  }   }
     } elsif ($list_missing) {      } elsif ($list_missing) {
  print "Package '$pkg' missing from remote repository\n";   print "Package '$pkg' missing from remote repository\n";
     }      }
 }  }
   
   
 if ($recheck && @q_updates) {  if ($recheck && @q_updates) {
    if ($ftp) {         if ($ftp) {    
       for (@q_updates) {        for (@q_updates) {
Line 560  if ($recheck && @q_updates) { Line 577  if ($recheck && @q_updates) {
       if ($verbose) {        if ($verbose) {
          print "Getting questionable packages form $FTPSERVER ...\n";           print "Getting questionable packages form $FTPSERVER ...\n";
       }        }
       my $status = system("$FTPGET $FTPSERVER $RPMDIR @ftp_files");        my $status = system("$FTPGET $FTPSERVER_auth $RPMDIR @ftp_files");
       if ($status) {        if ($status) {
          if ($< == 0) {           if ($< == 0) {
             # if we are running as root exit to avoid symlink attacks, etc.              # if we are running as root exit to avoid symlink attacks, etc.
   print("DEBUG DEBUG $FTPGET $FTPSERVER_auth $RPMDIR @ftp_files");
             die "$FTPGET failed with status ", $status/256, ".\n";              die "$FTPGET failed with status ", $status/256, ".\n";
  } else {   } else {
             print STDERR "warning: $FTPGET failed with status ", $status/256, ".\n";              print STDERR "warning: $FTPGET failed with status ", $status/256, ".\n";
Line 605  if (@updates) { Line 623  if (@updates) {
        if ($verbose) {         if ($verbose) {
           print "starting downloads ... \n";            print "starting downloads ... \n";
        }         }
        my $status = system("$FTPGET $FTPSERVER $RPMDIR @ftp_files");         my $status = system("$FTPGET $FTPSERVER_auth $RPMDIR @ftp_files");
        if ($status) {         if ($status) {
           if ($< == 0) {            if ($< == 0) {
              # if we are running as root exit to avoid symlink attacks, etc.               # if we are running as root exit to avoid symlink attacks, etc.
Line 642  if (@q_updates && $questionable) { Line 660  if (@q_updates && $questionable) {
        }         }
        if ($verbose) {         if ($verbose) {
           print "starting downloads ... \n";            print "starting downloads ... \n";
           system("$FTPGET $FTPSERVER $$RPMDIR @ftp_files");            system("$FTPGET $FTPSERVER_auth $$RPMDIR @ftp_files");
           print "... done.\n";            print "... done.\n";
        } else {         } else {
           system("$FTPGET $FTPSERVER $$RPMDIR @ftp_files");            system("$FTPGET $FTPSERVER_auth $$RPMDIR @ftp_files");
        }         }
     }                 }           
 }  }
Line 676  sub ftp_download { Line 694  sub ftp_download {
        my ($arch) = m/[^ ]*-[^-]+-[^-]*\.(\w+)\.rpm$/;         my ($arch) = m/[^ ]*-[^-]+-[^-]*\.(\w+)\.rpm$/;
        push(@ftp_packages,"$FTPDIR/$arch/$_");         push(@ftp_packages,"$FTPDIR/$arch/$_");
     }      }
     my $status = system("$FTPGET $FTPSERVER $downloaddir @ftp_packages");      my $status = system("$FTPGET $FTPSERVER_auth $downloaddir @ftp_packages");
     return $status;      return $status;
 }  }
   
Line 698  sub pkg_compare($$$) { Line 716  sub pkg_compare($$$) {
    }     }
    my $serial1 = `rpm -qp --queryformat '%{SERIAL}' $RPMDIR/$pkg1`;     my $serial1 = `rpm -qp --queryformat '%{SERIAL}' $RPMDIR/$pkg1`;
    my $serial2 = `rpm -qp --queryformat '%{SERIAL}' $RPMDIR/$pkg2`;     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($$$) {  sub mulpkg_msg($$$) {

Removed from v.1.2  
changed lines
  Added in v.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>