--- loncom/build/Attic/CHECKRPMS.default 2002/09/05 17:36:39 1.4 +++ loncom/build/Attic/CHECKRPMS.default 2004/09/01 16:28:26 1.19 @@ -1,178 +1,107 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w +# +# The LearningOnline Network with CAPA +# +# $Id: CHECKRPMS.default,v 1.19 2004/09/01 16:28:26 matthew Exp $ +# +# Copyright Michigan State University Board of Trustees +# +# This file is part of the LearningOnline Network with CAPA (LON-CAPA). +# +# LON-CAPA is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LON-CAPA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LON-CAPA; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# /home/httpd/html/adm/gpl.txt +# +# http://www.lon-capa.org/ +# +# (Navigate problems for statistical reports +# =pod =head1 NAME -B - automated status report about RPMs on a system - -=head1 SYNOPSIS - -./CHECKRPMS - -or - -perl CHECKRPMS +B - automated status report about RPMs on a system. =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 +Runs Martin Seigert's checkrpms script. See +http://www.sfu.ca/acs/security/linux/check-rpms.html for more information. -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 +Must be run as root or www. =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 ./'; -} -elsif (-e 'loncom/build/check-rpms') { - $commandpre='perl loncom/build/'; -} -else { - die("**** ERROR **** CANNOT FIND THE check-rpms SCRIPT\n"); -} - -$checkcommand=$commandpre.$checkcommand; +use strict; +use lib '/home/httpd/lib/perl/'; +use LONCAPA::Configuration; +# +# Determine who we email +my %perlvar=%{LONCAPA::Configuration::read_conf('loncapa.conf')}; +my $emailto = "$perlvar{'lonAdmEMail'}"; +my $subj=$perlvar{'lonHostID'}.' rpm status'; + +my $checkrpms = '/usr/local/bin/check-rpms'; +# +# Check that checkrpms is installed and is the proper version... +my $mailmsg = ''; +if (! -e $checkrpms) { + $mailmsg = </dev/null`; - if ($?==0) { - print "$FTPSERVER found...\n"; - `ncftpls ftp://$FTPSERVER`; - if ($?==0) { - $FTPUPDATES="$serverpath$RHversion/en/os"; - print "$checkcommand $FTPUPDATES\n"; - if ($download) { - $|=1; - print `$checkcommand $FTPUPDATES 2>\&1`; - exit(0); - } - @rpms=`$checkcommand $FTPUPDATES 2>\&1`; - my $rpmtext=join('',@rpms); - if ($rpmtext=~/You do not seem to have a/) { - 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) { - $reallygoodoutput=<$mail_file") || die("Unable to write to ".$mail_file); + print MAILFILE $mailmsg.$/; + close(MAILFILE); + my $mailcommand = "mail -s '$subj' $emailto <$mail_file"; + print STDERR $mailcommand; + system($mailcommand); } + +exit;