From 7851ab99ccf3daf8b196623dd27d777c95f16fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Stefanik?= Date: Mon, 1 Jan 2024 22:37:32 +0100 Subject: [PATCH] Support interactive issue resolution prompts This adds a new flag, -i / --interactive, which enables opening a Bash prompt whenever something goes wrong in the bootstrap. This is highly useful when developing or debugging live-bootstrap, but it needs to be off by default, for use in automated processes. In the future, asking for variables at runtime could (and perhaps should) also be gated behind this flag. --- rootfs.py | 14 +++++++++----- seed/script-generator.c | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/rootfs.py b/rootfs.py index 5a9e7988..5f3c9668 100755 --- a/rootfs.py +++ b/rootfs.py @@ -32,6 +32,7 @@ def create_configuration_file(args): config.write(f"UPDATE_CHECKSUMS={args.update_checksums}\n") config.write(f"JOBS={args.cores}\n") config.write(f"INTERNAL_CI={args.internal_ci or False}\n") + config.write(f"INTERACTIVE={args.interactive}\n") config.write(f"BARE_METAL={args.bare_metal}\n") if (args.bare_metal or args.qemu) and not args.kernel: if args.repo or args.external_sources: @@ -70,21 +71,24 @@ def main(): help="Force all files timestamps to be 0 unix time", action="store_true") parser.add_argument("--update-checksums", - help="Update checksum files.", + help="Update checksum files", action="store_true") parser.add_argument("--external-sources", - help="Download sources externally from live-bootstrap.", + help="Download sources externally from live-bootstrap", action="store_true") parser.add_argument("--build-kernels", - help="Also build kernels in chroot and bwrap builds.", + help="Also build kernels in chroot and bwrap builds", action="store_true") parser.add_argument("--no-create-config", help="Do not automatically create config file", action="store_true") + parser.add_argument("-i", "--interactive", + help="Use interactive prompts to resolve issues during bootstrap", + action="store_true") parser.add_argument("-r", "--repo", - help="Path to prebuilt binary packages.", nargs=None) + help="Path to prebuilt binary packages", nargs=None) parser.add_argument("--early-preseed", - help="Skip early stages of live-bootstrap.", nargs=None) + help="Skip early stages of live-bootstrap", nargs=None) parser.add_argument("--internal-ci", help="INTERNAL for github CI") # QEMU arguments diff --git a/seed/script-generator.c b/seed/script-generator.c index 65daa387..f22db09f 100644 --- a/seed/script-generator.c +++ b/seed/script-generator.c @@ -425,7 +425,17 @@ FILE *start_script(int id, int using_bash) { if (using_bash) { fputs("#!/bin/bash\n", out); - fputs("set -e\n", out); + if (strcmp(get_var("INTERACTIVE"), "True") == 0) { + if (using_bash != 1) { + fputs("set -E\ntrap 'env PS1=\"[TRAP] \\w # \" bash -i' ERR\n", out); + } else { + fputs("set -E\ntrap 'bash -c '\"'\"'while true; do printf \"" + "[TRAP - use Ctrl+D] $(pwd) # \"; $(cat); done'\"'\"'' ERR\n", + out); + } + } else { + fputs("set -e\n", out); + } fputs("cd /steps\n", out); fputs(". ./bootstrap.cfg\n", out); fputs(". ./env\n", out); @@ -537,7 +547,7 @@ void generate(Directive *directives) { */ generate_preseed_jump(counter); } - using_bash = 1; + using_bash += 1; /* Create call to new script. */ output_call_script(out, "", int2str(counter, 10, 0), using_bash, 0); fclose(out);