Skip to content

Commit

Permalink
Copy input-sources from DConf to installed system
Browse files Browse the repository at this point in the history
Right now, a users input source configuration gets set up in the live
environment and then gets lost.

This commit adds some code to put it in the installed system in
a system dconf database so that new users will pick it up.
  • Loading branch information
halfline committed Aug 29, 2023
1 parent 25d6f97 commit 5aab899
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
56 changes: 55 additions & 1 deletion pyanaconda/modules/payloads/payload/live_image/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
import stat
import requests
import shutil
import subprocess
import blivet.util

from pyanaconda.anaconda_loggers import get_module_logger
from pyanaconda.core.constants import NETWORK_CONNECTION_TIMEOUT
from pyanaconda.core.i18n import _
from pyanaconda.core.util import execWithRedirect, requests_session
from pyanaconda.core.util import execWithRedirect, startProgram, requests_session
from pyanaconda.core.path import join_paths
from pyanaconda.core.string import lower_ascii
from pyanaconda.modules.common.structures.live_image import LiveImageConfigurationData
Expand Down Expand Up @@ -504,3 +505,56 @@ def run(self):
log.debug(f"Copying {path} to {destination_path}")
if os.path.exists(path):
shutil.copy2(path, destination_path)

class CopyTransientDConfInputSourcesTask(Task):
"""Task to copy transient input source dconf data from live user to installed system"""

def __init__(self, sysroot):
"""Create a new task."""
super().__init__()
self._sysroot = sysroot
self._paths = ['/org/gnome/desktop/input-sources/']
self._uid = int(os.environ.get('PKEXEC_UID') or 0)
self._dconf_dump_file = "/etc/dconf/db/distro.d/10-installer"

@property
def name(self):
"""Name of the task."""
return "Export live user DConf input source config to installed system"""

def run(self):
"""Run the task."""
destination_path = os.path.join(self._sysroot, self._dconf_dump_file.lstrip('/'))
destination_dir = os.path.dirname(destination_path)
os.makedirs(destination_dir, exist_ok=True)

output_lines = []
for path in self._paths:
log.debug(f"Exporting DConf settings from uid {self._uid} under {path}")
process = startProgram(["dconf", "dump", path], stderr=subprocess.PIPE, env_prune=["USER", "LOGNAME", "HOME"], user=self._uid)
stdout, stderr = process.communicate()

if process.returncode != 0:
log.debug(f"dconf dump {path} failed: {stderr.decode('utf-8')}")
continue

lines = stdout.decode('utf-8').split('\n')

# The group is relative to the path passed, so ends up always
# being [/]. rewrite it to [org/gnome/desktop/input-sources] or
# whatever
if len(lines) > 1:
lines[0] = f"[{path.lstrip('/').rstrip('/')}]"
output_lines += lines

if len(output_lines) > 1:
log.debug(f"Writing exported settings to {destination_path}")
with open(destination_path, 'w') as file:
file.write('\n'.join(output_lines))
log.debug(f"Running dconf update on installed system")
process = startProgram(["dconf", "update"], stderr=subprocess.PIPE, root=self._sysroot)

stdout, stderr = process.communicate()

if process.returncode != 0:
log.debug(f"dconf update failed: {stderr.decode('utf-8')}")
6 changes: 5 additions & 1 deletion pyanaconda/modules/payloads/payload/live_os/live_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pyanaconda.core.configuration.anaconda import conf
from pyanaconda.modules.common.errors.payload import IncompatibleSourceError
from pyanaconda.modules.payloads.constants import SourceType, PayloadType
from pyanaconda.modules.payloads.payload.live_image.installation import InstallFromImageTask, CopyTransientGnomeInitialSetupState
from pyanaconda.modules.payloads.payload.live_image.installation import InstallFromImageTask, CopyTransientGnomeInitialSetupState, CopyTransientDConfInputSourcesTask
from pyanaconda.modules.payloads.payload.live_os.utils import get_kernel_version_list
from pyanaconda.modules.payloads.payload.payload_base import PayloadBase
from pyanaconda.modules.payloads.payload.live_os.live_os_interface import LiveOSInterface
Expand Down Expand Up @@ -83,6 +83,10 @@ def install_with_tasks(self):
sysroot=conf.target.system_root,
)]

tasks += [CopyTransientDConfInputSourcesTask(
sysroot=conf.target.system_root,
)]

return tasks

def _update_kernel_version_list(self, image_source):
Expand Down

0 comments on commit 5aab899

Please sign in to comment.