[LON-CAPA-cvs] cvs: loncom /build CHECKRPMS

harris41 lon-capa-cvs@mail.lon-capa.org
Sat, 03 Aug 2002 17:06:21 -0000


harris41		Sat Aug  3 13:06:21 2002 EDT

  Modified files:              
    /loncom/build	CHECKRPMS 
  Log:
  BUG 622 FIX; modularized code; pod documentation; more servers to check against
  (7 instead of 2); improved error detection; documenting plans for
  further improvements
  
  
Index: loncom/build/CHECKRPMS
diff -u loncom/build/CHECKRPMS:1.1 loncom/build/CHECKRPMS:1.2
--- loncom/build/CHECKRPMS:1.1	Wed May  1 13:01:18 2002
+++ loncom/build/CHECKRPMS	Sat Aug  3 13:06:21 2002
@@ -1,46 +1,146 @@
 #!/usr/bin/perl
 
-my $RHversion = (split /\s/, `cat /etc/redhat-release`)[4];
-my $FTPSERVER;
-`ping -q -c 1 mirror.pa.msu.edu 2>/dev/null`;
-if (!$FTPSERVER and $?==0) {
-    `ncftpls ftp://mirror.pa.msu.edu`;
-    if ($?==0) {
-	$FTPSERVER="mirror.pa.msu.edu";
-   $FTPUPDATES="mirror.pa.msu.edu/linux/redhat/linux/updates/$RHversion/en/os";
-    }
+=pod
+
+=head1 NAME
+
+B<CHECKRPMS> - automated status report about RPMs on a system
+
+=head1 SYNOPSIS
+
+./CHECKRPMS
+
+or
+
+perl CHECKRPMS
+
+=head1 DESCRIPTION
+
+This file automates the usage of Martin Siegert's "check-rpms"
+script.  It runs through a list of possible mirror sites
+until it finds one with a reasonably good FTP connection.
+
+=head2 Future directions
+
+Eventually, this script may have a simple argument format
+that allows the user to VIEW, DOWNLOAD, or AUTOUPDATE their
+computer.  Or, this script may evolve into an interactive
+series of steps:  For example, there may be questions like this:
+
+=over 4
+
+=item *
+
+Do you want to (D)ownload or (A)utoupdate the RPMs
+in the list above?
+
+=item *
+
+Specify a download location for the RPMs
+(default=/tmp/update_my_rpms/)?
+
+=back
+
+Note that there are no current plans to automate a software upgrade of the
+kernel.  This step should be performed by a qualified system administrator.
+
+=head1 AUTHOR
+
+Scott Harrison, sharrison@users.sourceforge.net, 2002
+
+=cut
+
+# =================================================== GENERAL INITIAL VARIABLES
+# ---------------- The FTP servers (and their directory paths) to check against
+my @serverpaths_to_try=(
+   'spock.lite.msu.edu/linux/redhat/linux/updates/',
+   'mirror234.pa.msu.edu/linux/redhat/linux/updates/',
+   'mirror.pa.msu.edu/linux/redhat/linux/updates/',
+   'rufus.w3.org/linux/redhat/linux/updates/',
+   'distro.ibiblio.org/pub/linux/distributions/redhat/updates/',
+   'limestone.uoregon.edu/redhat/updates/',
+   'opnsrc.support.compaq.com/linux/redhat/updates.redhat.com/',
+);
+
+my $RHversion = (split /\s/, `cat /etc/redhat-release`)[4]; # - 6.2 or 7.3 or ?
+my $checkcommand='check-rpms -ftp '; # -------- use check-rpms command this way
+
+my $FTPSERVER; # ------------------------- the server portion of the serverpath
+my $FTPUPDATES; # ----------------------------- the actual update root location
+my @rpms; # ---------------------------------- this will store the list of RPMs
+my $goodoutput; # ------------------------------------ good stuff was returned!
+my $reallygoodoutput; # ------------------------------- you are 100% up-to-date
+
+# ----------------------------------------- Find the check-rpms script location
+if (-e './check-rpms') {
+    $commandpre='perl ./';
+}
+elsif (-e 'loncom/build/check-rpms') {
+    $commandpre='perl loncom/build/';
 }
-`ping -q -c 1 rufus.w3.org 2>/dev/null`;
-if (!$FTPSERVER and $?==0) {
-    `ncftpls ftp://rufus.w3.org`;
+else {
+    die("**** ERROR **** CANNOT FIND THE check-rpms SCRIPT\n");
+}
+
+$checkcommand=$commandpre.$checkcommand;
+
+# =============== Go through all the servers until a decent connection is found
+print(<<END);
+THIS SCRIPT IS NOW PROBING SEVERAL FTP SERVERS....
+PLEASE BE PATIENT, THIS MAY TAKE A FEW MINUTES.
+END
+
+SERVERLOOP: foreach my $serverpath (@serverpaths_to_try) {
+    $serverpath=~/^(.*?)\//;
+    $FTPSERVER=$1;
+    print "Trying $FTPSERVER...\n";
+    `ping -q -c 1 $FTPSERVER 2>/dev/null`;
     if ($?==0) {
-	$FTPSERVER="rufus.w3.org";
-	$FTPUPDATES="rufus.w3.org/linux/redhat/updates/$RHversion/en/os";
+	`ncftpls ftp://$FTPSERVER`;
+	if ($?==0) {
+	    $FTPUPDATES="$serverpath$RHversion/en/os";
+	    print "$checkcommand $FTPUPDATES\n";
+	    @rpms=`$checkcommand $FTPUPDATES`;
+	    my $rpmtext=join('',@rpms);
+	    if ($rpmtext=~/This account is currently not/) { # ---------- uh-oh
+		print "...strange error, moving on ($FTPSERVER)\n";
+	    }
+	    else { # ------------------------------------- the output is "good"
+		$goodoutput=$rpmtext;
+		unless (@rpms) {
+		    $reallygoodoutput=<<END;
+**** NOTE **** All RPMS on your system appear to be up to date.
+END
+		}
+		last SERVERLOOP;
+	    }
+	}
+	print "...cannot establish an ftp session with $FTPSERVER\n";
+    }
+    else {
+	print "...cannot find $FTPSERVER on the network\n";
     }
 }
-if (!$FTPSERVER) {
-    print "Cannot find a working ftp server.\n";
+if (!$goodoutput) {
+    print "**** ERROR **** Cannot find a working ftp server.\n";
+    exit(1);
 }
-print "Using $FTPSERVER for ftp transaction...(please be patient)\n";
-my @rpms=`perl loncom/build/check-rpms -ftp $FTPUPDATES`;
-if (@rpms) {
-    my $rpm_count=scalar(@rpms);
+elsif ($reallygoodoutput) {
+    print $reallygoodoutput;
+}
+else {
+    my $rpmcount=scalar(@rpms);
     print(<<END);
-**** WARNING **** You need to update at least $rpm_count RPMS shown in 
+ **** WARNING **** You need to update at least $rpmcount RPMS shown in
 the list below.  THIS IS IMPORTANT FOR SECURITY.
 
 END
-    print join("\n",map {chomp;$_} @rpms)."\n";
+    print $goodoutput;
     print(<<END);
 
 Please visit ftp://$FTPUPDATES
 and download the RPMS you need.
 For instructions on working with (and upgrading) RPMS, please
 visit http://www.rpm.org/max-rpm/.
-END
-}
-else {
-    print(<<END);
-**** NOTE **** All RPMS on your system appear to be up to date.
 END
 }