Annotation of loncom/misc/checkforupdates.pl, revision 1.1
1.1 ! raeburn 1: #!/usr/bin/perl
! 2: # The LearningOnline Network
! 3: #
! 4: # $Id: checkforupdates.pl,v 1.1 2013/01/31 21:20:25 raeburn Exp $
! 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:
! 30: =pod
! 31:
! 32: =head1 NAME
! 33:
! 34: checkforupdates.pl
! 35:
! 36: =head1 SYNOPSIS
! 37:
! 38: checkforupdates.pl gathers version numbers and computes checksums
! 39: for LON-CAPA modules, scripts, and a couple of configuration files,
! 40: and compares them with those expected for the version of LON-CAPA
! 41: installed on the server.
! 42:
! 43: =head1 DESCRIPTION
! 44:
! 45: If there are discrepancies in checksums between the installed modules
! 46: and those expected, or if there are problems performing the update check,
! 47: or if a newer stable release of LON-CAPA is available, an e-mail will be
! 48: sent to the e-mail address configured to receive these types of alert.
! 49:
! 50: Run as www.
! 51:
! 52: =cut
! 53:
! 54: #################################################
! 55:
! 56: use strict;
! 57: use lib '/home/httpd/lib/perl/';
! 58: use Apache::lonnet();
! 59: use Apache::lonlocal();
! 60: use LONCAPA::Configuration;
! 61: use LONCAPA::Checksumming;
! 62: use Apache::loncommon();
! 63:
! 64: my $tmpfile = '/tmp/checkLONCAPA.'.$$;
! 65: my $perlvar= LONCAPA::Configuration::read_conf('loncapa.conf');
! 66:
! 67: my ($londaemons,$lonlib,$lonincludes,$lontabdir,$lonhost,$defdom,$origmail,
! 68: $docroot);
! 69: if (ref($perlvar) eq 'HASH') {
! 70: $londaemons = $perlvar->{'lonDaemons'};
! 71: $lonlib = $perlvar->{'lonLib'};
! 72: $lonincludes = $perlvar->{'lonIncludes'};
! 73: $lontabdir = $perlvar->{'lonTabDir'};
! 74: $lonhost = $perlvar->{'lonHostID'};
! 75: $defdom = $perlvar->{'lonDefDomain'};
! 76: $origmail = $perlvar->{'lonAdmEMail'};
! 77: $docroot = $perlvar->{'lonDocRoot'};
! 78: }
! 79: undef($perlvar);
! 80:
! 81: &Apache::lonlocal::get_language_handle();
! 82:
! 83: my ($distro,$send,$message);
! 84:
! 85: my $loncaparev = &Apache::lonnet::get_server_loncaparev($defdom);
! 86: my ($version,$timestamp) = split(/\-/,$loncaparev);
! 87: if ($loncaparev =~ /CVS_HEAD/) {
! 88: $message = &Apache::lonlocal::mt('Code checking unavailable for LON-CAPA CVS HEAD.')."\n";
! 89: } else {
! 90: # Get Linux distro
! 91: if (open(PIPE, "$londaemons/distprobe |")) {
! 92: $distro = <PIPE>;
! 93: close(PIPE);
! 94: }
! 95:
! 96: if ($distro) {
! 97: my ($serversums,$serverversions) =
! 98: &LONCAPA::Checksumming::get_checksums($distro,$londaemons,$lonlib,
! 99: $lonincludes,$lontabdir);
! 100: if ((ref($serversums) eq 'HASH') && (ref($serverversions) eq 'HASH')) {
! 101: if (keys(%{$serversums}) > 0) {
! 102: my ($result,$numchg) =
! 103: &LONCAPA::Checksumming::compare_checksums('mail',$lonhost,
! 104: $version,
! 105: $serversums,
! 106: $serverversions);
! 107: if ($numchg) {
! 108: $send = 1;
! 109: }
! 110: $message = $result;
! 111: } else {
! 112: $message = &Apache::lonlocal::mt('No comparison attempted - failed to retrieve checksums for installed files.');
! 113: }
! 114: } else {
! 115: $message = &Apache::lonlocal::mt('No comparison attempted - failed to retrieve checksums for installed files.');
! 116: }
! 117: } else {
! 118: $message = &Apache::lonlocal::mt('No comparison attempted - unable to determine Linux distribution.');
! 119: }
! 120:
! 121: my ($update_toprod,$update_totest);
! 122: my ($smajor,$sminor,$sdecimal,$smodifier) =
! 123: ($version =~ /^(\d+)\.(\d+)\.(\d+)\.?(\w*)$/);
! 124: my ($production,$proddate,$testing,$testdate) = &latest_release();
! 125: my ($pmajor,$pminor,$pdecimal,$pmodifier) =
! 126: ($production =~ /^(\d+)\.(\d+)\.(\d+)\.?(\w*)$/);
! 127: if ($smodifier =~ /^RC(\d+)$/) {
! 128: my $scand = $1;
! 129: my ($tmajor,$tminor,$tdecimal,$tmodifier) =
! 130: ($testing =~ /^(\d+)\.(\d+)\.(\d+)\.?(\w*)$/);
! 131: my $tcand;
! 132: if ($tmodifier =~ /^RC(\d+)$/) {
! 133: $tcand = $1;
! 134: }
! 135: if (($smajor < $tmajor ) ||
! 136: (($smajor == $tmajor) && ($sminor < $tminor)) ||
! 137: (($smajor == $tmajor) && ($sminor == $tminor) &&
! 138: ($sdecimal < $tdecimal)) ||
! 139: ((($smajor == $tmajor) && ($sminor == $tminor) &&
! 140: ($sdecimal == $tdecimal) &&
! 141: (($scand && $tcand) && ($scand < $tcand))))) {
! 142: $update_totest = $testing;
! 143: }
! 144: }
! 145: if (($smajor < $pmajor ) ||
! 146: (($smajor == $pmajor) && ($sminor < $pminor)) ||
! 147: (($smajor == $pmajor) && ($sminor == $pminor) &&
! 148: ($sdecimal < $pdecimal))) {
! 149: $update_toprod = $production;
! 150: }
! 151: if ($update_totest) {
! 152: $message .=
! 153: "\n\n".
! 154: &Apache::lonlocal::mt('A newer testing version of LON-CAPA: [_1]'.
! 155: ' is available from: [_2]',
! 156: $testing.'-'.$testdate,
! 157: "\n http://install.loncapa.org/\n");
! 158: }
! 159: if ($update_toprod) {
! 160: $message .=
! 161: "\n\n".
! 162: &Apache::lonlocal::mt('A newer version of LON-CAPA: [_1]'.
! 163: ' is available from: [_2]',
! 164: $production.'-'.$proddate,
! 165: "\n http://install.loncapa.org/\n");
! 166: }
! 167: if (open(my $tmpfh,">$tmpfile")) {
! 168: print $tmpfh
! 169: &Apache::lonlocal::mt('Update check result -- [_1]',
! 170: &Apache::lonlocal::locallocaltime(time)).
! 171: "\n\n".
! 172: $message;
! 173: close($tmpfh);
! 174: }
! 175: }
! 176:
! 177: if ($docroot ne '') {
! 178: system("cat $tmpfile > $docroot/lon-status/checkLCupdates.txt");
! 179: if ($< == 0) {
! 180: system("chown www:www $docroot/lon-status/checkLCupdates.txt");
! 181: }
! 182: chmod(0600,"$docroot/lon-status/checkLCupdates.txt");
! 183: }
! 184:
! 185: # Determine who receives the e-mail
! 186: my $emailto =
! 187: &Apache::loncommon::build_recipient_list(undef,'updatesmail',
! 188: $defdom,$origmail);
! 189: if ($emailto) {
! 190: if ($send) {
! 191: my $subj = "LON-CAPA module check -- $lonhost";
! 192: system(qq{mail -s '$subj' "$emailto" < $tmpfile});
! 193: }
! 194: }
! 195:
! 196: exit;
! 197:
! 198: sub latest_release {
! 199: my ($production,$proddate,$testing,$testdate);
! 200: if (-e "/tmp/latestLCrelease.txt") {
! 201: unlink("/tmp/latestLCrelease.txt");
! 202: }
! 203: my $rtncode = system("wget -O /tmp/latestLCrelease.txt ".
! 204: "http://install.loncapa.org/versions/latest.txt ".
! 205: "> /dev/null 2>&1");
! 206: if (!$rtncode) {
! 207: if (open(my $fh,"</tmp/latestLCrelease.txt")) {
! 208: my @info = <$fh>;
! 209: close($fh);
! 210: foreach my $line (@info) {
! 211: chomp($line);
! 212: if ($line =~ /^\QLATEST-IS: \E([\w\-.]+):\d+$/) {
! 213: $production = $1;
! 214: } elsif ($line =~ /^\QLASTRELPROD: \E(\d+)$/) {
! 215: $proddate = $1;
! 216: } elsif ($line =~ /^\QLATEST-TESTING-IS: \E([\w\-.]+):\d+$/) {
! 217: $testing = $1;
! 218: } elsif ($line =~ /^\QLASTRELTEST: \E(\d+)$/) {
! 219: $testdate = $1;
! 220: }
! 221: }
! 222: }
! 223: }
! 224: return ($production,$proddate,$testing,$testdate);
! 225: }
! 226:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>