version 1.11, 2009/07/14 14:36:06
|
version 1.17, 2017/04/09 14:54:02
|
Line 3
|
Line 3
|
# The LearningOnline Network with CAPA |
# The LearningOnline Network with CAPA |
# Checks status of RPM packages on system. |
# Checks status of RPM packages on system. |
# |
# |
|
# $Id$ |
|
# |
# Copyright Michigan State University Board of Trustees |
# Copyright Michigan State University Board of Trustees |
# |
# |
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
Line 40 to LON-CAPA systems. distprobe is used t
|
Line 42 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, rhel 5/5+, centos, scientific - yum |
fedora, rhel >= 5, centos, scientific - yum |
|
fedora >= 22 - dnf |
suse 9.X and sles9 - you |
suse 9.X and sles9 - you |
suse 10.2,10.3,11.1 - zypper |
suse 10.2,10.3,11.1,11.2,11.3,11.4,sles11 - zypper |
sles10,suse10.1 - rug |
sles10,suse10.1 - rug |
rhel 4 - up2date |
rhel 4 - up2date |
debian, ubuntu - apt-get |
debian, ubuntu - apt-get |
Line 61 use Apache::loncommon();
|
Line 64 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'); |
|
my $docroot = $perlvar->{'lonDocRoot'}; |
|
|
# Determine who we email |
# Determine who we email |
my $defdom = $perlvar->{'lonDefDomain'}; |
my $defdom = $perlvar->{'lonDefDomain'}; |
Line 82 open(TMPFILE,">$tmpfile");
|
Line 86 open(TMPFILE,">$tmpfile");
|
print TMPFILE localtime(time).' '.$hostname."\n"; |
print TMPFILE localtime(time).' '.$hostname."\n"; |
close(TMPFILE); |
close(TMPFILE); |
|
|
|
if ($docroot ne '') { |
|
if (-e "$docroot/lon-status/checkrpms.txt") { |
|
unlink("$docroot/lon-status/checkrpms.txt"); |
|
} |
|
} |
|
|
my ($cmd,$send,$addsubj); |
my ($cmd,$send,$addsubj); |
if ($distro =~ /^fedora\d+$/) { |
if ($distro =~ /^fedora(\d+)$/) { |
$cmd = 'yum update'; |
my $version =$1; |
&prepare_msg($tmpfile,$cmd); |
if ($version > 21) { |
($send,$addsubj) = &check_with_yum($tmpfile); |
$cmd = 'dnf update'; |
|
&prepare_msg($tmpfile,$cmd); |
|
($send,$addsubj) = &check_with_dnf($tmpfile); |
|
} else { |
|
$cmd = 'yum update'; |
|
&prepare_msg($tmpfile,$cmd); |
|
($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); |
Line 107 if ($distro =~ /^fedora\d+$/) {
|
Line 124 if ($distro =~ /^fedora\d+$/) {
|
$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 =~ /^sles(\d+)$/) { |
|
$cmd = 'zypper up'; |
|
&prepare_msg($tmpfile,$cmd); |
|
($send,$addsubj) = &check_with_zypper($tmpfile); |
} elsif ($distro =~ /^rhes(\d+)$/) { |
} elsif ($distro =~ /^rhes(\d+)$/) { |
my $version = $1; |
my $version = $1; |
if ($version == 4) { |
if ($version == 4) { |
Line 122 if ($distro =~ /^fedora\d+$/) {
|
Line 143 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 =~ /^scientific\d+\.\d$/) { |
} elsif ($distro =~ /^scientific\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); |
Line 136 if ($distro =~ /^fedora\d+$/) {
|
Line 157 if ($distro =~ /^fedora\d+$/) {
|
} |
} |
if ($send) { |
if ($send) { |
$subj .= $addsubj; |
$subj .= $addsubj; |
|
if ($docroot ne '') { |
|
system("cat $tmpfile > $docroot/lon-status/checkrpms.txt"); |
|
if ($< == 0) { |
|
system("chown www:www $docroot/lon-status/checkrpms.txt"); |
|
} |
|
chmod(0600,"$docroot/lon-status/checkrpms.txt"); |
|
} |
system(qq{mail -s '$subj' "$emailto" < $tmpfile}); |
system(qq{mail -s '$subj' "$emailto" < $tmpfile}); |
} |
} |
|
|
Line 224 sub check_with_yum {
|
Line 252 sub check_with_yum {
|
} |
} |
return ($sendflag,$append_to_subj); |
return ($sendflag,$append_to_subj); |
} |
} |
|
|
|
sub check_with_dnf { |
|
my ($tmpfile) = @_; |
|
my $dnf = '/usr/bin/dnf'; |
|
my $sendflag = 0; |
|
my $append_to_subj; |
|
|
|
# |
|
# Execute dnf command |
|
my $command = $dnf.' check-update '.'>>'.$tmpfile; |
|
system($command); |
|
|
|
my $returnvalue = $?>>8; |
|
|
|
# |
|
# Determine status of dnf run |
|
if (100 == $returnvalue) { |
|
$sendflag = 1; |
|
$append_to_subj = ' RPMS to upgrade'; |
|
} elsif (0 != $returnvalue) { |
|
$sendflag = 1; |
|
$append_to_subj = ' Error running RPM update script'; |
|
} else { |
|
# dnf returned 0, so everything is up to date. |
|
} |
|
return ($sendflag,$append_to_subj); |
|
} |
|
|
sub check_with_up2date { |
sub check_with_up2date { |
my ($tmpfile) = @_; |
my ($tmpfile) = @_; |