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 19, 2023
1 parent 5870438 commit a20c80d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 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 CopyTransientDConfDataTask(Task):
"""Task to copy transient dconf data from live user to installed system"""

def __init__(self, sysroot, paths):
"""Create a new task."""
super().__init__()
self._sysroot = sysroot
self._paths = paths
self._uid = int(os.environ.get('PKEXEC_UID'))
self._dconf_dump_file = "/etc/dconf/db/distro.d/10-installer"

@property
def name(self):
"""Name of the task."""
return "Export live user DConf 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')}")
10 changes: 8 additions & 2 deletions 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, CopyTransientLiveDataTask
from pyanaconda.modules.payloads.payload.live_image.installation import InstallFromImageTask, CopyTransientLiveDataTask, CopyTransientDConfDataTask
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 @@ -81,7 +81,13 @@ def install_with_tasks(self):

tasks += [CopyTransientLiveDataTask(
sysroot=conf.target.system_root,
paths=['/var/lib/gnome-initial-setup/state']
paths=['/var/lib/gnome-initial-setup/state',
'/etc/locale.conf']
)]

tasks += [CopyTransientDConfDataTask(
sysroot=conf.target.system_root,
paths=['/org/gnome/desktop/input-sources/']
)]

return tasks
Expand Down

0 comments on commit a20c80d

Please sign in to comment.