2021-08-31 10:07:20 +00:00
|
|
|
# Copyright 2020 Canonical, Ltd.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2021-10-15 16:50:06 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
2021-08-31 10:07:20 +00:00
|
|
|
import logging
|
2021-11-05 20:29:33 +00:00
|
|
|
import re
|
2022-01-14 11:52:01 +00:00
|
|
|
from typing import Optional, Tuple, List
|
2021-08-31 10:07:20 +00:00
|
|
|
|
|
|
|
from subiquity.common.errorreport import ErrorReportKind
|
2021-09-23 08:52:31 +00:00
|
|
|
from subiquity.common.types import ApplicationState
|
2021-10-05 14:53:53 +00:00
|
|
|
from subiquity.common.resources import get_users_and_groups
|
2021-09-23 08:52:31 +00:00
|
|
|
from subiquity.server.controller import SubiquityController
|
|
|
|
from subiquitycore.context import with_context
|
2021-11-03 11:35:25 +00:00
|
|
|
from subiquitycore.utils import arun_command
|
2021-10-04 10:55:25 +00:00
|
|
|
from system_setup.common.wsl_conf import wsl_config_update
|
2021-08-31 10:07:20 +00:00
|
|
|
|
2021-09-27 12:36:25 +00:00
|
|
|
log = logging.getLogger("system_setup.server.controllers.configure")
|
2021-08-31 10:07:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ConfigureController(SubiquityController):
|
2021-12-14 15:07:40 +00:00
|
|
|
default_uid = 0
|
2021-08-31 10:07:20 +00:00
|
|
|
|
|
|
|
def __init__(self, app):
|
|
|
|
super().__init__(app)
|
2021-09-20 06:37:55 +00:00
|
|
|
self.app = app
|
2021-08-31 10:07:20 +00:00
|
|
|
self.model = app.base_model
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
self.install_task = self.app.aio_loop.create_task(self.configure())
|
|
|
|
|
2021-11-08 16:11:30 +00:00
|
|
|
def __locale_gen_cmd(self) -> Tuple[str, bool]:
|
2021-11-12 19:04:02 +00:00
|
|
|
""" Return a tuple of the locale-gen command path and True for
|
|
|
|
validity. In dry-run, copy the locale-gen script, altering the
|
|
|
|
localedef command line to output into a specified directory.
|
|
|
|
"""
|
2021-11-08 16:11:30 +00:00
|
|
|
cmd = "usr/sbin/locale-gen"
|
|
|
|
if self.app.opts.dry_run is False or self.app.opts.dry_run is None:
|
|
|
|
return (os.path.join("/", cmd), True)
|
|
|
|
|
|
|
|
outDir = os.path.join(self.model.root, "usr/lib/locale")
|
|
|
|
usrSbinDir = os.path.join(self.model.root, "usr/sbin")
|
|
|
|
os.makedirs(outDir, exist_ok=True)
|
|
|
|
os.makedirs(usrSbinDir, exist_ok=True)
|
|
|
|
cmdFile = os.path.join(self.model.root, cmd)
|
|
|
|
shutil.copy(os.path.join("/", cmd), cmdFile)
|
|
|
|
# Supply LC_* definition files to avoid complains from localedef.
|
2022-02-17 01:59:05 +00:00
|
|
|
candidateSourceDirs = ["/usr/lib/locale/C.UTF-8/",
|
|
|
|
"/usr/lib/locale/C.utf8/"]
|
|
|
|
sourceDirs = [d for d in candidateSourceDirs if os.path.exists(d)]
|
2022-02-17 10:07:19 +00:00
|
|
|
if len(sourceDirs) == 0:
|
2022-02-17 01:59:05 +00:00
|
|
|
log.error("No available LC_* definitions found in this system")
|
|
|
|
return ("", False)
|
|
|
|
|
|
|
|
shutil.copytree(sourceDirs[0], outDir, dirs_exist_ok=True)
|
2021-11-08 16:11:30 +00:00
|
|
|
try:
|
|
|
|
# Altering locale-gen script to output to the desired folder.
|
|
|
|
with open(cmdFile, "r+") as f:
|
|
|
|
script = f.read()
|
|
|
|
pattern = r'(localedef .+) (\|\| :; \\)'
|
|
|
|
localeDefRe = re.compile(pattern)
|
|
|
|
replacement = r'\1 "{}/" \2'.format(outDir)
|
|
|
|
(fileContents, n) = localeDefRe.subn(replacement, script,
|
|
|
|
count=1)
|
|
|
|
if n != 1:
|
|
|
|
log.error("locale-gen script contents were unexpected."
|
|
|
|
" Aborting mock creation")
|
|
|
|
return ("", False)
|
|
|
|
|
|
|
|
f.seek(0)
|
|
|
|
f.write(fileContents)
|
|
|
|
|
|
|
|
return (cmdFile, True)
|
|
|
|
|
|
|
|
except IOError as err:
|
|
|
|
log.error("Failed to modify %s file. %s", cmdFile, err)
|
|
|
|
return ("", False)
|
|
|
|
|
2021-11-08 22:03:10 +00:00
|
|
|
def __update_locale_cmd(self, lang) -> List[str]:
|
2021-11-12 19:04:02 +00:00
|
|
|
""" Add mocking cli to update-locale if in dry-run."""
|
2022-01-18 13:18:45 +00:00
|
|
|
updateLocCmd = ["update-locale", "LANG={}".format(lang),
|
|
|
|
"--no-checks"]
|
2021-11-09 12:36:10 +00:00
|
|
|
if not self.app.opts.dry_run:
|
|
|
|
return updateLocCmd
|
|
|
|
|
|
|
|
defaultLocDir = os.path.join(self.model.root,
|
|
|
|
"etc/default/")
|
|
|
|
os.makedirs(defaultLocDir, exist_ok=True)
|
|
|
|
updateLocCmd += ["--locale-file",
|
2022-01-18 13:18:45 +00:00
|
|
|
os.path.join(defaultLocDir, "locale")]
|
2021-11-08 16:11:30 +00:00
|
|
|
return updateLocCmd
|
|
|
|
|
|
|
|
async def _activate_locale(self, lang, env) -> bool:
|
2021-11-12 19:04:02 +00:00
|
|
|
""" Return true if succeed in running the last commands
|
|
|
|
to set the locale.
|
|
|
|
"""
|
2021-11-08 16:11:30 +00:00
|
|
|
(locGenCmd, ok) = self.__locale_gen_cmd()
|
2021-11-09 12:36:10 +00:00
|
|
|
if not ok:
|
2021-11-08 16:11:30 +00:00
|
|
|
log.error("Locale generation failed.")
|
|
|
|
return False
|
|
|
|
|
|
|
|
updateCmd = self.__update_locale_cmd(lang)
|
|
|
|
cmds = [[locGenCmd], updateCmd]
|
|
|
|
for cmd in cmds:
|
|
|
|
cp = await arun_command(cmd, env=env)
|
|
|
|
if cp.returncode != 0:
|
|
|
|
log.error('Command "{}" failed with return code {}'
|
|
|
|
.format(cp.args, cp.returncode))
|
|
|
|
return False
|
2021-11-12 19:04:02 +00:00
|
|
|
|
2021-11-08 16:11:30 +00:00
|
|
|
return True
|
|
|
|
|
2022-03-22 20:47:53 +00:00
|
|
|
async def __recommended_language_packs(self, lang) \
|
2022-01-14 11:52:01 +00:00
|
|
|
-> Optional[List[str]]:
|
2021-11-22 15:16:01 +00:00
|
|
|
""" Return a list of package names recommended by
|
|
|
|
check-language-support (or a fake list if in dryrun).
|
2021-11-22 16:42:45 +00:00
|
|
|
List returned can be empty on success. None for failure.
|
2021-11-12 19:04:02 +00:00
|
|
|
"""
|
2021-11-05 20:29:33 +00:00
|
|
|
clsCommand = "check-language-support"
|
2021-11-09 21:15:59 +00:00
|
|
|
# lang code may be separated by @, dot or spaces.
|
|
|
|
# clsLang = lang.split('@')[0].split('.')[0].split(' ')[0]
|
|
|
|
pattern = re.compile(r'([^.@\s]+)', re.IGNORECASE)
|
|
|
|
matches = pattern.match(lang)
|
|
|
|
if matches is None:
|
|
|
|
log.error("Failed to match expected language format: %s", lang)
|
2021-11-22 16:42:45 +00:00
|
|
|
return None
|
2021-11-09 21:15:59 +00:00
|
|
|
|
|
|
|
langCodes = matches.groups()
|
|
|
|
if len(langCodes) != 1:
|
|
|
|
log.error("Only one match was expected for: %s", lang)
|
2021-11-22 16:42:45 +00:00
|
|
|
return None
|
2021-11-09 21:15:59 +00:00
|
|
|
|
|
|
|
clsLang = langCodes[0]
|
2021-11-24 13:57:57 +00:00
|
|
|
packages = []
|
2021-11-08 16:11:30 +00:00
|
|
|
# Running that command doesn't require root.
|
2022-03-22 20:47:53 +00:00
|
|
|
snap_dir = os.getenv("SNAP", default="/")
|
2022-01-17 13:49:47 +00:00
|
|
|
data_dir = os.path.join(snap_dir, "usr/share/language-selector")
|
|
|
|
if not os.path.exists(data_dir):
|
|
|
|
log.error("Misconfigured snap environment pointed L-S-C data dir"
|
|
|
|
" to %s", data_dir)
|
|
|
|
return None
|
|
|
|
|
2022-03-22 20:47:53 +00:00
|
|
|
cp = await arun_command([clsCommand, "-d", data_dir, "-l", clsLang])
|
2021-11-05 20:29:33 +00:00
|
|
|
if cp.returncode != 0:
|
2021-11-08 16:11:30 +00:00
|
|
|
log.error('Command "%s" failed with return code %d',
|
2021-11-05 20:29:33 +00:00
|
|
|
cp.args, cp.returncode)
|
2021-11-24 13:57:57 +00:00
|
|
|
if not self.app.opts.dry_run:
|
|
|
|
return None
|
|
|
|
|
|
|
|
else:
|
|
|
|
packages += [pkg for pkg in cp.stdout.strip().split(' ') if pkg]
|
2021-11-05 20:29:33 +00:00
|
|
|
|
2021-11-24 13:57:57 +00:00
|
|
|
# We will always have language-pack-{baseLang}-base in dryrun.
|
|
|
|
if len(packages) == 0 and self.app.opts.dry_run:
|
|
|
|
baseLang = clsLang.split('_')[0]
|
|
|
|
packages += ["language-pack-{}-base".format(baseLang)]
|
2021-11-22 15:16:01 +00:00
|
|
|
|
2021-11-24 13:57:57 +00:00
|
|
|
return packages
|
2021-11-22 15:16:01 +00:00
|
|
|
|
|
|
|
async def _install_check_lang_support_packages(self, lang, env) -> bool:
|
|
|
|
""" Install recommended packages.
|
|
|
|
lang is expected to be one single language/locale.
|
|
|
|
"""
|
2022-03-22 20:50:54 +00:00
|
|
|
packages = await self.__recommended_language_packs(lang)
|
|
|
|
# Hardcoded path is necessary to ensure escaping out of the snap env.
|
|
|
|
aptCommand = "/usr/bin/apt"
|
2021-11-22 16:42:45 +00:00
|
|
|
if packages is None:
|
|
|
|
log.error('Failed to detect recommended language packs.')
|
|
|
|
return False
|
|
|
|
|
2022-03-22 20:50:54 +00:00
|
|
|
cp = await arun_command([aptCommand,"update"], env=env)
|
|
|
|
|
|
|
|
if cp.returncode != 0:
|
|
|
|
# TODO: deal with the error case.
|
|
|
|
log.error("Failed to update apt cache.\n%s", cp.stderr)
|
|
|
|
|
|
|
|
|
2021-11-22 15:16:01 +00:00
|
|
|
if self.app.opts.dry_run: # only empty in dry-run on failure.
|
|
|
|
if len(packages) == 0:
|
|
|
|
log.error("Packages list in dry-run should never be empty.")
|
|
|
|
return False
|
|
|
|
|
2021-11-08 16:11:30 +00:00
|
|
|
packs_dir = os.path.join(self.model.root,
|
2022-03-22 20:50:54 +00:00
|
|
|
"var/cache/apt/archives/")
|
2021-11-08 16:11:30 +00:00
|
|
|
os.makedirs(packs_dir, exist_ok=True)
|
2021-11-09 21:15:20 +00:00
|
|
|
try:
|
2021-11-09 21:15:59 +00:00
|
|
|
for package in packages:
|
2021-11-09 21:30:18 +00:00
|
|
|
# Just write the package uri to a file.
|
2022-03-22 20:50:54 +00:00
|
|
|
lcp = await arun_command([aptCommand,"install",package,
|
|
|
|
"--simulate"], env=env)
|
|
|
|
archive = os.path.join(packs_dir, package)
|
2021-11-09 21:15:20 +00:00
|
|
|
with open(archive, "wt") as f:
|
2022-03-22 20:50:54 +00:00
|
|
|
f.write(lcp.stdout)
|
2021-11-17 16:26:41 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
2021-11-24 13:57:57 +00:00
|
|
|
except IOError as e:
|
|
|
|
log.error("Failed to write file.", e)
|
2021-11-09 21:30:18 +00:00
|
|
|
return False
|
|
|
|
|
2021-11-22 15:16:01 +00:00
|
|
|
if len(packages) == 0:
|
|
|
|
log.info("No missing recommended packages. Nothing to do.")
|
|
|
|
return True
|
|
|
|
|
2022-03-22 20:50:54 +00:00
|
|
|
cmd = [aptCommand,"install","-y"] + packages
|
|
|
|
acp = await arun_command(cmd, env=env)
|
2021-11-08 16:11:30 +00:00
|
|
|
|
2022-03-22 20:50:54 +00:00
|
|
|
return acp.returncode==0
|
2021-11-08 16:11:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _update_locale_gen_file(self, localeGenPath, lang) -> bool:
|
2021-11-12 19:04:02 +00:00
|
|
|
""" Uncomment the line in locale.gen file matching lang,
|
|
|
|
if found commented. A fully qualified language is expected,
|
|
|
|
since that would have passed thru the Locale controller
|
|
|
|
validation. e.g. en_UK.UTF-8. Return True for success.
|
|
|
|
"""
|
2021-11-08 16:11:30 +00:00
|
|
|
fileContents: str
|
|
|
|
try:
|
|
|
|
with open(localeGenPath, "r+") as f:
|
|
|
|
fileContents = f.read()
|
|
|
|
lineFound = fileContents.find(lang)
|
|
|
|
if lineFound == -1:
|
|
|
|
# An unsupported locale coming from our UI is a bug
|
|
|
|
log.error("Selected language %s not supported.", lang)
|
|
|
|
return False
|
|
|
|
|
|
|
|
pattern = r'[# ]*({}.*)'.format(lang)
|
|
|
|
commented = re.compile(pattern)
|
|
|
|
(fileContents, n) = commented.subn(r'\1', fileContents,
|
|
|
|
count=1)
|
|
|
|
if n != 1:
|
|
|
|
log.error("Unexpected locale.gen file contents. Aborting.")
|
|
|
|
return False
|
|
|
|
|
|
|
|
f.seek(0)
|
|
|
|
f.write(fileContents)
|
|
|
|
return True
|
|
|
|
|
|
|
|
except IOError as err:
|
|
|
|
log.error("Failed to modify %s file. %s", localeGenPath, err)
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _locale_gen_file_path(self):
|
2021-11-12 19:04:02 +00:00
|
|
|
""" Return the proper locale.gen path for dry or live-run."""
|
2021-11-08 16:11:30 +00:00
|
|
|
localeGenPath = "/etc/locale.gen"
|
|
|
|
if self.app.opts.dry_run is False or self.app.opts.dry_run is None:
|
|
|
|
return localeGenPath
|
|
|
|
|
|
|
|
# For testing purposes.
|
|
|
|
etc_dir = os.path.join(self.model.root, "etc")
|
|
|
|
testLocGenPath = os.path.join(etc_dir,
|
|
|
|
os.path.basename(localeGenPath))
|
|
|
|
shutil.copy(localeGenPath, testLocGenPath)
|
2021-11-12 19:04:02 +00:00
|
|
|
shutil.copy(localeGenPath, "{}.test".format(testLocGenPath))
|
2021-11-08 16:11:30 +00:00
|
|
|
return testLocGenPath
|
|
|
|
|
2022-03-22 20:46:25 +00:00
|
|
|
async def apply_locale(self, lang, env):
|
2021-11-12 19:04:02 +00:00
|
|
|
""" Effectively apply the locale setup to the new system."""
|
2021-11-08 16:11:30 +00:00
|
|
|
localeGenPath = self._locale_gen_file_path()
|
|
|
|
if self._update_locale_gen_file(localeGenPath, lang) is False:
|
|
|
|
log.error("Failed to update locale.gen")
|
|
|
|
return
|
|
|
|
|
|
|
|
ok = await self._install_check_lang_support_packages(lang, env)
|
2021-11-09 12:36:10 +00:00
|
|
|
if not ok:
|
2021-11-08 16:11:30 +00:00
|
|
|
log.error("Failed to install recommended language packs.")
|
|
|
|
return
|
|
|
|
|
|
|
|
ok = await self._activate_locale(lang, env)
|
2021-11-09 12:36:10 +00:00
|
|
|
if not ok:
|
2021-11-08 16:11:30 +00:00
|
|
|
log.error("Failed to run locale activation commands.")
|
|
|
|
return
|
2021-11-05 20:29:33 +00:00
|
|
|
|
2021-12-17 13:35:38 +00:00
|
|
|
def __query_uid(self, etc_dir, username):
|
|
|
|
""" Finds the UID of username in etc_dir/passwd file. """
|
|
|
|
uid = None
|
|
|
|
with open(os.path.join(etc_dir, "passwd")) as f:
|
|
|
|
for line in f:
|
|
|
|
tokens = line.split(":")
|
|
|
|
if username == tokens[0]:
|
|
|
|
if len(tokens) != 7:
|
|
|
|
raise Exception("Invalid passwd entry")
|
|
|
|
|
|
|
|
uid = int(tokens[2])
|
|
|
|
break
|
|
|
|
|
|
|
|
return uid
|
|
|
|
|
2022-03-22 20:46:25 +00:00
|
|
|
async def create_user(self, root_dir, env):
|
2021-12-17 13:35:38 +00:00
|
|
|
""" Helper method to create the user from the identity model
|
|
|
|
and store it's UID. """
|
|
|
|
wsl_id = self.model.identity.user
|
|
|
|
username = wsl_id.username
|
|
|
|
create_user_base = []
|
|
|
|
assign_grp_base = []
|
|
|
|
usergroups_list = get_users_and_groups()
|
2022-01-17 13:48:58 +00:00
|
|
|
etc_dir = "/etc" # default if not dryrun.
|
2021-12-17 13:35:38 +00:00
|
|
|
if self.app.opts.dry_run:
|
|
|
|
log.debug("creating a mock-up env for user %s", username)
|
|
|
|
# creating folders and files for dryrun
|
|
|
|
etc_dir = os.path.join(root_dir, "etc")
|
|
|
|
os.makedirs(etc_dir, exist_ok=True)
|
|
|
|
home_dir = os.path.join(root_dir, "home")
|
|
|
|
os.makedirs(home_dir, exist_ok=True)
|
|
|
|
pseudo_files = ["passwd", "shadow", "gshadow", "group",
|
|
|
|
"subgid", "subuid"]
|
|
|
|
for file in pseudo_files:
|
|
|
|
filepath = os.path.join(etc_dir, file)
|
|
|
|
open(filepath, "a").close()
|
|
|
|
|
|
|
|
# mimic groupadd
|
|
|
|
group_id = 1000
|
|
|
|
for group in usergroups_list:
|
|
|
|
group_filepath = os.path.join(etc_dir, "group")
|
|
|
|
gshadow_filepath = os.path.join(etc_dir, "gshadow")
|
|
|
|
shutil.copy(group_filepath,
|
|
|
|
"{}-".format(group_filepath))
|
|
|
|
with open(group_filepath, "a") as group_file:
|
|
|
|
group_file.write("{}:x:{}:\n".format(group, group_id))
|
|
|
|
group_id += 1
|
|
|
|
shutil.copy(gshadow_filepath,
|
|
|
|
"{}-".format(gshadow_filepath))
|
|
|
|
with open(gshadow_filepath, "a") as gshadow_file:
|
|
|
|
gshadow_file.write("{}:!::\n".format(group))
|
|
|
|
|
|
|
|
create_user_base = ["-P", root_dir]
|
|
|
|
assign_grp_base = ["-P", root_dir]
|
|
|
|
|
2022-03-22 20:46:25 +00:00
|
|
|
# TODO: Figure out if Hardcoded paths here cause trouble for runtests.
|
|
|
|
create_user_cmd = ["/usr/sbin/useradd"] + create_user_base + \
|
2021-12-17 13:35:38 +00:00
|
|
|
["-m", "-s", "/bin/bash", "-c", wsl_id.realname,
|
|
|
|
"-p", wsl_id.password, username]
|
2022-03-22 20:46:25 +00:00
|
|
|
assign_grp_cmd = ["/usr/sbin/usermod"] + assign_grp_base + \
|
2021-12-17 13:35:38 +00:00
|
|
|
["-a", "-G", ",".join(usergroups_list), username]
|
|
|
|
|
2022-03-22 20:46:25 +00:00
|
|
|
create_user_proc = await arun_command(create_user_cmd, env=env)
|
2021-12-17 13:35:38 +00:00
|
|
|
if create_user_proc.returncode != 0:
|
|
|
|
raise Exception("Failed to create user %s: %s"
|
|
|
|
% (username, create_user_proc.stderr))
|
|
|
|
log.debug("created user %s", username)
|
|
|
|
|
|
|
|
self.default_uid = self.__query_uid(etc_dir, username)
|
|
|
|
if self.default_uid is None:
|
|
|
|
log.error("Could not retrieve %s UID", username)
|
|
|
|
|
2022-03-22 20:46:25 +00:00
|
|
|
assign_grp_proc = await arun_command(assign_grp_cmd, env=env)
|
2021-12-17 13:35:38 +00:00
|
|
|
if assign_grp_proc.returncode != 0:
|
|
|
|
raise Exception(("Failed to assign group to user %s: %s")
|
|
|
|
% (username, assign_grp_proc.stderr))
|
|
|
|
|
2021-08-31 10:07:20 +00:00
|
|
|
@with_context(
|
|
|
|
description="final system configuration", level="INFO",
|
|
|
|
childlevel="DEBUG")
|
|
|
|
async def configure(self, *, context):
|
2021-11-12 19:04:02 +00:00
|
|
|
""" Apply the installation steps submitted by the user."""
|
2021-09-01 08:48:44 +00:00
|
|
|
context.set('is-install-context', True)
|
2021-08-31 10:07:20 +00:00
|
|
|
try:
|
|
|
|
|
|
|
|
self.app.update_state(ApplicationState.WAITING)
|
|
|
|
|
2021-09-01 08:48:44 +00:00
|
|
|
await self.model.wait_install()
|
|
|
|
|
2021-08-31 10:07:20 +00:00
|
|
|
self.app.update_state(ApplicationState.NEEDS_CONFIRMATION)
|
|
|
|
|
|
|
|
self.app.update_state(ApplicationState.RUNNING)
|
|
|
|
|
2021-09-01 08:48:44 +00:00
|
|
|
await self.model.wait_postinstall()
|
|
|
|
|
2021-08-31 10:07:20 +00:00
|
|
|
self.app.update_state(ApplicationState.POST_WAIT)
|
|
|
|
|
|
|
|
self.app.update_state(ApplicationState.POST_RUNNING)
|
|
|
|
|
2021-09-14 08:16:06 +00:00
|
|
|
variant = self.app.variant
|
2021-10-06 14:10:56 +00:00
|
|
|
root_dir = self.model.root
|
2021-12-17 13:35:38 +00:00
|
|
|
|
2021-09-28 12:48:30 +00:00
|
|
|
if variant == "wsl_setup":
|
2021-11-05 20:29:33 +00:00
|
|
|
lang = self.model.locale.selected_language
|
2022-03-22 20:46:25 +00:00
|
|
|
envcp = os.environ.copy()
|
|
|
|
# Ensures a safe escape out of the snap environment for WSL.
|
|
|
|
if not self.app.opts.dry_run:
|
|
|
|
envcp['LD_LIBRARY_PATH']=''
|
|
|
|
envcp['LD_PRELOAD']=''
|
|
|
|
await self.create_user(root_dir, envcp)
|
|
|
|
await self.apply_locale(lang, envcp)
|
2021-11-12 19:04:02 +00:00
|
|
|
|
2021-09-28 12:48:30 +00:00
|
|
|
else:
|
2021-10-04 10:55:25 +00:00
|
|
|
wsl_config_update(self.model.wslconfadvanced.wslconfadvanced,
|
2021-10-06 14:10:56 +00:00
|
|
|
root_dir)
|
2021-09-30 16:00:32 +00:00
|
|
|
|
2021-10-08 12:21:16 +00:00
|
|
|
# update advanced config when it is in autoinstall mode
|
|
|
|
if self.app.opts.autoinstall is not None and \
|
|
|
|
self.model.wslconfadvanced.wslconfadvanced is not None:
|
|
|
|
wsl_config_update(self.model.wslconfadvanced.wslconfadvanced,
|
|
|
|
root_dir)
|
|
|
|
|
2021-12-14 15:07:40 +00:00
|
|
|
wsl_config_update(self.model.wslconfbase.wslconfbase, root_dir)
|
2021-09-28 12:48:30 +00:00
|
|
|
|
2021-08-31 10:07:20 +00:00
|
|
|
self.app.update_state(ApplicationState.DONE)
|
2021-11-12 19:04:02 +00:00
|
|
|
|
2021-08-31 10:07:20 +00:00
|
|
|
except Exception:
|
|
|
|
kw = {}
|
|
|
|
self.app.make_apport_report(
|
|
|
|
ErrorReportKind.INSTALL_FAIL, "configuration failed", **kw)
|
|
|
|
raise
|
|
|
|
|
|
|
|
def stop_uu(self):
|
|
|
|
# This is a no-op to allow Shutdown controller to depend on this one
|
2021-08-31 11:26:49 +00:00
|
|
|
pass
|
2021-12-14 15:07:40 +00:00
|
|
|
|
|
|
|
# Allows passing the recently created user UID to the Shutdown controller.
|
|
|
|
def get_default_uid(self):
|
|
|
|
return self.default_uid
|