Annotation of loncom/build/CHECKRPMS.default, revision 1.4
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
73: my @serverpaths_to_try=(
74: 'mirror.pa.msu.edu/linux/redhat/linux/updates/',
75: 'rufus.w3.org/linux/redhat/linux/updates/',
76: 'distro.ibiblio.org/pub/linux/distributions/redhat/updates/',
77: 'limestone.uoregon.edu/redhat/updates/',
78: 'opnsrc.support.compaq.com/linux/redhat/updates.redhat.com/',
79: );
80:
1.4 ! harris41 81: # --------------------------------------------------- Determine RedHat version.
1.2 harris41 82: my $RHversion = (split /\s/, `cat /etc/redhat-release`)[4]; # - 6.2 or 7.3 or ?
1.4 ! harris41 83:
! 84: # ------------------------------------------- Use check-rpms command this way.
! 85: my $checkcommand='check-rpms '.$download.' --rpmuser www -ftp';
1.2 harris41 86:
87: my $FTPSERVER; # ------------------------- the server portion of the serverpath
88: my $FTPUPDATES; # ----------------------------- the actual update root location
89: my @rpms; # ---------------------------------- this will store the list of RPMs
90: my $goodoutput; # ------------------------------------ good stuff was returned!
91: my $reallygoodoutput; # ------------------------------- you are 100% up-to-date
92:
93: # ----------------------------------------- Find the check-rpms script location
94: if (-e './check-rpms') {
95: $commandpre='perl ./';
96: }
97: elsif (-e 'loncom/build/check-rpms') {
98: $commandpre='perl loncom/build/';
99: }
100: else {
101: die("**** ERROR **** CANNOT FIND THE check-rpms SCRIPT\n");
102: }
103:
104: $checkcommand=$commandpre.$checkcommand;
105:
106: # =============== Go through all the servers until a decent connection is found
107: print(<<END);
108: THIS SCRIPT IS NOW PROBING SEVERAL FTP SERVERS....
109: PLEASE BE PATIENT, THIS MAY TAKE A FEW MINUTES.
110: END
111:
112: SERVERLOOP: foreach my $serverpath (@serverpaths_to_try) {
113: $serverpath=~/^(.*?)\//;
114: $FTPSERVER=$1;
115: print "Trying $FTPSERVER...\n";
1.4 ! harris41 116: `ping -c 1 $FTPSERVER 2>/dev/null`;
1.1 harris41 117: if ($?==0) {
1.4 ! harris41 118: print "$FTPSERVER found...\n";
1.2 harris41 119: `ncftpls ftp://$FTPSERVER`;
120: if ($?==0) {
121: $FTPUPDATES="$serverpath$RHversion/en/os";
122: print "$checkcommand $FTPUPDATES\n";
1.4 ! harris41 123: if ($download) {
! 124: $|=1;
! 125: print `$checkcommand $FTPUPDATES 2>\&1`;
! 126: exit(0);
! 127: }
! 128: @rpms=`$checkcommand $FTPUPDATES 2>\&1`;
1.2 harris41 129: my $rpmtext=join('',@rpms);
1.4 ! harris41 130: if ($rpmtext=~/You do not seem to have a/) {
! 131: print "You do not have a 'www' user on your system.\n".
! 132: "Please add this user and try this command again.\n";
! 133: exit(1);
! 134: }
1.2 harris41 135: if ($rpmtext=~/This account is currently not/) { # ---------- uh-oh
136: print "...strange error, moving on ($FTPSERVER)\n";
137: }
138: else { # ------------------------------------- the output is "good"
139: $goodoutput=$rpmtext;
140: unless (@rpms) {
141: $reallygoodoutput=<<END;
142: **** NOTE **** All RPMS on your system appear to be up to date.
143: END
144: }
145: last SERVERLOOP;
146: }
147: }
148: print "...cannot establish an ftp session with $FTPSERVER\n";
149: }
150: else {
151: print "...cannot find $FTPSERVER on the network\n";
1.1 harris41 152: }
153: }
1.2 harris41 154: if (!$goodoutput) {
155: print "**** ERROR **** Cannot find a working ftp server.\n";
156: exit(1);
1.1 harris41 157: }
1.2 harris41 158: elsif ($reallygoodoutput) {
159: print $reallygoodoutput;
1.1 harris41 160: }
1.2 harris41 161: else {
162: my $rpmcount=scalar(@rpms);
1.1 harris41 163: print(<<END);
1.4 ! harris41 164: **** WARNING **** You need to update at least $rpmcount RPMS shown in
1.1 harris41 165: the list below. THIS IS IMPORTANT FOR SECURITY.
166:
167: END
1.2 harris41 168: print $goodoutput;
1.1 harris41 169: print(<<END);
170:
171: Please visit ftp://$FTPUPDATES
172: and download the RPMS you need.
173: For instructions on working with (and upgrading) RPMS, please
174: visit http://www.rpm.org/max-rpm/.
1.4 ! harris41 175: To automatically download these RPMs to /tmp/loncapa_rpm_updates/,
! 176: run the CHECKRPMS command as "./CHECKRPMS --download"
1.1 harris41 177: END
178: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>