zengxyz / rpms / anaconda

Forked from rpms/anaconda 3 months ago
Clone
225e24
diff -uNrp anaconda-21.48.22.121.orig/pyanaconda/packaging/rpmostreepayload.py anaconda-21.48.22.121/pyanaconda/packaging/rpmostreepayload.py
225e24
--- anaconda-21.48.22.121.orig/pyanaconda/packaging/rpmostreepayload.py	2017-06-21 12:44:34.000000000 +0000
225e24
+++ anaconda-21.48.22.121/pyanaconda/packaging/rpmostreepayload.py	2017-08-23 02:28:23.121006339 +0000
225e24
@@ -142,24 +142,25 @@ class RPMOSTreePayload(ArchivePayload):
225e24
             ["admin", "--sysroot=" + iutil.getTargetPhysicalRoot(),
225e24
              "init-fs", iutil.getTargetPhysicalRoot()])
225e24
 
225e24
-        repo_arg = "--repo=" + iutil.getTargetPhysicalRoot() + '/ostree/repo'
225e24
+        self._sysroot_path = Gio.File.new_for_path(iutil.getTargetPhysicalRoot())
225e24
+        sysroot = OSTree.Sysroot.new(self._sysroot_path)
225e24
+        sysroot.load(cancellable)
225e24
+        repo = sysroot.get_repo(None)[1]
225e24
+        # We don't support resuming from interrupted installs
225e24
+        repo.set_disable_fsync(True)
225e24
+
225e24
+        self._remoteOptions = {}
225e24
 
225e24
-        # Store this for use in postInstall too, where we need to
225e24
-        # undo/redo this step.
225e24
-        self._base_remote_args = ["remote", "add"]
225e24
+        # Handle variations in pykickstart
225e24
         if ((hasattr(ostreesetup, 'noGpg') and ostreesetup.noGpg) or
225e24
             (hasattr(ostreesetup, 'nogpg') and ostreesetup.nogpg)):
225e24
-            self._base_remote_args.append("--set=gpg-verify=false")
225e24
-        self._base_remote_args.extend([ostreesetup.remote,
225e24
-                                     ostreesetup.url])
225e24
-        self._safeExecWithRedirect("ostree", [repo_arg] + self._base_remote_args)
225e24
+            self._remoteOptions['gpg-verify'] = GLib.Variant('b', False)
225e24
 
225e24
-        self._sysroot_path = sysroot_path = Gio.File.new_for_path(iutil.getTargetPhysicalRoot())
225e24
-        sysroot = OSTree.Sysroot.new(sysroot_path)
225e24
-        sysroot.load(cancellable)
225e24
+        repo.remote_change(None, OSTree.RepoRemoteChange.ADD_IF_NOT_EXISTS,
225e24
+                           ostreesetup.remote, ostreesetup.url,
225e24
+                           GLib.Variant('a{sv}', self._remoteOptions),
225e24
+                           cancellable)
225e24
 
225e24
-        repo = sysroot.get_repo(None)[1]
225e24
-        repo.set_disable_fsync(True)
225e24
         progressQ.send_message(_("Starting pull of %(branchName)s from %(source)s") % \
225e24
                                {"branchName": ostreesetup.ref, "source": ostreesetup.remote})
225e24
 
225e24
@@ -178,6 +179,14 @@ class RPMOSTreePayload(ArchivePayload):
225e24
 
225e24
         progressQ.send_message(_("Preparing deployment of %s") % (ostreesetup.ref, ))
225e24
 
225e24
+        # Now that we have the data pulled, delete the remote for now.
225e24
+        # This will allow a remote configuration defined in the tree
225e24
+        # (if any) to override what's in the kickstart.  Otherwise,
225e24
+        # we'll re-add it in post.  Ideally, ostree would support a
225e24
+        # pull without adding a remote, but that would get quite
225e24
+        # complex.
225e24
+        repo.remote_delete(self.data.ostreesetup.remote, None)
225e24
+
225e24
         self._safeExecWithRedirect("ostree",
225e24
             ["admin", "--sysroot=" + iutil.getTargetPhysicalRoot(),
225e24
              "os-init", ostreesetup.osname])
225e24
@@ -257,20 +266,30 @@ class RPMOSTreePayload(ArchivePayload):
225e24
         from gi.repository import OSTree
225e24
         cancellable = None
225e24
 
225e24
-        # Reload this data - we couldn't keep it open across
225e24
-        # the remounts happening.
225e24
         sysroot = OSTree.Sysroot.new(self._sysroot_path)
225e24
         sysroot.load(cancellable)
225e24
         repo = sysroot.get_repo(None)[1]
225e24
 
225e24
-        # This is an ugly hack - we didn't have /etc/ostree/remotes.d,
225e24
-        # so the remote went into /ostree/repo/config.  But we want it
225e24
-        # in /etc, so delete that remote, then re-add it to
225e24
-        # /etc/ostree/remotes.d, executing ostree inside the sysroot
225e24
-        # so that it understands it's a "system repository" and should
225e24
-        # modify /etc.
225e24
-        repo.remote_delete(self.data.ostreesetup.remote, None)
225e24
-        self._safeExecWithRedirect("ostree", self._base_remote_args, root=iutil.getSysroot())
225e24
+        # CentOS specific patch (for now) - pull the remote config from usr/etc if it exists.
225e24
+        # The OSTree handling here was buggy in that it wasn't looking in the sysroot
225e24
+        # for existing remotes.
225e24
+        default_remote_path = iutil.getSysroot() + '/usr/etc/ostree/remotes.d/' + self.data.ostreesetup.osname + '.conf'
225e24
+        if os.path.isfile(default_remote_path):
225e24
+            destpath = iutil.getSysroot() + '/etc/ostree/remotes.d/' + os.path.basename(default_remote_path)
225e24
+            self._safeExecWithRedirect('cp', ['-r', '-p', default_remote_path, destpath])
225e24
+        else:
225e24
+            # Following up on the "remote delete" above, we removed the
225e24
+            # remote from /ostree/repo/config.  But we want it in /etc, so
225e24
+            # re-add it to /etc/ostree/remotes.d, using the sysroot path.
225e24
+            #
225e24
+            # However, we ignore the case where the remote already exists,
225e24
+            # which occurs when the content itself provides the remote
225e24
+            # config file.
225e24
+            repo.remote_change(Gio.File.new_for_path(iutil.getSysroot()),
225e24
+                               OSTree.RepoRemoteChange.ADD_IF_NOT_EXISTS,
225e24
+                               self.data.ostreesetup.remote, self.data.ostreesetup.url,
225e24
+                               GLib.Variant('a{sv}', self._remoteOptions),
225e24
+                               cancellable)
225e24
 
225e24
         boot = iutil.getSysroot() + '/boot'
225e24