Annotation of loncom/build/CHECKRPMS.default, revision 1.3

1.1       harris41    1: #!/usr/bin/perl
                      2: 
1.2       harris41    3: =pod
                      4: 
                      5: =head1 NAME
                      6: 
                      7: B<CHECKRPMS> - automated status report about RPMs on a system
                      8: 
                      9: =head1 SYNOPSIS
                     10: 
                     11: ./CHECKRPMS
                     12: 
                     13: or
                     14: 
                     15: perl CHECKRPMS
                     16: 
                     17: =head1 DESCRIPTION
                     18: 
                     19: This file automates the usage of Martin Siegert's "check-rpms"
                     20: script.  It runs through a list of possible mirror sites
                     21: until it finds one with a reasonably good FTP connection.
                     22: 
                     23: =head2 Future directions
                     24: 
                     25: Eventually, this script may have a simple argument format
                     26: that allows the user to VIEW, DOWNLOAD, or AUTOUPDATE their
                     27: computer.  Or, this script may evolve into an interactive
                     28: series of steps:  For example, there may be questions like this:
                     29: 
                     30: =over 4
                     31: 
                     32: =item *
                     33: 
                     34: Do you want to (D)ownload or (A)utoupdate the RPMs
                     35: in the list above?
                     36: 
                     37: =item *
                     38: 
                     39: Specify a download location for the RPMs
                     40: (default=/tmp/update_my_rpms/)?
                     41: 
                     42: =back
                     43: 
                     44: Note that there are no current plans to automate a software upgrade of the
                     45: kernel.  This step should be performed by a qualified system administrator.
                     46: 
                     47: =head1 AUTHOR
                     48: 
                     49: Scott Harrison, sharrison@users.sourceforge.net, 2002
                     50: 
                     51: =cut
                     52: 
                     53: # =================================================== GENERAL INITIAL VARIABLES
                     54: # ---------------- The FTP servers (and their directory paths) to check against
                     55: my @serverpaths_to_try=(
                     56:    'mirror.pa.msu.edu/linux/redhat/linux/updates/',
                     57:    'rufus.w3.org/linux/redhat/linux/updates/',
                     58:    'distro.ibiblio.org/pub/linux/distributions/redhat/updates/',
                     59:    'limestone.uoregon.edu/redhat/updates/',
                     60:    'opnsrc.support.compaq.com/linux/redhat/updates.redhat.com/',
                     61: );
                     62: 
                     63: my $RHversion = (split /\s/, `cat /etc/redhat-release`)[4]; # - 6.2 or 7.3 or ?
                     64: my $checkcommand='check-rpms -ftp '; # -------- use check-rpms command this way
                     65: 
                     66: my $FTPSERVER; # ------------------------- the server portion of the serverpath
                     67: my $FTPUPDATES; # ----------------------------- the actual update root location
                     68: my @rpms; # ---------------------------------- this will store the list of RPMs
                     69: my $goodoutput; # ------------------------------------ good stuff was returned!
                     70: my $reallygoodoutput; # ------------------------------- you are 100% up-to-date
                     71: 
                     72: # ----------------------------------------- Find the check-rpms script location
                     73: if (-e './check-rpms') {
                     74:     $commandpre='perl ./';
                     75: }
                     76: elsif (-e 'loncom/build/check-rpms') {
                     77:     $commandpre='perl loncom/build/';
                     78: }
                     79: else {
                     80:     die("**** ERROR **** CANNOT FIND THE check-rpms SCRIPT\n");
                     81: }
                     82: 
                     83: $checkcommand=$commandpre.$checkcommand;
                     84: 
                     85: # =============== Go through all the servers until a decent connection is found
                     86: print(<<END);
                     87: THIS SCRIPT IS NOW PROBING SEVERAL FTP SERVERS....
                     88: PLEASE BE PATIENT, THIS MAY TAKE A FEW MINUTES.
                     89: END
                     90: 
                     91: SERVERLOOP: foreach my $serverpath (@serverpaths_to_try) {
                     92:     $serverpath=~/^(.*?)\//;
                     93:     $FTPSERVER=$1;
                     94:     print "Trying $FTPSERVER...\n";
                     95:     `ping -q -c 1 $FTPSERVER 2>/dev/null`;
1.1       harris41   96:     if ($?==0) {
1.2       harris41   97: 	`ncftpls ftp://$FTPSERVER`;
                     98: 	if ($?==0) {
                     99: 	    $FTPUPDATES="$serverpath$RHversion/en/os";
                    100: 	    print "$checkcommand $FTPUPDATES\n";
                    101: 	    @rpms=`$checkcommand $FTPUPDATES`;
                    102: 	    my $rpmtext=join('',@rpms);
                    103: 	    if ($rpmtext=~/This account is currently not/) { # ---------- uh-oh
                    104: 		print "...strange error, moving on ($FTPSERVER)\n";
                    105: 	    }
                    106: 	    else { # ------------------------------------- the output is "good"
                    107: 		$goodoutput=$rpmtext;
                    108: 		unless (@rpms) {
                    109: 		    $reallygoodoutput=<<END;
                    110: **** NOTE **** All RPMS on your system appear to be up to date.
                    111: END
                    112: 		}
                    113: 		last SERVERLOOP;
                    114: 	    }
                    115: 	}
                    116: 	print "...cannot establish an ftp session with $FTPSERVER\n";
                    117:     }
                    118:     else {
                    119: 	print "...cannot find $FTPSERVER on the network\n";
1.1       harris41  120:     }
                    121: }
1.2       harris41  122: if (!$goodoutput) {
                    123:     print "**** ERROR **** Cannot find a working ftp server.\n";
                    124:     exit(1);
1.1       harris41  125: }
1.2       harris41  126: elsif ($reallygoodoutput) {
                    127:     print $reallygoodoutput;
1.1       harris41  128: }
1.2       harris41  129: else {
                    130:     my $rpmcount=scalar(@rpms);
1.1       harris41  131:     print(<<END);
1.2       harris41  132:  **** WARNING **** You need to update at least $rpmcount RPMS shown in
1.1       harris41  133: the list below.  THIS IS IMPORTANT FOR SECURITY.
                    134: 
                    135: END
1.2       harris41  136:     print $goodoutput;
1.1       harris41  137:     print(<<END);
                    138: 
                    139: Please visit ftp://$FTPUPDATES
                    140: and download the RPMS you need.
                    141: For instructions on working with (and upgrading) RPMS, please
                    142: visit http://www.rpm.org/max-rpm/.
                    143: END
                    144: }

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