zengxyz / rpms / anaconda

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