fix: handle initialise/finalise failures, use env during update check
This commit is contained in:
parent
2a08830ac0
commit
5ec321bcb0
2 changed files with 28 additions and 17 deletions
|
|
@ -8,23 +8,28 @@ from . import output
|
||||||
|
|
||||||
|
|
||||||
def run_script_rootfs(rootfs: RootFS, input: str, args: list):
|
def run_script_rootfs(rootfs: RootFS, input: str, args: list):
|
||||||
"""Run a script within the rootfs."""
|
"""Runs a script within the rootfs."""
|
||||||
|
|
||||||
rootfs.exec(["bash", "-s", *args], text=True, input=input)
|
rootfs.exec(["bash", "-s", *args], text=True, input=input)
|
||||||
|
|
||||||
|
|
||||||
def gen_rootfs(system_config: dict, rootfs_path: str, env: dict = {}) -> RootFS:
|
def gen_rootfs(system_config: dict, rootfs_path: str) -> RootFS:
|
||||||
"""Generates a rootfs for a given system configuration."""
|
"""Generates a rootfs for a given system configuration."""
|
||||||
|
|
||||||
rootfs = RootFS(rootfs_path, system_config["distro-config"], env)
|
rootfs = RootFS(rootfs_path, system_config["distro-config"], system_config["env"])
|
||||||
|
|
||||||
subprocess.run(
|
if (
|
||||||
["bash", "-s"],
|
subprocess.run(
|
||||||
text=True,
|
["bash", "-s"],
|
||||||
input=system_config["distro-config"]["before-stages"],
|
text=True,
|
||||||
cwd=rootfs_path,
|
input=system_config["distro-config"]["before-stages"],
|
||||||
env=os.environ.copy() | env,
|
cwd=rootfs_path,
|
||||||
)
|
env=os.environ.copy() | system_config["env"],
|
||||||
|
).returncode
|
||||||
|
!= 0
|
||||||
|
):
|
||||||
|
output.error("failed to initialise rootfs")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
modules = {}
|
modules = {}
|
||||||
|
|
||||||
|
|
@ -42,13 +47,18 @@ def gen_rootfs(system_config: dict, rootfs_path: str, env: dict = {}) -> RootFS:
|
||||||
run_script_rootfs(rootfs, modules[stage["module"]], inputs)
|
run_script_rootfs(rootfs, modules[stage["module"]], inputs)
|
||||||
|
|
||||||
if isinstance(system_config["distro-config"].get("after-stages"), str):
|
if isinstance(system_config["distro-config"].get("after-stages"), str):
|
||||||
subprocess.run(
|
if (
|
||||||
["bash", "-s"],
|
subprocess.run(
|
||||||
text=True,
|
["bash", "-s"],
|
||||||
input=system_config["distro-config"]["after-stages"],
|
text=True,
|
||||||
cwd=str(rootfs_path),
|
input=system_config["distro-config"]["after-stages"],
|
||||||
env=os.environ.copy() | env,
|
cwd=str(rootfs_path),
|
||||||
)
|
env=os.environ.copy() | system_config["env"],
|
||||||
|
)
|
||||||
|
!= 0
|
||||||
|
):
|
||||||
|
output.error("failed to finalise rootfs")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
with open(os.path.join(rootfs_path, "usr/system.json"), "w") as system_json_file:
|
with open(os.path.join(rootfs_path, "usr/system.json"), "w") as system_json_file:
|
||||||
json.dump(system_config, system_json_file, ensure_ascii=False)
|
json.dump(system_config, system_json_file, ensure_ascii=False)
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,7 @@ def is_already_latest() -> bool:
|
||||||
["bash", "-s"],
|
["bash", "-s"],
|
||||||
text=True,
|
text=True,
|
||||||
input=system_config["distro-config"]["should-update"],
|
input=system_config["distro-config"]["should-update"],
|
||||||
|
env=os.environ.copy() | system_config["env"],
|
||||||
).returncode
|
).returncode
|
||||||
!= 0
|
!= 0
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue