Annotation of loncom/build/CHECKRPMS, revision 1.1
1.1 ! raeburn 1: #!/usr/bin/perl -w
! 2: #
! 3: # The LearningOnline Network with CAPA
! 4: # Checks status of RPM packages on system.
! 5: #
! 6: # Copyright Michigan State University Board of Trustees
! 7: #
! 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 9: #
! 10: # LON-CAPA is free software; you can redistribute it and/or modify
! 11: # it under the terms of the GNU General Public License as published by
! 12: # the Free Software Foundation; either version 2 of the License, or
! 13: # (at your option) any later version.
! 14: #
! 15: # LON-CAPA is distributed in the hope that it will be useful,
! 16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 18: # GNU General Public License for more details.
! 19: #
! 20: # You should have received a copy of the GNU General Public License
! 21: # along with LON-CAPA; if not, write to the Free Software
! 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 23: #
! 24: # /home/httpd/html/adm/gpl.txt
! 25: #
! 26: # http://www.lon-capa.org/
! 27: #
! 28:
! 29: =pod
! 30:
! 31: =head1 NAME
! 32:
! 33: B<CHECKRPMS> - automated status report about RPMs on a system.
! 34:
! 35: =head1 DESCRIPTION
! 36:
! 37: This file automates the process of checking for available updates
! 38: to LON-CAPA systems. distprobe is used to determine the Linux distribution.
! 39:
! 40: The utility which is used to complete the check depends on the distro:
! 41:
! 42: fedora - yum
! 43: suse 9.X and sles9 - you
! 44: suse 10.X and sles10 - rug
! 45: rhel 4 - up2date
! 46: others - check-rpms
! 47:
! 48: Created by amalgamating previous distribution-specific CHECKRPMS.dist files (where dist was one of: fedora, rhel, suse, sles10, default).
! 49:
! 50: Must be run as root or www.
! 51:
! 52: =cut
! 53:
! 54: use strict;
! 55: use lib '/home/httpd/lib/perl/';
! 56: use LONCAPA::Configuration;
! 57:
! 58: my $tmpfile = '/tmp/CHECKRPMS.'.$$;
! 59: my $perlvar= LONCAPA::Configuration::read_conf('loncapa.conf');
! 60:
! 61: # Determine who we email
! 62: my $emailto = "$perlvar->{'lonAdmEMail'}";
! 63: my $subj = $perlvar->{'lonHostID'};
! 64:
! 65: # Get Linux distro
! 66: open(PIPE, "$perlvar->{'lonDaemons'}/distprobe |");
! 67: my $distro = <PIPE>;
! 68: close(PIPE);
! 69:
! 70: undef($perlvar);
! 71:
! 72: my $hostname = `hostname`;
! 73: chomp($hostname);
! 74: open(TMPFILE,">$tmpfile");
! 75: print TMPFILE localtime(time).' '.$hostname."\n";
! 76: close(TMPFILE);
! 77:
! 78: my ($cmd,$send,$addsubj);
! 79: if ($distro =~ /^fedora\d+$/) {
! 80: $cmd = 'yum update';
! 81: &prepare_msg($tmpfile,$cmd);
! 82: ($send,$addsubj) = &check_with_yum($tmpfile);
! 83: } elsif ($distro =~ /^(suse|sles)9\.\d$/) {
! 84: $cmd = 'you';
! 85: &prepare_msg($tmpfile,$cmd);
! 86: ($send,$addsubj) = &check_with_you($tmpfile);
! 87: } elsif ($distro =~ /^(suse|sles)10\.?\d?$/) {
! 88: $cmd = 'rug up';
! 89: &prepare_msg($tmpfile,$cmd);
! 90: ($send,$addsubj) = &check_with_rug($tmpfile);
! 91: } elsif ($distro =~ /^rhes4$/) {
! 92: $cmd ='up2date -u --nox';
! 93: &prepare_msg($tmpfile,$cmd);
! 94: ($send,$addsubj) = &check_with_up2date($tmpfile);
! 95: } else {
! 96: $cmd = '/usr/local/bin/check-rpms --update';
! 97: ($send,$addsubj) = &check_with_checkrpms($tmpfile);
! 98: }
! 99: if ($send) {
! 100: $subj .= $addsubj;
! 101: system(qq{mail -s '$subj' $emailto < $tmpfile});
! 102: }
! 103:
! 104: sub prepare_msg {
! 105: my ($tmpfile,$cmd) = @_;
! 106: #
! 107: # Put some nice text in $tmpfile
! 108: open(TMPFILE,">>$tmpfile");
! 109: print TMPFILE <<ENDHEADER;
! 110: Your system needs to be updated. Please execute (as root)
! 111:
! 112: $cmd
! 113:
! 114: to bring it up to date.
! 115:
! 116: This is very important for the security of your server. The table below lists the packages which need to be updated.
! 117:
! 118: ENDHEADER
! 119: close(TMPFILE);
! 120: return;
! 121: }
! 122:
! 123: sub check_with_you {
! 124: my ($tmpfile) =@_;
! 125: my $you = '/usr/bin/online_update';
! 126: my $sendflag = 0;
! 127: my $append_to_subj;
! 128:
! 129: if (open (PIPE, "$you -d -k -l en 2>&1 |")) {
! 130: my $output=<PIPE>;
! 131: close(PIPE);
! 132: chomp $output;
! 133: unless ($output eq 'No updates available.') {
! 134: my $command = $you.' -s -k -l en |grep ^[^I] >>'.$tmpfile;
! 135: system($command);
! 136: $sendflag = 1;
! 137: $append_to_subj = ' RPMS to upgrade';
! 138: }
! 139: } else {
! 140: $sendflag = 1;
! 141: $append_to_subj = ' Error running RPM update script';
! 142: }
! 143: return ($sendflag,$append_to_subj);
! 144: }
! 145:
! 146: sub check_with_yum {
! 147: my ($tmpfile) = @_;
! 148: my $yum = '/usr/bin/yum';
! 149: my $sendflag = 0;
! 150: my $append_to_subj;
! 151:
! 152: #
! 153: # Execute yum command
! 154: my $command = $yum.' check-update '.'>>'.$tmpfile;
! 155: system($command);
! 156:
! 157: my $returnvalue = $?>>8;
! 158:
! 159: #
! 160: # Determine status of yum run
! 161: if (100 == $returnvalue) {
! 162: $sendflag = 1;
! 163: $append_to_subj = ' RPMS to upgrade';
! 164: } elsif (0 != $returnvalue) {
! 165: $sendflag = 1;
! 166: $append_to_subj = ' Error running RPM update script';
! 167: } else {
! 168: # yum returned 0, so everything is up to date.
! 169: }
! 170: return ($sendflag,$append_to_subj);
! 171: }
! 172:
! 173: sub check_with_up2date {
! 174: my ($tmpfile) = @_;
! 175: my $up2date = '/usr/bin/up2date-nox';
! 176: my $sendflag = 0;
! 177: my $append_to_subj;
! 178: #
! 179: # Execute online_update command to check for updates
! 180: my $up2date_error = 1;
! 181: if (open (PIPE, "$up2date -l 2>&1 |")) {
! 182: my @result=<PIPE>;
! 183: close(PIPE);
! 184: if (@result > 0) {
! 185: my $output = join('',@result);
! 186: if ($output =~ /Fetching Obsoletes list/) {
! 187: $up2date_error = 0;
! 188: if ($output =~ /Name\s+Version\s+Rel\s+[\n\r\f]+\-+[\n\r\f]+(.+)/s) {
! 189: my $packagelist = $1;
! 190: unless (($packagelist =~ /^The following Packages were marked to be skipped by your configuration:/) || ($packagelist eq '')) {
! 191: open(TMPFILE,">>$tmpfile");
! 192: print TMPFILE $packagelist;
! 193: close(TMPFILE);
! 194: $append_to_subj = ' RPMS to upgrade';
! 195: $sendflag = 1;
! 196: }
! 197: }
! 198: }
! 199: }
! 200: }
! 201: if ($up2date_error) {
! 202: $append_to_subj = ' Error running RPM update script';
! 203: $sendflag = 1;
! 204: }
! 205: return ($sendflag,$append_to_subj);
! 206: }
! 207:
! 208: sub check_with_rug {
! 209: my ($tmpfile) = @_;
! 210: my $rug = '/usr/bin/rug';
! 211: my $sendflag = 0;
! 212: my $append_to_subj;
! 213: #
! 214: # Execute rug command to check for updates
! 215: if (open (PIPE, "$rug up -N 2>&1 |")) {
! 216: my @output=<PIPE>;
! 217: close(PIPE);
! 218: chomp(@output);
! 219: my @clean_output;
! 220: foreach my $line (@output) {
! 221: if ($line eq 'Waking up ZMD...' || $line eq 'Done') {
! 222: next;
! 223: }
! 224: if ($line eq 'No updates are available.') {
! 225: last;
! 226: } else {
! 227: push(@clean_output,$line);
! 228: }
! 229: }
! 230: if (@clean_output > 0) {
! 231: open(TMPFILE,">>$tmpfile");
! 232: print TMPFILE join("\n",@clean_output);
! 233: close(TMPFILE);
! 234: $append_to_subj= ' RPMS to upgrade';
! 235: $sendflag = 1;
! 236: }
! 237: } else {
! 238: $append_to_subj = ' Error running RPM update check';
! 239: $sendflag = 1;
! 240: }
! 241: return ($sendflag,$append_to_subj);
! 242: }
! 243:
! 244: sub check_with_checkrpms {
! 245: my ($tmpfile,$perlvar) = @_;
! 246: my $checkrpms = '/usr/local/bin/check-rpms';
! 247: my $sendflag = 0;
! 248: my $append_to_subj;
! 249:
! 250: # Run Martin Seigert's checkrpms script. See
! 251: # See http://www.sfu.ca/acs/security/linux/check-rpms.html
! 252: # for more information.
! 253:
! 254: #
! 255: # Check that checkrpms is installed and is the proper version...
! 256: if (! -e $checkrpms) {
! 257: open(TMPFILE,">>$tmpfile");
! 258: print TMPFILE <<END;
! 259:
! 260: Unable to locate check-rpms on your system. Please go to
! 261: http://www.sfu.ca/acs/security/linux/check-rpms.html, download and
! 262: install check-rpms on this system.
! 263:
! 264: END
! 265: $append_to_subj = ' Error running RPM update check';
! 266: $sendflag = 1;
! 267: } else {
! 268: #
! 269: # Run check-rpms and capture its output
! 270: if (open (PIPE, "$checkrpms 2>&1 |")) {
! 271: my $output=<PIPE>;
! 272: close(PIPE);
! 273: if ($output ne '') {
! 274: $output = <<"END";
! 275:
! 276: checkrpms checked the status of the packages on your system and
! 277: produced the following output:
! 278: -------------------------------------------------------
! 279: $output
! 280: -------------------------------------------------------
! 281: If there are rpms which need to be installed, please log into
! 282: $perlvar->{'lonHostID'} and run the following command
! 283:
! 284: $checkrpms --update
! 285:
! 286: If there are kernel packages to be installed, use
! 287:
! 288: $checkrpms --update --install-kernel
! 289:
! 290: Keeping your system up to date is very important.
! 291: Ensuring you are using up to date software is a prerequisite for a
! 292: secure system.
! 293:
! 294: END
! 295: open(TMPFILE,">>$tmpfile");
! 296: print TMPFILE $output;
! 297: close(TMPFILE);
! 298: $append_to_subj = ' RPMS to upgrade';
! 299: $sendflag = 1;
! 300: }
! 301: }
! 302: }
! 303: return ($sendflag,$append_to_subj);
! 304: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>