--- loncom/build/Attic/CHECKRPMS.default 2002/05/01 17:01:18 1.1 +++ loncom/build/Attic/CHECKRPMS.default 2002/09/05 18:09:54 1.5 @@ -1,46 +1,215 @@ #!/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"; - } -} -`ping -q -c 1 rufus.w3.org 2>/dev/null`; -if (!$FTPSERVER and $?==0) { - `ncftpls ftp://rufus.w3.org`; - if ($?==0) { - $FTPSERVER="rufus.w3.org"; - $FTPUPDATES="rufus.w3.org/linux/redhat/updates/$RHversion/en/os"; - } -} -if (!$FTPSERVER) { - print "Cannot find a working ftp server.\n"; -} -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); - print(< - 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 + +# =================================================== READ IN COMMAND ARGUMENTS +# ---------------------------------------------------- Process download option. +my $download=shift(@ARGV); +if ($download eq '--download') + { + if ($< != 0) # Download mode requires 'root'. + { + print('**** ERROR **** Download mode needs to be run as root'."\n"); + exit(1); # Exit with error status. + } + `rm -Rf /tmp/loncapa_rpm_updates`; + $download='-v -dl -d /tmp/loncapa_rpm_updates'; # Part of check-rpms args. + } +else + { + $download=''; + } + +# =================================================== GENERAL INITIAL VARIABLES +# ---------------- The FTP servers (and their directory paths) to check against +my @serverpaths_to_try = + ( + '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/', + ); + +# --------------------------------------------------- Determine RedHat version. +my $RHversion = (split /\s/, `cat /etc/redhat-release`)[4]; # - 6.2 or 7.3 or ? + + # ------------------------------------------- Use check-rpms command this way. +my $checkcommand = 'check-rpms '.$download.' --rpmuser www -ftp'; + +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 ./'; # Use the check-rpms in the current directory. + } +elsif (-e 'loncom/build/check-rpms') + { + $commandpre='perl loncom/build/'; # Use check-rpms int he loncom/build dir. + } +else # Cannot find check-rpms, so abort. + { + die("**** ERROR **** CANNOT FIND THE check-rpms SCRIPT\n"); + } + +# Define the overall check-rpms invocation based on the path to the check-rpms +# command. +$checkcommand = $commandpre.$checkcommand; + +# ============== Go through all the servers until a decent connection is found. +# Notify user of current action. +print(</dev/null`; # Ping ftp server (are you out there?). + if ($?==0) # If the ftp server can be pinged. + { + print "$FTPSERVER found...\n"; # Tell user the ftp server is found. + `ncftpls ftp://$FTPSERVER`; # Try to access server with ftp protocol. + if ($?==0) # If the ftp server can be accessed with the ftp protocol. + { + $FTPUPDATES="$serverpath$RHversion/en/os"; # The full update path. + # Print the check-rpms command that will be executed. + print($checkcommand.' '.$FTPUPDATES."\n"); + if ($download) # Was CHECKRPMS run in download mode? + { + $|=1; # Try to send things immediately to stdout; err umm.... + # Tell the user about the /tmp/loncapa_rpm_updates directory. + print('**** NOTE ****'. + 'To check the status of the download, you can '. + 'periodically inspect the contents of the '. + '/tmp/loncapa_rpm_updates directory. '. + 'Please be patient; this download may take a while.'. + "\n"); + # Do the download. + print(`$checkcommand $FTPUPDATES 2>\&1`); + # Tell the user about what action they need to take with the + # downloaded RPMs. + print('You may now wish to visit the /tmp/loncapa_rpm_updates'. + ' directory and upgrade the RPMs. '."\n". + 'If this is a critical server (it is currently being'. + ' used for classes) and you do not know how to upgrade'. + ' RPMs, you should consult someone who has experience '. + 'with the "rpm" command.'."\n"); + exit(0); # Assume everything is okay and exit. + } + @rpms=`$checkcommand $FTPUPDATES 2>\&1`; # Read in list of RPMs. + # Create a text string that can be pattern matched. + my $rpmtext=join('',@rpms); + if ($rpmtext=~/You do not seem to have a/) # No www? + { + print "You do not have a 'www' user on your system.\n". + "Please add this user and try this command again.\n"; + exit(1); + } + 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) # If there are no RPMs to update. + { + $reallygoodoutput=<