Annotation of loncom/build/CHECKRPMS.default, revision 1.5
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:
1.4 harris41 53: # =================================================== READ IN COMMAND ARGUMENTS
54: # ---------------------------------------------------- Process download option.
55: my $download=shift(@ARGV);
56: if ($download eq '--download')
57: {
58: if ($< != 0) # Download mode requires 'root'.
59: {
60: print('**** ERROR **** Download mode needs to be run as root'."\n");
61: exit(1); # Exit with error status.
62: }
63: `rm -Rf /tmp/loncapa_rpm_updates`;
64: $download='-v -dl -d /tmp/loncapa_rpm_updates'; # Part of check-rpms args.
65: }
66: else
67: {
68: $download='';
69: }
70:
1.2 harris41 71: # =================================================== GENERAL INITIAL VARIABLES
72: # ---------------- The FTP servers (and their directory paths) to check against
1.5 ! harris41 73: my @serverpaths_to_try =
! 74: (
! 75: 'mirror.pa.msu.edu/linux/redhat/linux/updates/',
! 76: 'rufus.w3.org/linux/redhat/linux/updates/',
! 77: 'distro.ibiblio.org/pub/linux/distributions/redhat/updates/',
! 78: 'limestone.uoregon.edu/redhat/updates/',
! 79: 'opnsrc.support.compaq.com/linux/redhat/updates.redhat.com/',
! 80: );
1.2 harris41 81:
1.4 harris41 82: # --------------------------------------------------- Determine RedHat version.
1.2 harris41 83: my $RHversion = (split /\s/, `cat /etc/redhat-release`)[4]; # - 6.2 or 7.3 or ?
1.4 harris41 84:
85: # ------------------------------------------- Use check-rpms command this way.
1.5 ! harris41 86: my $checkcommand = 'check-rpms '.$download.' --rpmuser www -ftp';
1.2 harris41 87:
88: my $FTPSERVER; # ------------------------- the server portion of the serverpath
89: my $FTPUPDATES; # ----------------------------- the actual update root location
90: my @rpms; # ---------------------------------- this will store the list of RPMs
91: my $goodoutput; # ------------------------------------ good stuff was returned!
92: my $reallygoodoutput; # ------------------------------- you are 100% up-to-date
93:
94: # ----------------------------------------- Find the check-rpms script location
1.5 ! harris41 95: if (-e './check-rpms')
! 96: {
! 97: $commandpre='perl ./'; # Use the check-rpms in the current directory.
! 98: }
! 99: elsif (-e 'loncom/build/check-rpms')
! 100: {
! 101: $commandpre='perl loncom/build/'; # Use check-rpms int he loncom/build dir.
! 102: }
! 103: else # Cannot find check-rpms, so abort.
! 104: {
1.2 harris41 105: die("**** ERROR **** CANNOT FIND THE check-rpms SCRIPT\n");
1.5 ! harris41 106: }
1.2 harris41 107:
1.5 ! harris41 108: # Define the overall check-rpms invocation based on the path to the check-rpms
! 109: # command.
! 110: $checkcommand = $commandpre.$checkcommand;
1.2 harris41 111:
1.5 ! harris41 112: # ============== Go through all the servers until a decent connection is found.
! 113: # Notify user of current action.
1.2 harris41 114: print(<<END);
115: THIS SCRIPT IS NOW PROBING SEVERAL FTP SERVERS....
116: PLEASE BE PATIENT, THIS MAY TAKE A FEW MINUTES.
117: END
118:
1.5 ! harris41 119: SERVERLOOP: foreach my $serverpath (@serverpaths_to_try)
! 120: {
! 121: $serverpath=~/^(.*?)\//; # Pattern match the ip name.
! 122: $FTPSERVER=$1; # Set to the ip name.
! 123: print "Trying $FTPSERVER...\n"; # Notify user of attempts with the ip name.
! 124: `ping -c 1 $FTPSERVER 2>/dev/null`; # Ping ftp server (are you out there?).
! 125: if ($?==0) # If the ftp server can be pinged.
! 126: {
! 127: print "$FTPSERVER found...\n"; # Tell user the ftp server is found.
! 128: `ncftpls ftp://$FTPSERVER`; # Try to access server with ftp protocol.
! 129: if ($?==0) # If the ftp server can be accessed with the ftp protocol.
! 130: {
! 131: $FTPUPDATES="$serverpath$RHversion/en/os"; # The full update path.
! 132: # Print the check-rpms command that will be executed.
! 133: print($checkcommand.' '.$FTPUPDATES."\n");
! 134: if ($download) # Was CHECKRPMS run in download mode?
! 135: {
! 136: $|=1; # Try to send things immediately to stdout; err umm....
! 137: # Tell the user about the /tmp/loncapa_rpm_updates directory.
! 138: print('**** NOTE ****'.
! 139: 'To check the status of the download, you can '.
! 140: 'periodically inspect the contents of the '.
! 141: '/tmp/loncapa_rpm_updates directory. '.
! 142: 'Please be patient; this download may take a while.'.
! 143: "\n");
! 144: # Do the download.
! 145: print(`$checkcommand $FTPUPDATES 2>\&1`);
! 146: # Tell the user about what action they need to take with the
! 147: # downloaded RPMs.
! 148: print('You may now wish to visit the /tmp/loncapa_rpm_updates'.
! 149: ' directory and upgrade the RPMs. '."\n".
! 150: 'If this is a critical server (it is currently being'.
! 151: ' used for classes) and you do not know how to upgrade'.
! 152: ' RPMs, you should consult someone who has experience '.
! 153: 'with the "rpm" command.'."\n");
! 154: exit(0); # Assume everything is okay and exit.
! 155: }
! 156: @rpms=`$checkcommand $FTPUPDATES 2>\&1`; # Read in list of RPMs.
! 157: # Create a text string that can be pattern matched.
1.2 harris41 158: my $rpmtext=join('',@rpms);
1.5 ! harris41 159: if ($rpmtext=~/You do not seem to have a/) # No www?
! 160: {
1.4 harris41 161: print "You do not have a 'www' user on your system.\n".
162: "Please add this user and try this command again.\n";
163: exit(1);
1.5 ! harris41 164: }
! 165: if ($rpmtext=~/This account is currently not/) # ------------ uh-oh
! 166: {
1.2 harris41 167: print "...strange error, moving on ($FTPSERVER)\n";
1.5 ! harris41 168: }
! 169: else # --------------------------------------- the output is "good"
! 170: {
1.2 harris41 171: $goodoutput=$rpmtext;
1.5 ! harris41 172: unless (@rpms) # If there are no RPMs to update.
! 173: {
1.2 harris41 174: $reallygoodoutput=<<END;
175: **** NOTE **** All RPMS on your system appear to be up to date.
176: END
1.5 ! harris41 177: }
1.2 harris41 178: last SERVERLOOP;
1.5 ! harris41 179: }
! 180: }
! 181: print('...cannot establish an ftp session with '.$FTPSERVER."\n");
! 182: }
! 183: else
! 184: {
1.2 harris41 185: print "...cannot find $FTPSERVER on the network\n";
1.5 ! harris41 186: }
! 187: }
! 188: if (!$goodoutput) # If never received any useable output, assume "no server".
! 189: {
1.2 harris41 190: print "**** ERROR **** Cannot find a working ftp server.\n";
191: exit(1);
1.5 ! harris41 192: }
! 193: elsif ($reallygoodoutput) # Everything is peachy keen and up-to-date already.
! 194: {
1.2 harris41 195: print $reallygoodoutput;
1.5 ! harris41 196: }
! 197: else # There are RPMs that need to be updated; show list to user.
! 198: {
! 199: my $rpmcount=scalar(@rpms); # Count up size of RPM list.
! 200: print(<<END); # Print out an advisory warning to user.
1.4 harris41 201: **** WARNING **** You need to update at least $rpmcount RPMS shown in
1.1 harris41 202: the list below. THIS IS IMPORTANT FOR SECURITY.
203:
204: END
1.5 ! harris41 205: print $goodoutput; # Output the RPM list.
! 206: print(<<END); # Output instructions to user about taking action.
1.1 harris41 207:
208: Please visit ftp://$FTPUPDATES
209: and download the RPMS you need.
210: For instructions on working with (and upgrading) RPMS, please
211: visit http://www.rpm.org/max-rpm/.
1.4 harris41 212: To automatically download these RPMs to /tmp/loncapa_rpm_updates/,
213: run the CHECKRPMS command as "./CHECKRPMS --download"
1.1 harris41 214: END
1.5 ! harris41 215: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>