--- loncom/build/CHECKRPMS 2007/04/23 20:04:52 1.7 +++ loncom/build/CHECKRPMS 2010/10/04 15:07:17 1.12 @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # # The LearningOnline Network with CAPA # Checks status of RPM packages on system. @@ -30,7 +30,8 @@ =head1 NAME -B - automated status report about RPMs on a system. +B - automated status report about RPMs (RHEL/Fedora/CentOS/SuSE) + or debs (Debian/Ubuntu) on a system. =head1 DESCRIPTION @@ -39,10 +40,12 @@ to LON-CAPA systems. distprobe is used t The utility which is used to complete the check depends on the distro: -fedora, rhel 5/5+ - yum +fedora, rhel 5/5+, centos, scientific - yum suse 9.X and sles9 - you -suse 10.X and sles10 - rug +suse 10.2,10.3,11.1 - zypper +sles10,suse10.1 - rug rhel 4 - up2date +debian, ubuntu - apt-get others - check-rpms Created by amalgamating previous distribution-specific CHECKRPMS.dist files (where dist was one of: fedora, rhel, suse, sles10, default). @@ -54,12 +57,16 @@ Must be run as root or www. use strict; use lib '/home/httpd/lib/perl/'; use LONCAPA::Configuration; +use Apache::loncommon(); my $tmpfile = '/tmp/CHECKRPMS.'.$$; my $perlvar= LONCAPA::Configuration::read_conf('loncapa.conf'); # Determine who we email -my $emailto = "$perlvar->{'lonAdmEMail'}"; +my $defdom = $perlvar->{'lonDefDomain'}; +my $origmail = $perlvar->{'lonAdmEMail'}; +my $emailto = &Apache::loncommon::build_recipient_list(undef, + 'packagesmail',$defdom,$origmail); my $subj = $perlvar->{'lonHostID'}; # Get Linux distro @@ -84,7 +91,19 @@ if ($distro =~ /^fedora\d+$/) { $cmd = 'you'; &prepare_msg($tmpfile,$cmd); ($send,$addsubj) = &check_with_you($tmpfile); -} elsif ($distro =~ /^(suse|sles)10\.?\d?$/) { +} elsif ($distro =~ /^suse(\d{2,})\.(\d+)$/) { + my $version =$1; + my $subversion = $2; + if (($version > 10) || (($version == 10) && ($subversion > 1))) { + $cmd = 'zypper up'; + &prepare_msg($tmpfile,$cmd); + ($send,$addsubj) = &check_with_zypper($tmpfile); + } else { + $cmd = 'rug up'; + &prepare_msg($tmpfile,$cmd); + ($send,$addsubj) = &check_with_rug($tmpfile); + } +} elsif ($distro =~ /^sles10$/) { $cmd = 'rug up'; &prepare_msg($tmpfile,$cmd); ($send,$addsubj) = &check_with_rug($tmpfile); @@ -99,13 +118,25 @@ if ($distro =~ /^fedora\d+$/) { &prepare_msg($tmpfile,$cmd); ($send,$addsubj) = &check_with_yum($tmpfile); } +} elsif ($distro =~ /^centos\d+$/) { + $cmd = 'yum update'; + &prepare_msg($tmpfile,$cmd); + ($send,$addsubj) = &check_with_yum($tmpfile); +} elsif ($distro =~ /^scientific\d+$/) { + $cmd = 'yum update'; + &prepare_msg($tmpfile,$cmd); + ($send,$addsubj) = &check_with_yum($tmpfile); +} elsif ($distro =~ /^(debian|ubuntu)\d+/) { + $cmd = 'apt-get upgrade'; + &prepare_msg($tmpfile,$cmd); + ($send,$addsubj) = &check_with_apt($tmpfile); } else { $cmd = '/usr/local/bin/check-rpms --update'; ($send,$addsubj) = &check_with_checkrpms($tmpfile); } if ($send) { $subj .= $addsubj; - system(qq{mail -s '$subj' $emailto < $tmpfile}); + system(qq{mail -s '$subj' "$emailto" < $tmpfile}); } sub prepare_msg { @@ -281,6 +312,100 @@ sub check_with_rug { $sendflag = 1; } return ($sendflag,$append_to_subj); +} + +sub check_with_zypper { + my ($tmpfile) = @_; + my $zypper = '/usr/bin/zypper'; + my $sendflag = 0; + my $append_to_subj; + my $header; + # + # Execute zypper command to check for updates + if (open (PIPE, "$zypper lu 2>&1 |")) { + my @output=; + close(PIPE); + chomp(@output); + my @clean_output; + foreach my $line (@output) { + if ($line eq 'Restoring system sources...') { + next; + } elsif ($line =~ /^Parsing\smetadata\sfor\s/) { + next; + } elsif ($line eq 'Parsing RPM database...') { + next; + } elsif ($line =~ /^Catalog\s+\|\s+Name\s+\|\s+Version\s+\|\s+Category\s+\|\s+Status$/) { + $header = $line."\n"; + next; + } elsif ($line =~ /^[-+]+$/) { + $header .= $line."\n"; + next; + } elsif ($line eq 'WARNING: These are only the updates affecting the updater itself.') { + next; + } elsif ($line eq 'There are others available too.') { + next; + } else { + push(@clean_output,$line); + } + } + if (@clean_output > 0) { + open(TMPFILE,">>$tmpfile"); + my $message = join("\n",@clean_output); + print TMPFILE $header.$message; + close(TMPFILE); + $append_to_subj= ' RPMS to upgrade'; + $sendflag = 1; + } + } else { + $append_to_subj = ' Error running RPM update check'; + $sendflag = 1; + } + return ($sendflag,$append_to_subj); +} + +sub check_with_apt { + my ($tmpfile) = @_; + my $apt = '/usr/bin/apt-get'; + my $sendflag = 0; + my $append_to_subj; + my $header; + my @chg_package; + # + # Execute apt-get command to update distributions + system ("$apt update > /dev/null"); + my $returnvalue = $?>>8; + if ($returnvalue == 0) { + # Execute apt-get commands to check for upgrades + if (open (PIPE, "$apt -y --dry-run upgrade 2>&1 |")) { + my @output=; + close(PIPE); + chomp(@output); + foreach my $line (@output) { + $line =~ s/^\s+//; + my @items = split(/\s+/,$line); + if ($items[0] eq "Inst") { + push(@chg_package,$items[1]); + } + } + if (@chg_package > 0) { + $header = 'apt-get upgrade found the following packages need updating:'. + "\n\n"; + open(TMPFILE,">>$tmpfile"); + my $message = join("\n",@output); + print TMPFILE $header.$message; + close(TMPFILE); + $append_to_subj= ' deb packages to upgrade'; + $sendflag = 1; + } + } else { + $append_to_subj = ' Error running deb upgrade check'; + $sendflag = 1; + } + } else { + $append_to_subj = ' Error running deb update check'; + $sendflag = 1; + } + return ($sendflag,$append_to_subj); } sub check_with_checkrpms { 500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.