[LON-CAPA-cvs] cvs: loncom /build CHECKRPMS

raeburn raeburn at source.lon-capa.org
Wed Oct 23 16:34:39 EDT 2019


raeburn		Wed Oct 23 20:34:39 2019 EDT

  Modified files:              
    /loncom/build	CHECKRPMS 
  Log:
  - Combine routines for yum and dnf to eliminate duplicate code.
  - Update documentation
  
  
Index: loncom/build/CHECKRPMS
diff -u loncom/build/CHECKRPMS:1.18 loncom/build/CHECKRPMS:1.19
--- loncom/build/CHECKRPMS:1.18	Sat Jul  6 19:20:36 2019
+++ loncom/build/CHECKRPMS	Wed Oct 23 20:34:39 2019
@@ -3,7 +3,7 @@
 # The LearningOnline Network with CAPA
 # Checks status of RPM packages on system.
 #
-# $Id: CHECKRPMS,v 1.18 2019/07/06 19:20:36 raeburn Exp $
+# $Id: CHECKRPMS,v 1.19 2019/10/23 20:34:39 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -32,7 +32,7 @@
 
 =head1 NAME
 
-B<CHECKRPMS> - automated status report about RPMs (RHEL/Fedora/CentOS/SuSE) 
+B<CHECKRPMS> - automated status report about RPMs (RHEL/Fedora/CentOS/Oracle Linux/SuSE/SLES) 
                or debs (Debian/Ubuntu) on a system. 
 
 =head1 DESCRIPTION
@@ -42,11 +42,12 @@
 
 The utility which is used to complete the check depends on the distro:
 
-fedora, rhel >= 5, centos, scientific, oracle linux - yum
+fedora < 22; rhel (5, 6, 7); centos/scientific/oracle linux <=7 - yum
 fedora >= 22 - dnf
+rhel/centos/oracle linux >= 8 - 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
+suse 10.2, 10.3, 11.X and 12.X; sles (>= 11) - zypper
+sles10, suse10.1 - rug
 rhel 4 - up2date
 debian, ubuntu - apt-get
 others - check-rpms
@@ -98,11 +99,11 @@
     if ($version > 21) {
         $cmd = 'dnf update';
         &prepare_msg($tmpfile,$cmd);
-        ($send,$addsubj) = &check_with_dnf($tmpfile);
+        ($send,$addsubj) = &check_with_yum_or_dnf($tmpfile,'dnf');
     } else {
         $cmd = 'yum update';
         &prepare_msg($tmpfile,$cmd);
-        ($send,$addsubj) = &check_with_yum($tmpfile);
+        ($send,$addsubj) = &check_with_yum_or_dnf($tmpfile,'yum');
     }
 } elsif ($distro =~ /^(suse|sles)9\.?\d?$/) {
     $cmd = 'you';
@@ -134,15 +135,26 @@
         $cmd ='up2date -u --nox';
         &prepare_msg($tmpfile,$cmd);
         ($send,$addsubj) = &check_with_up2date($tmpfile);
-    } elsif ($version > 4) {
+    } elsif ($version <= 7) {
         $cmd = 'yum update';
         &prepare_msg($tmpfile,$cmd);
-        ($send,$addsubj) = &check_with_yum($tmpfile);
+        ($send,$addsubj) = &check_with_yum_or_dnf($tmpfile,'yum');
+    } else {
+        $cmd = 'dnf update';
+        &prepare_msg($tmpfile,$cmd);
+        ($send,$addsubj) = &check_with_yum_or_dnf($tmpfile,'dnf');
+    }
+} elsif ($distro =~ /^(?:centos|scientific|oracle)(\d+)$/) {
+    my $version = $1;
+    if ($version <= 7) {
+        $cmd = 'yum update';
+        &prepare_msg($tmpfile,$cmd);
+        ($send,$addsubj) = &check_with_yum_or_dnf($tmpfile,'yum');
+    } else {
+        $cmd = 'dnf update';
+        &prepare_msg($tmpfile,$cmd);
+        ($send,$addsubj) = &check_with_yum_or_dnf($tmpfile,'dnf');
     }
-} elsif ($distro =~ /^(centos|scientific|oracle)\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);
@@ -222,48 +234,26 @@
     return ($sendflag,$append_to_subj);
 }
 
-sub check_with_yum {
-    my ($tmpfile) = @_;
-    my $yum = '/usr/bin/yum';
-    my $sendflag = 0;
-    my $append_to_subj;
-
-    #
-    # Execute yum command
-    my $command = $yum.' check-update '.'>>'.$tmpfile;
-    system($command);
-
-    my $returnvalue = $?>>8;
-
-    #
-    # Determine status of yum 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';
+sub check_with_yum_or_dnf {
+    my ($tmpfile,$progname) = @_;
+    my $path_to_exec = '/usr/bin/';
+    if ($progname eq 'dnf') {
+        $path_to_exec .= $progname;
     } else {
-        # yum returned 0, so everything is up to date.
+        $path_to_exec .= '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;
+    # Execute command
+    my $command = $path_to_exec.' check-update '.'>>'.$tmpfile;
     system($command);
 
     my $returnvalue = $?>>8;
 
     #
-    # Determine status of dnf run
+    # Determine status of yum or dnf run
     if (100 == $returnvalue) {
         $sendflag = 1;
         $append_to_subj = ' RPMS to upgrade';
@@ -271,7 +261,7 @@
         $sendflag = 1;
         $append_to_subj = ' Error running RPM update script';
     } else {
-        # dnf returned 0, so everything is up to date.
+        # yum or dnf returned 0, so everything is up to date.
     }
     return ($sendflag,$append_to_subj);
 }




More information about the LON-CAPA-cvs mailing list