From 6899f2497dd2dc45a0d48e5d9621c19f4ca4fe7b Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Sat, 28 Oct 2023 23:50:57 -0500 Subject: image: Allow custom paths for qemu-static binaries This allows one to use i.e. /opt/qemu/bin or /usr/gxemul/bin for the qemu static binaries used to generate foreign-architecture images. --- image/creator.1 | 10 +++++++++- image/creator.cc | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/image/creator.1 b/image/creator.1 index 5673f75..2de51a1 100644 --- a/image/creator.1 +++ b/image/creator.1 @@ -1,4 +1,4 @@ -.Dd May 16, 2020 +.Dd October 28, 2023 .Dt HSCRIPT-IMAGE 1 .Os "Adélie Linux" .Sh NAME @@ -6,6 +6,7 @@ .Nd create an image based on a HorizonScript for later deployment .Sh SYNOPSIS .Nm +.Op Fl e Ar DIRECTORY .Op Fl h .Op Fl i Ar DIRECTORY .Op Fl n @@ -80,6 +81,13 @@ as the argument to .Fl t . .It Fl v Displays the version information for this utility, and then exits. +.It Fl e Ar DIRECTORY +Sets the qemu-static binary directory to +.Ar DIRECTORY . +This must be equivalent to the configuration of binfmt-misc on the host. +The default is +.Pa /usr/bin , +and typically should not be changed unless you have a very good reason. .It Ar INSTALLFILE Specifies the location of the HorizonScript to use for configuring the image. You may specify diff --git a/image/creator.cc b/image/creator.cc index 0d97ff1..ce2c537 100644 --- a/image/creator.cc +++ b/image/creator.cc @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) { bool needs_help{}, disable_pretty{}, version_only{}; int exit_code = EXIT_SUCCESS; std::string if_path{"/etc/horizon/installfile"}, ir_dir{"/tmp/horizon-image"}, - output_path{"image.tar"}, type_code{"tar"}; + output_path{"image.tar"}, type_code{"tar"}, emul_dir{"/usr/bin"}; BasicBackend *backend = nullptr; std::map backend_opts; Horizon::ScriptOptions opts; @@ -66,6 +66,7 @@ int main(int argc, char *argv[]) { target.add_options() ("output,o", value()->default_value("image.tar"), "Desired filename for the output file.") ("ir-dir,i", value()->default_value("/tmp/horizon-image"), "Where to store intermediate files.") + ("emul-dir,e", value()->default_value("/usr/bin"), "Where qemu-static binaries are stored.") ; options_description backconfig{"Backend configuration options"}; backconfig.add_options() @@ -134,6 +135,14 @@ int main(int argc, char *argv[]) { ir_dir = fs::absolute(ir_dir).string(); } + if(!vm["emul-dir"].empty()) { + emul_dir = vm["emul-dir"].as(); + } + + if(fs::path(emul_dir).is_relative()) { + emul_dir = fs::absolute(emul_dir).string(); + } + if(!vm["output"].empty()) { output_path = vm["output"].as(); } @@ -222,11 +231,11 @@ int main(int argc, char *argv[]) { if(archkey) { const Horizon::Keys::Arch *arch = dynamic_cast(archkey); - qpath = "/usr/bin/qemu-" + arch_xlate(arch->value()); + qpath = emul_dir + "/qemu-" + arch_xlate(arch->value()); error_code ec; if(fs::exists(qpath, ec)) { - fs::create_directories(ir_dir + "/target/usr/bin", ec); - if(!ec) fs::copy_file(qpath, ir_dir + "/target/" + qpath, ec); + fs::create_directories(ir_dir + "/target" + emul_dir, ec); + if(!ec) fs::copy_file(qpath, ir_dir + "/target" + qpath, ec); } } -- cgit v1.2.3-60-g2f50