system_setup: setup user with wsl.conf

This commit is contained in:
Patrick Wu 2021-10-11 15:10:06 +08:00
parent 7ae8e108a6
commit 271b72b41a
No known key found for this signature in database
GPG Key ID: 9DD33DF28FC324F1
5 changed files with 22 additions and 4 deletions

View File

@ -111,12 +111,13 @@ def default_loader(is_advanced=False):
return data
def wsl_config_update(config_class, root_dir):
def wsl_config_update(config_class, root_dir, default_user=None):
"""
This update the configuration file for the given class.zzd
This update the configuration file for the given class.
:param config_class: WSLConfigurationBase or WSLConfigurationAdvanced
:param is_dry_run: boolean, True if it is a dry run
:param root_dir: string, the root directory of the WSL
:param create_user: string, the user to create
"""
temp_conf_default = {}
temp_confname = config_class.__str__()
@ -162,6 +163,11 @@ def wsl_config_update(config_class, root_dir):
config.add_section(config_section)
config[config_section][config_setting] = config_value
if config_type == "wsl" and default_user is not None:
if "user" not in config:
config.add_section("user")
config["user"]["default"] = default_user
# sort config in ascii order
for section in config._sections:
config._sections[section] = \

View File

@ -69,8 +69,10 @@ class ConfigureController(SubiquityController):
dryrun = self.app.opts.dry_run
variant = self.app.variant
root_dir = self.model.root
username = None
if variant == "wsl_setup":
wsl_id = self.model.identity.user
username = wsl_id.username
if dryrun:
log.debug("mimicking creating user %s",
wsl_id.username)
@ -105,7 +107,8 @@ class ConfigureController(SubiquityController):
wsl_config_update(self.model.wslconfadvanced.wslconfadvanced,
root_dir)
wsl_config_update(self.model.wslconfbase.wslconfbase, root_dir)
wsl_config_update(self.model.wslconfbase.wslconfbase, root_dir,
default_user=username)
self.app.update_state(ApplicationState.DONE)
except Exception:

View File

@ -6,3 +6,6 @@ root = /custom_mnt_path
generatehosts = false
generateresolvconf = false
[user]
default = ubuntu

View File

@ -12,3 +12,6 @@ enabled = false
generatehosts = false
generateresolvconf = false
[user]
default = ubuntu

View File

@ -6,3 +6,6 @@ root = /custom_mnt_path
generatehosts = false
generateresolvconf = false
[user]
default = ubuntu