version 1.4, 2006/10/05 17:44:38
|
version 1.10, 2007/12/04 04:43:24
|
Line 39 to LON-CAPA systems. distprobe is used t
|
Line 39 to LON-CAPA systems. distprobe is used t
|
|
|
The utility which is used to complete the check depends on the distro: |
The utility which is used to complete the check depends on the distro: |
|
|
fedora - yum |
fedora, rhel 5/5+, centos, scientific - yum |
suse 9.X and sles9 - you |
suse 9.X and sles9 - you |
suse 10.X and sles10 - rug |
suse 10.2,10.3 - zypper |
|
sles10,suse10.1 - rug |
rhel 4 - up2date |
rhel 4 - up2date |
others - check-rpms |
others - check-rpms |
|
|
Line 54 Must be run as root or www.
|
Line 55 Must be run as root or www.
|
use strict; |
use strict; |
use lib '/home/httpd/lib/perl/'; |
use lib '/home/httpd/lib/perl/'; |
use LONCAPA::Configuration; |
use LONCAPA::Configuration; |
|
use Apache::loncommon(); |
|
|
my $tmpfile = '/tmp/CHECKRPMS.'.$$; |
my $tmpfile = '/tmp/CHECKRPMS.'.$$; |
my $perlvar= LONCAPA::Configuration::read_conf('loncapa.conf'); |
my $perlvar= LONCAPA::Configuration::read_conf('loncapa.conf'); |
|
|
# Determine who we email |
# 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'}; |
my $subj = $perlvar->{'lonHostID'}; |
|
|
# Get Linux distro |
# Get Linux distro |
Line 80 if ($distro =~ /^fedora\d+$/) {
|
Line 85 if ($distro =~ /^fedora\d+$/) {
|
$cmd = 'yum update'; |
$cmd = 'yum update'; |
&prepare_msg($tmpfile,$cmd); |
&prepare_msg($tmpfile,$cmd); |
($send,$addsubj) = &check_with_yum($tmpfile); |
($send,$addsubj) = &check_with_yum($tmpfile); |
} elsif ($distro =~ /^(suse|sles)9\.\d$/) { |
} elsif ($distro =~ /^(suse|sles)9\.?\d?$/) { |
$cmd = 'you'; |
$cmd = 'you'; |
&prepare_msg($tmpfile,$cmd); |
&prepare_msg($tmpfile,$cmd); |
($send,$addsubj) = &check_with_you($tmpfile); |
($send,$addsubj) = &check_with_you($tmpfile); |
} elsif ($distro =~ /^(suse|sles)10\.?\d?$/) { |
} elsif ($distro =~ /^suse10\.(\d)$/) { |
|
my $version =$1; |
|
if ($version > 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'; |
$cmd = 'rug up'; |
&prepare_msg($tmpfile,$cmd); |
&prepare_msg($tmpfile,$cmd); |
($send,$addsubj) = &check_with_rug($tmpfile); |
($send,$addsubj) = &check_with_rug($tmpfile); |
} elsif ($distro =~ /^rhes4$/) { |
} elsif ($distro =~ /^rhes(\d+)$/) { |
$cmd ='up2date -u --nox'; |
my $version = $1; |
|
if ($version == 4) { |
|
$cmd ='up2date -u --nox'; |
|
&prepare_msg($tmpfile,$cmd); |
|
($send,$addsubj) = &check_with_up2date($tmpfile); |
|
} elsif ($version > 4) { |
|
$cmd = 'yum update'; |
|
&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+\.\d$/) { |
|
$cmd = 'yum update'; |
&prepare_msg($tmpfile,$cmd); |
&prepare_msg($tmpfile,$cmd); |
($send,$addsubj) = &check_with_up2date($tmpfile); |
($send,$addsubj) = &check_with_yum($tmpfile); |
} else { |
} else { |
$cmd = '/usr/local/bin/check-rpms --update'; |
$cmd = '/usr/local/bin/check-rpms --update'; |
($send,$addsubj) = &check_with_checkrpms($tmpfile); |
($send,$addsubj) = &check_with_checkrpms($tmpfile); |
} |
} |
if ($send) { |
if ($send) { |
$subj .= $addsubj; |
$subj .= $addsubj; |
system(qq{mail -s '$subj' $emailto < $tmpfile}); |
system(qq{mail -s '$subj' "$emailto" < $tmpfile}); |
} |
} |
|
|
sub prepare_msg { |
sub prepare_msg { |
Line 113 $cmd
|
Line 144 $cmd
|
|
|
to bring it up to date. |
to bring it up to date. |
|
|
This is very important for the security of your server. The table below lists the packages which need to be updated. |
This is very important for the security of your server. The packages which need to be updated are listed below. |
|
|
ENDHEADER |
ENDHEADER |
close(TMPFILE); |
close(TMPFILE); |
Line 126 sub check_with_you {
|
Line 157 sub check_with_you {
|
my $sendflag = 0; |
my $sendflag = 0; |
my $append_to_subj; |
my $append_to_subj; |
|
|
if (open (PIPE, "$you -d -k -l en 2>&1 |")) { |
if (open (PIPE, "$you -k -len 2>&1 |")) { |
my $output=<PIPE>; |
my $output=<PIPE>; |
close(PIPE); |
close(PIPE); |
chomp $output; |
chomp $output; |
unless ($output eq 'No updates available.') { |
unless ($output eq 'No updates available.') { |
my $command = $you.' -s -k -l en |grep ^[^I] >>'.$tmpfile; |
if (open (PIPE, "$you -s -d -len |grep ^INSTALL |")) { |
system($command); |
my @updates = <PIPE>; |
$sendflag = 1; |
close(PIPE); |
$append_to_subj = ' RPMS to upgrade'; |
my $allpackages; |
|
foreach my $line (@updates) { |
|
my $package = substr($line,rindex($line,'/')+1); |
|
if ($package ne '') { |
|
$allpackages .= $package; |
|
} |
|
} |
|
if ($allpackages ne '') { |
|
open(TMPFILE,">>$tmpfile"); |
|
print TMPFILE $allpackages; |
|
close(TMPFILE); |
|
$sendflag = 1; |
|
$append_to_subj = ' RPMS to upgrade'; |
|
} |
|
} else { |
|
$sendflag = 1; |
|
$append_to_subj = ' Error running RPM update script'; |
|
} |
} |
} |
} else { |
} else { |
$sendflag = 1; |
$sendflag = 1; |
Line 239 sub check_with_rug {
|
Line 287 sub check_with_rug {
|
last; |
last; |
} elsif ($line eq 'No updates are available.') { |
} elsif ($line eq 'No updates are available.') { |
last; |
last; |
|
} elsif ($line eq 'Downloading Packages...') { |
|
last; |
} else { |
} else { |
push(@clean_output,$line); |
push(@clean_output,$line); |
} |
} |
Line 253 sub check_with_rug {
|
Line 303 sub check_with_rug {
|
} else { |
} else { |
$append_to_subj = ' Error running RPM update check'; |
$append_to_subj = ' Error running RPM update check'; |
$sendflag = 1; |
$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=<PIPE>; |
|
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); |
return ($sendflag,$append_to_subj); |
} |
} |