--- loncom/build/CHECKRPMS 2011/05/13 00:21:45 1.13 +++ loncom/build/CHECKRPMS 2019/07/06 19:20:36 1.18 @@ -3,7 +3,7 @@ # The LearningOnline Network with CAPA # Checks status of RPM packages on system. # -# $Id: CHECKRPMS,v 1.13 2011/05/13 00:21:45 raeburn Exp $ +# $Id: CHECKRPMS,v 1.18 2019/07/06 19:20:36 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,7 +42,8 @@ to LON-CAPA systems. distprobe is used t The utility which is used to complete the check depends on the distro: -fedora, rhel >= 5, centos, scientific - yum +fedora, rhel >= 5, centos, scientific, oracle linux - yum +fedora >= 22 - dnf suse 9.X and sles9 - you suse 10.2,10.3,11.1,11.2,11.3,11.4,sles11 - zypper sles10,suse10.1 - rug @@ -63,6 +64,7 @@ use Apache::loncommon(); my $tmpfile = '/tmp/CHECKRPMS.'.$$; my $perlvar= LONCAPA::Configuration::read_conf('loncapa.conf'); +my $docroot = $perlvar->{'lonDocRoot'}; # Determine who we email my $defdom = $perlvar->{'lonDefDomain'}; @@ -84,11 +86,24 @@ open(TMPFILE,">$tmpfile"); print TMPFILE localtime(time).' '.$hostname."\n"; close(TMPFILE); +if ($docroot ne '') { + if (-e "$docroot/lon-status/checkrpms.txt") { + unlink("$docroot/lon-status/checkrpms.txt"); + } +} + my ($cmd,$send,$addsubj); -if ($distro =~ /^fedora\d+$/) { - $cmd = 'yum update'; - &prepare_msg($tmpfile,$cmd); - ($send,$addsubj) = &check_with_yum($tmpfile); +if ($distro =~ /^fedora(\d+)$/) { + my $version =$1; + if ($version > 21) { + $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?$/) { $cmd = 'you'; &prepare_msg($tmpfile,$cmd); @@ -124,11 +139,7 @@ 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+$/) { +} elsif ($distro =~ /^(centos|scientific|oracle)\d+$/) { $cmd = 'yum update'; &prepare_msg($tmpfile,$cmd); ($send,$addsubj) = &check_with_yum($tmpfile); @@ -142,6 +153,13 @@ if ($distro =~ /^fedora\d+$/) { } if ($send) { $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}); } @@ -230,6 +248,33 @@ sub check_with_yum { } 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 { my ($tmpfile) = @_;