Cleanup complete.

- No user setup in wsl.conf
- Shutdown controller creates the launcher-command file
This commit is contained in:
Carlos Nihelton 2021-12-14 12:07:40 -03:00
parent bad945f5d7
commit b17c3d3db9
3 changed files with 33 additions and 18 deletions

View File

@ -111,7 +111,7 @@ def default_loader(is_advanced=False):
return data return data
def wsl_config_update(config_class, root_dir, default_user=None): def wsl_config_update(config_class, root_dir):
""" """
This update the configuration file for the given class. This update the configuration file for the given class.
@ -163,11 +163,6 @@ def wsl_config_update(config_class, root_dir, default_user=None):
config.add_section(config_section) config.add_section(config_section)
config[config_section][config_setting] = config_value 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 # sort config in ascii order
for section in config._sections: for section in config._sections:
config._sections[section] = \ config._sections[section] = \

View File

@ -32,6 +32,7 @@ log = logging.getLogger("system_setup.server.controllers.configure")
class ConfigureController(SubiquityController): class ConfigureController(SubiquityController):
default_uid = 0
def __init__(self, app): def __init__(self, app):
super().__init__(app) super().__init__(app)
@ -343,6 +344,16 @@ class ConfigureController(SubiquityController):
raise Exception("Failed to create user %s: %s" raise Exception("Failed to create user %s: %s"
% (username, create_user_proc.stderr)) % (username, create_user_proc.stderr))
log.debug("created user %s", username) log.debug("created user %s", username)
with open(os.path.join(etc_dir, "passwd")) as f:
for line in f:
if username not in line:
continue
uid = int(line.split(":")[2])
if uid == 0:
log.error("Could not retrieve UID from %s", username)
self.default_uid = uid
assign_grp_proc = await arun_command(assign_grp_cmd) assign_grp_proc = await arun_command(assign_grp_cmd)
if assign_grp_proc.returncode != 0: if assign_grp_proc.returncode != 0:
@ -361,8 +372,7 @@ class ConfigureController(SubiquityController):
wsl_config_update(self.model.wslconfadvanced.wslconfadvanced, wsl_config_update(self.model.wslconfadvanced.wslconfadvanced,
root_dir) 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) self.app.update_state(ApplicationState.DONE)
@ -375,3 +385,7 @@ class ConfigureController(SubiquityController):
def stop_uu(self): def stop_uu(self):
# This is a no-op to allow Shutdown controller to depend on this one # This is a no-op to allow Shutdown controller to depend on this one
pass pass
# Allows passing the recently created user UID to the Shutdown controller.
def get_default_uid(self):
return self.default_uid

View File

@ -50,18 +50,24 @@ class SetupShutdownController(ShutdownController):
@with_context(description='mode={self.mode.name}') @with_context(description='mode={self.mode.name}')
def shutdown(self, context): def shutdown(self, context):
self.shuttingdown_event.set() self.shuttingdown_event.set()
launcher_status = "complete" comments = ["# This file was auto generated by subiquity server.",
"# Don't edit it. It will be overwritten at next run."]
launcher_status = []
if self.mode == ShutdownMode.REBOOT: if self.mode == ShutdownMode.REBOOT:
log.debug("rebooting") log.debug("Setting launcher for reboot")
launcher_status = "reboot" launcher_status += ["action=reboot"]
elif self.mode == ShutdownMode.POWEROFF: elif self.mode == ShutdownMode.POWEROFF:
log.debug("Shutting down") log.debug("Setting launcher for shut down")
launcher_status = "shutdown" launcher_status += ["action=shutdown"]
default_uid = self.app.controllers.Install.get_default_uid()
if default_uid is not None and default_uid != 0:
launcher_status += ["defaultUid={}".format(default_uid)]
if len(launcher_status) > 0:
status_file = os.path.join(self.root_dir, "run/launcher-command")
with open(status_file, "w+") as f:
f.write("\n".join(comments + launcher_status))
subiquity_rundir = os.path.join(self.root_dir, "run", "subiquity")
os.makedirs(subiquity_rundir, exist_ok=True)
lau_status_file = os.path.join(subiquity_rundir, "launcher-status")
with open(lau_status_file, "w+") as f:
f.write(launcher_status)
self.app.exit() self.app.exit()