diff --git a/Makefile b/Makefile index f82c5670..3b38d1aa 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,6 @@ PROBERTDIR=./probert PROBERT_REPO=https://github.com/canonical/probert DRYRUN?=--dry-run --bootloader uefi --machine-config examples/simple.json SYSTEM_SETUP_DRYRUN?=--dry-run -RECONFIG?=--reconfigure export PYTHONPATH CWD := $(shell pwd) @@ -57,10 +56,10 @@ dryrun-system-setup-server: $(PYTHON) -m system_setup.cmd.server $(SYSTEM_SETUP_DRYRUN) dryrun-system-setup-recon: - $(PYTHON) -m system_setup.cmd.tui $(SYSTEM_SETUP_DRYRUN) $(RECONFIG) + DRYRUN_RECONFIG=true $(PYTHON) -m system_setup.cmd.tui $(SYSTEM_SETUP_DRYRUN) dryrun-system-setup-server-recon: - $(PYTHON) -m system_setup.cmd.server $(SYSTEM_SETUP_DRYRUN) $(RECONFIG) + DRYRUN_RECONFIG=true $(PYTHON) -m system_setup.cmd.server $(SYSTEM_SETUP_DRYRUN) lint: flake8 diff --git a/system_setup/client/client.py b/system_setup/client/client.py index 2439f967..0d2d6f3a 100644 --- a/system_setup/client/client.py +++ b/system_setup/client/client.py @@ -15,6 +15,7 @@ import logging import sys +from system_setup.common.helpers import is_reconfigure from subiquity.client.client import SubiquityClient @@ -40,15 +41,12 @@ class SystemSetupClient(SubiquityClient): def __init__(self, opts): # TODO WSL: - # 1. remove reconfigure flag - # 2. decide on which UI to show up based on existing user UID >=1000 - # (or default user set in wsl.conf?) # 3. provide an API for this for the flutter UI to know about it - # 4. Add Configuration Base page before Advanced - # 5. Add language page - # self.variant = "wsl_configuration" - if opts.reconfigure: + + if is_reconfigure(opts.dry_run): + self.variant = "wsl_configuration" self.controllers = [ + "Welcome", "WSLConfigurationBase", "WSLConfigurationAdvanced", "Summary", diff --git a/system_setup/cmd/tui.py b/system_setup/cmd/tui.py index 92fb8c57..f70249b2 100755 --- a/system_setup/cmd/tui.py +++ b/system_setup/cmd/tui.py @@ -72,10 +72,6 @@ def make_client_args_parser(): help='Synthesize a click on a button matching PAT') parser.add_argument('--answers') parser.add_argument('--server-pid') - # TODO WSL: remove reconfigure flag and use dynamic decision (see below) - # Expose that as an endpoint on the server and decide in the client what - # to show - parser.add_argument('--reconfigure', action='store_true') return parser diff --git a/system_setup/common/helpers.py b/system_setup/common/helpers.py new file mode 100644 index 00000000..e1a788ed --- /dev/null +++ b/system_setup/common/helpers.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +# Copyright 2015-2021 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 . + +import os + + +def is_reconfigure(is_dryrun): + is_dryrun_reconfigure = is_dryrun and \ + os.getenv("DRYRUN_RECONFIG") == "true" + count = 0 + with open('/etc/passwd', 'r') as f: + for line in f: + # check every normal user except nobody (65534) + if int(line.split(':')[2]) >= 1000 and \ + int(line.split(':')[2]) != 65534: + count += 1 + is_none_dryrun_normaluser = not is_dryrun and count != 0 + return is_dryrun_reconfigure or is_none_dryrun_normaluser