From 97776b4642e12971a326760d944662872c89f056 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 13 May 2025 22:20:16 +1200 Subject: [PATCH] dropshell release 2025.0513.2220 --- multibuild.sh | 11 +++++++++-- src/commands/edit.cpp | 2 -- src/commands/install.cpp | 37 ++++++++++++++++++++++++++++++++++++- src/config.cpp | 22 ++-------------------- src/config.hpp | 1 - src/utils/directories.hpp | 3 +-- src/utils/execute.cpp | 6 +++--- 7 files changed, 51 insertions(+), 31 deletions(-) diff --git a/multibuild.sh b/multibuild.sh index 4f9016b..e3beec9 100755 --- a/multibuild.sh +++ b/multibuild.sh @@ -8,6 +8,13 @@ set -e rm -f build_amd64/dropshell build_arm64/dropshell build/dropshell.amd64 build/dropshell.arm64 +# Determine number of CPU cores for parallel build +if command -v nproc >/dev/null 2>&1; then + JOBS=$(nproc) +else + JOBS=4 # fallback default +fi + # Build for amd64 (musl) echo "Building for amd64 (musl)..." cmake -B build_amd64 -DCMAKE_BUILD_TYPE=Release \ @@ -15,7 +22,7 @@ cmake -B build_amd64 -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CXX_COMPILER=x86_64-linux-musl-g++ \ -DCMAKE_EXE_LINKER_FLAGS="-static" \ -DCMAKE_CXX_FLAGS="-march=x86-64" . -cmake --build build_amd64 --target dropshell --config Release +cmake --build build_amd64 --target dropshell --config Release -j"$JOBS" mkdir -p build cp build_amd64/dropshell build/dropshell.amd64 @@ -27,7 +34,7 @@ cmake -B build_arm64 -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_EXE_LINKER_FLAGS="-static" \ -DCMAKE_CXX_FLAGS="-march=armv8-a" \ -DCMAKE_SYSTEM_PROCESSOR=aarch64 . -cmake --build build_arm64 --target dropshell --config Release +cmake --build build_arm64 --target dropshell --config Release -j"$JOBS" mkdir -p build cp build_arm64/dropshell build/dropshell.arm64 diff --git a/src/commands/edit.cpp b/src/commands/edit.cpp index b03d7e1..f0b90fb 100644 --- a/src/commands/edit.cpp +++ b/src/commands/edit.cpp @@ -102,8 +102,6 @@ int edit_config() gConfig().save_config(true); - // make sure we have executables. - std::cout << "Successfully edited config file at " << config_file << std::endl; return 0; } diff --git a/src/commands/install.cpp b/src/commands/install.cpp index 9ac3496..ffdc8ca 100644 --- a/src/commands/install.cpp +++ b/src/commands/install.cpp @@ -243,14 +243,49 @@ namespace dropshell return -1; } + int install_local_agent() + { + std::vector paths = { + gConfig().get_local_template_cache_path(), + gConfig().get_local_backup_path(), + gConfig().get_local_tempfiles_path(), + localpath::agent() + }; + for (auto &p : gConfig().get_local_server_definition_paths()) + paths.push_back(p); + for (auto &p : paths) + if (!std::filesystem::exists(p)) + { + std::cout << "Creating directory: " << p << std::endl; + std::filesystem::create_directories(p); + } + + // download bb64. + if (!std::filesystem::exists(localpath::agent()+"bb64")) + { + std::string cmd = "cd " + localpath::agent() + " && curl -fsSL -o bb64 https://gitea.jde.nz/public/bb64/releases/download/latest/bb64.amd64 && chmod a+x bb64"; + int ret = system(cmd.c_str()); + if (EXITSTATUSCHECK(ret)) + std::cout << "Downloaded bb64 to " << localpath::agent() << std::endl; + else + std::cerr << "Failed to download bb64 to " << localpath::agent() << std::endl; + } else + system((localpath::agent()+"bb64 -u").c_str()); // update. + } int install_host() { // update dropshell. // install the local dropshell agent. - return update_dropshell(); + int rval = update_dropshell(); + if (rval != 0) + return rval; + + rval = install_local_agent(); + if (rval != 0) + return rval; } diff --git a/src/config.cpp b/src/config.cpp index 5c812ad..4588eac 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -61,7 +61,6 @@ bool config::save_config(bool create_aux_directories) std::string dropshell_base = homedir + "/.dropshell"; mConfig["tempfiles"] = dropshell_base + "/tmp"; mConfig["backups"] = dropshell_base + "/backups"; - mConfig["executables"] = dropshell_base + "/executables"; mConfig["template_cache"] = dropshell_base + "/template_cache"; mConfig["template_registry_URLs"] = { @@ -85,8 +84,7 @@ bool config::save_config(bool create_aux_directories) std::vector paths = { get_local_template_cache_path(), get_local_backup_path(), - get_local_tempfiles_path(), - get_local_executables_path() + get_local_tempfiles_path() }; for (auto & p : get_local_server_definition_paths()) paths.push_back(p); @@ -98,18 +96,7 @@ bool config::save_config(bool create_aux_directories) std::filesystem::create_directories(p); } } - - // also make sure the executables are in the path. - std::string executables_path = get_local_executables_path(); - - // download bb64. - std::string cmd = "cd " + executables_path + " && curl -fsSL -o bb64 https://gitea.jde.nz/public/bb64/releases/download/latest/bb64.amd64 && chmod a+x bb64"; - int ret = system(cmd.c_str()); - if (EXITSTATUSCHECK(ret)) - std::cout << "Downloaded bb64 to " << executables_path << std::endl; - else - std::cerr << "Failed to download bb64 to " << executables_path << std::endl; - + return true; } @@ -135,11 +122,6 @@ std::string config::get_local_template_cache_path() { return mConfig["template_cache"]; } -std::string config::get_local_executables_path() -{ - return mConfig["executables"]; -} - std::vector config::get_template_registry_urls() { nlohmann::json template_registry_urls = mConfig["template_registry_URLs"]; std::vector urls; diff --git a/src/config.hpp b/src/config.hpp index 429a70d..3da4d03 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -20,7 +20,6 @@ class config { std::string get_local_tempfiles_path(); std::string get_local_backup_path(); std::string get_local_template_cache_path(); - std::string get_local_executables_path(); std::vector get_template_registry_urls(); std::vector get_template_local_paths(); std::vector get_local_server_definition_paths(); diff --git a/src/utils/directories.hpp b/src/utils/directories.hpp index b555b27..49848a2 100644 --- a/src/utils/directories.hpp +++ b/src/utils/directories.hpp @@ -12,6 +12,7 @@ namespace dropshell { // local user config directories // ~/.config/dropshell/dropshell.json + // ~/.local/dropshell_agent/bb64 // server_definition_path // |-- @@ -27,8 +28,6 @@ namespace dropshell { // temp files path - // executables path - // template cache path // |-- templates // | |-- .json diff --git a/src/utils/execute.cpp b/src/utils/execute.cpp index 4bd48f2..7749cd2 100644 --- a/src/utils/execute.cpp +++ b/src/utils/execute.cpp @@ -25,7 +25,7 @@ namespace dropshell { if (command.get_command_to_run().empty()) return false; - std::string full_command = command.construct_cmd(gConfig().get_local_executables_path()); // Get the command string + std::string full_command = command.construct_cmd(localpath::agent()); // Get the command string pid_t pid = fork(); @@ -56,7 +56,7 @@ namespace dropshell ASSERT(output != nullptr, "Output string must be provided"); if (command.get_command_to_run().empty()) return false; - std::string full_cmd = command.construct_cmd(gConfig().get_local_executables_path()) + " 2>&1"; + std::string full_cmd = command.construct_cmd(localpath::agent()) + " 2>&1"; FILE *pipe = popen(full_cmd.c_str(), "r"); if (!pipe) { @@ -99,7 +99,7 @@ namespace dropshell if (command.get_command_to_run().empty()) return false; bool silent = hasFlag(mode, cMode::Silent); - std::string full_cmd = command.construct_cmd(gConfig().get_local_executables_path()) + " 2>&1" + (silent ? " > /dev/null" : ""); + std::string full_cmd = command.construct_cmd(localpath::agent()) + " 2>&1" + (silent ? " > /dev/null" : ""); int ret = system(full_cmd.c_str()); bool ok = EXITSTATUSCHECK(ret);