From de1c2cfa75cb399553ecd925e230c11c3b879f71 Mon Sep 17 00:00:00 2001
From: Ben Morrice <ben.morrice@cern.ch>
Date: Thu, 18 Mar 2021 15:16:00 +0100
Subject: [PATCH] use dnf-automatic on 8 family systems

---
 cern-anaconda-addon.spec           |  5 +++-
 src/cern_customizations/ks/cern.py | 43 ++++++++++++++++++------------
 2 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/cern-anaconda-addon.spec b/cern-anaconda-addon.spec
index 0a54041..d26f3a4 100644
--- a/cern-anaconda-addon.spec
+++ b/cern-anaconda-addon.spec
@@ -1,5 +1,5 @@
 Name:       cern-anaconda-addon
-Version:    1.7
+Version:    1.8
 Release:    1%{?dist}
 Summary:    CERN configuration anaconda addon
 
@@ -31,6 +31,9 @@ install -p -m 644 data/cern.svg %{buildroot}/%{_datadir}/icons/hicolor/scalable/
 %doc LICENSE README.md
 
 %changelog
+* Thu Mar 18 2021 Ben Morrice <ben.morrice@cern.ch> - 1.8-1
+- Use dnf-automatic instead of yum-autoupdate on 8 family systems
+
 * Tue Jan 28 2020 Ben Morrice <ben.morrice@cern.ch> - 1.7-1
 - Add support for C8
 
diff --git a/src/cern_customizations/ks/cern.py b/src/cern_customizations/ks/cern.py
index 249e5c6..cd7b325 100644
--- a/src/cern_customizations/ks/cern.py
+++ b/src/cern_customizations/ks/cern.py
@@ -238,31 +238,40 @@ class CernData(AddonData):
             except NoOptionError:
                 print("Unexpected error:", sys.exc_info()[0])
 
+        # we will need this for later
+        release=open('/etc/redhat-release','r').read().split(' ')[3].split('.')[0]
+
         # Configure yum-autoupdate
         if self.autoupdate:
-            yumautoupdate_installed=os.path.isfile('/usr/sbin/yum-autoupdate')
-            if yumautoupdate_installed == False:
-                # 'yum' will work for both 7 and 8
-                subprocess.check_call(["yum", "-y", "install", "yum-autoupdate"])
-            subprocess.check_call([SYSTEMCTL_BIN, "enable", "yum-autoupdate"])
-            try:
-                with open(yumupdate_file, "a") as fobj:
-                    fobj.write("\n# initial-setup [cern-anaconda-cern] values\n")
-                    fobj.write("YUMUPDATE=%d\n" % int(self.autoupdate))
-                    fobj.write("YUMONBOOT=%d\n" % int(self.autoupdateboot))
-                    fobj.close()
-            except IOError:
-                print("I/O Error couldn't write %s" % (yumupdate_file))
-            except:
-                print("Unexpected error:", sys.exc_info()[0])
+            if release == '8':
+                # install dnf-automatic instead of custom yum-autoupdate
+                subprocess.check_call(["dnf", "-y", "install", "dnf-automatic"])
+                subprocess.check_call([SYSTEMCTL_BIN, "enable", "--now", "dnf-automatic-install.timer"])
+            else:
+                yumautoupdate_installed=os.path.isfile('/usr/sbin/yum-autoupdate')
+                if yumautoupdate_installed == False:
+                    subprocess.check_call(["yum", "-y", "install", "yum-autoupdate"])
+                subprocess.check_call([SYSTEMCTL_BIN, "enable", "yum-autoupdate"])
+                try:
+                    with open(yumupdate_file, "a") as fobj:
+                        fobj.write("\n# initial-setup [cern-anaconda-cern] values\n")
+                        fobj.write("YUMUPDATE=%d\n" % int(self.autoupdate))
+                        fobj.write("YUMONBOOT=%d\n" % int(self.autoupdateboot))
+                        fobj.close()
+                except IOError:
+                    print("I/O Error couldn't write %s" % (yumupdate_file))
+                except:
+                    print("Unexpected error:", sys.exc_info()[0])
         else:
             # we use call rather than check_call as we don't care if this fails
             # due to yumautoupdate not being installed
-            subprocess.call([SYSTEMCTL_BIN, "disable", "yum-autoupdate"])
+            if release == '8':
+                subprocess.call([SYSTEMCTL_BIN, "disable", "yum-autoupdate"])
+            else:
+                subprocess.call([SYSTEMCTL_BIN, "disable", "dnf-automatic-install.timer"])
 
         # locmap may not be installed - force install if it's not
         locmap_installed=os.path.isfile('/usr/bin/locmap')
-        release=open('/etc/redhat-release','r').read().split(' ')[3].split('.')[0]
         if locmap_installed == False:
             # locmap does not reside in CERN repo on 8, install locmap-release
             if release == '8':
-- 
GitLab