mirror of
https://github.com/fosslinux/live-bootstrap.git
synced 2026-03-24 12:06:31 +01:00
refactor(resume-init): move network bring-up into generated jump init and keep checkpoint compatibility patch
This commit is contained in:
parent
84400964ed
commit
f11bbe6733
2 changed files with 29 additions and 22 deletions
37
rootfs.py
37
rootfs.py
|
|
@ -74,7 +74,6 @@ def update_stage0_image(image_path,
|
||||||
mounted = True
|
mounted = True
|
||||||
script = '''
|
script = '''
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
@ -109,30 +108,28 @@ lines.append("PAYLOAD_REQUIRED=False\\n")
|
||||||
with open(config_path, "w", encoding="utf-8") as cfg:
|
with open(config_path, "w", encoding="utf-8") as cfg:
|
||||||
cfg.writelines(lines)
|
cfg.writelines(lines)
|
||||||
|
|
||||||
# Resumed jump init scripts look like "bash /steps*/N.sh" and miss network bring-up.
|
# Compatibility for older checkpoints: patch simple resume /init stubs in-place.
|
||||||
# Wrap only that form to keep normal /init behavior unchanged.
|
|
||||||
init_path = os.path.join(mountpoint, "init")
|
init_path = os.path.join(mountpoint, "init")
|
||||||
if os.path.isfile(init_path):
|
if os.path.isfile(init_path):
|
||||||
with open(init_path, "r", encoding="utf-8") as init_file:
|
with open(init_path, "r", encoding="utf-8") as init_file:
|
||||||
init_text = init_file.read()
|
init_text = init_file.read()
|
||||||
|
init_lines = [line.strip() for line in init_text.splitlines() if line.strip()]
|
||||||
if "dhcpcd --waitip=4" not in init_text:
|
if ("dhcpcd --waitip=4" not in init_text
|
||||||
resume_match = re.search(
|
and len(init_lines) == 2
|
||||||
r"^\\s*bash\\s+(/(?:steps|steps-guix)/[0-9]+\\.sh)\\s*$",
|
and init_lines[0].startswith("#!/bin/bash")
|
||||||
init_text,
|
and init_lines[1].startswith("bash /")
|
||||||
re.MULTILINE,
|
and init_lines[1].endswith(".sh")):
|
||||||
)
|
|
||||||
if resume_match:
|
|
||||||
resume_script = resume_match.group(1)
|
|
||||||
wrapped_init = f"""#!/usr/bin/bash
|
|
||||||
set -e
|
|
||||||
if command -v dhcpcd >/dev/null 2>&1; then
|
|
||||||
dhcpcd --waitip=4 || true
|
|
||||||
fi
|
|
||||||
exec bash {resume_script}
|
|
||||||
"""
|
|
||||||
with open(init_path, "w", encoding="utf-8") as init_file:
|
with open(init_path, "w", encoding="utf-8") as init_file:
|
||||||
init_file.write(wrapped_init)
|
init_file.write("#!/bin/bash\\n")
|
||||||
|
init_file.write("if [ -f /steps/bootstrap.cfg ]; then\\n")
|
||||||
|
init_file.write(". /steps/bootstrap.cfg\\n")
|
||||||
|
init_file.write("fi\\n")
|
||||||
|
init_file.write(
|
||||||
|
"if [ \\"${CHROOT}\\" = False ] && command -v dhcpcd >/dev/null 2>&1; then\\n"
|
||||||
|
)
|
||||||
|
init_file.write("dhcpcd --waitip=4 || true\\n")
|
||||||
|
init_file.write("fi\\n")
|
||||||
|
init_file.write(f"exec {init_lines[1]}\\n")
|
||||||
os.chmod(init_path, 0o755)
|
os.chmod(init_path, 0o755)
|
||||||
|
|
||||||
if build_guix_also:
|
if build_guix_also:
|
||||||
|
|
|
||||||
|
|
@ -530,6 +530,15 @@ void output_call_script(FILE *out, char *type, char *name, int bash_build, int s
|
||||||
fputs(".sh\n", out);
|
fputs(".sh\n", out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void output_resume_network_init(FILE *out) {
|
||||||
|
fputs("if [ -f /steps/bootstrap.cfg ]; then\n", out);
|
||||||
|
fputs(". /steps/bootstrap.cfg\n", out);
|
||||||
|
fputs("fi\n", out);
|
||||||
|
fputs("if [ \"${CHROOT}\" = False ] && command -v dhcpcd >/dev/null 2>&1; then\n", out);
|
||||||
|
fputs("dhcpcd --waitip=4 || true\n", out);
|
||||||
|
fputs("fi\n", out);
|
||||||
|
}
|
||||||
|
|
||||||
void output_build(FILE *out, Directive *directive, int pass_no, int bash_build) {
|
void output_build(FILE *out, Directive *directive, int pass_no, int bash_build) {
|
||||||
if (bash_build) {
|
if (bash_build) {
|
||||||
fputs("build ", out);
|
fputs("build ", out);
|
||||||
|
|
@ -650,6 +659,7 @@ void generate(Directive *directives) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
fputs("#!/bin/bash\n", out);
|
fputs("#!/bin/bash\n", out);
|
||||||
|
output_resume_network_init(out);
|
||||||
} else {
|
} else {
|
||||||
out = fopen(filename, "w");
|
out = fopen(filename, "w");
|
||||||
if (out == NULL) {
|
if (out == NULL) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue