Ask startup question earlier

This commit is contained in:
Jip-Hop 2024-02-16 10:46:51 +01:00
parent 7be1c7c7d2
commit 930e9568d4
1 changed files with 9 additions and 12 deletions

View File

@ -266,6 +266,7 @@ def shell_jail(args):
""" """
return subprocess.run(["machinectl", "shell"] + args).returncode return subprocess.run(["machinectl", "shell"] + args).returncode
def parse_config_string(config_string): def parse_config_string(config_string):
config = configparser.ConfigParser() config = configparser.ConfigParser()
# Workaround to read config file without section headers # Workaround to read config file without section headers
@ -326,7 +327,7 @@ def start_jail(jail_name):
# Handle initial setup # Handle initial setup
initial_setup = config.get("initial_setup") initial_setup = config.get("initial_setup")
# Alternative method to setup on first boot: # Alternative method to setup on first boot:
# https://www.undrground.org/2021/01/25/adding-a-single-run-task-via-systemd/ # https://www.undrground.org/2021/01/25/adding-a-single-run-task-via-systemd/
# If there's no machine-id, then this the first time the jail is started # If there's no machine-id, then this the first time the jail is started
@ -359,7 +360,7 @@ def start_jail(jail_name):
eprint() eprint()
eprint("Abort starting jail.") eprint("Abort starting jail.")
return returncode return returncode
# Cleanup the initial_setup_file # Cleanup the initial_setup_file
Path(initial_setup_file).unlink(missing_ok=True) Path(initial_setup_file).unlink(missing_ok=True)
@ -960,6 +961,11 @@ def create_jail(jail_name="", config_path=None, distro="debian", release="bookwo
) )
) )
print()
start_now = agree(
"Do you want to start this jail now (when create is done)?", "y"
)
# Use mostly default settings for systemd-nspawn but with systemd-run instead of a service file: # Use mostly default settings for systemd-nspawn but with systemd-run instead of a service file:
# https://github.com/systemd/systemd/blob/main/units/systemd-nspawn%40.service.in # https://github.com/systemd/systemd/blob/main/units/systemd-nspawn%40.service.in
# Use TasksMax=infinity since this is what docker does: # Use TasksMax=infinity since this is what docker does:
@ -1206,16 +1212,7 @@ def create_jail(jail_name="", config_path=None, distro="debian", release="bookwo
cleanup(jail_path) cleanup(jail_path)
raise error raise error
# In case you want to create a jail without any user interaction, if start_now:
# you need to skip this final question
# echo 'y' | jlmkr create test testconfig
# TODO: make jlmkr create work cleanly without user interaction.
# Current echo 'y' workaround may cause problems when the jail name already exists
# You'd end up with a new jail called 'y'
# and the script will crash at the agree statement below
# TODO: move this question higher, above the actual creating bit
print()
if agree(f"Do you want to start jail {jail_name} right now?", "y"):
return start_jail(jail_name) return start_jail(jail_name)