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