From 798e95dca430d23aa770c54c024623db103a1dd5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 12 May 2025 20:59:44 +1200 Subject: [PATCH] bb64 release v13 --- bb64.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ version.h | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/bb64.cpp b/bb64.cpp index 74b78cb..9b74b6d 100644 --- a/bb64.cpp +++ b/bb64.cpp @@ -36,6 +36,18 @@ constexpr unsigned int hash(const char *s, int off = 0) return !s[off] ? 5381 : (hash(s, off + 1) * 33) ^ s[off]; } +std::string get_arch() +{ + // determine the architecture of the system + std::string arch; +#ifdef __aarch64__ + arch = "arm64"; +#elif __x86_64__ + arch = "amd64"; +#endif + return arch; +} + int update_bb64() { std::cout << "Updating bb64..." << std::endl; @@ -44,6 +56,36 @@ int update_bb64() std::filesystem::path bb64_path = std::filesystem::canonical("/proc/self/exe"); std::cout << "bb64 path: " << bb64_path << std::endl; + // determine the architecture of the system + std::string arch = get_arch(); + std::cout << "arch: " << arch << std::endl; + + std::string url = "https://gitea.jde.nz/j/bb64/releases/download/latest/bb64." + arch; + + // make unique temp directory + std::string temp_dir = "/tmp/bb64_" + std::to_string(getpid()); + std::filesystem::create_directories(temp_dir); + + std::string bash_script; + bash_script += "docker run --rm -v " + temp_dir + ":/tmp" + " -v /usr/local/bin:/target"; + bash_script += " alpine/curl:latest"; + bash_script += " sh -c 'curl -fsSL " + url; + bash_script += " -o /tmp/bb64"; + bash_script += " && chmod +x /tmp/bb64"; + bash_script += " && cp /tmp/bb64 /usr/local/bin/bb64"; + bash_script += " && rm -rf /tmp/bb64'"; + + std::cout << "bash_script: " << std::endl + << bash_script << std::endl; + + // run the bash script + int ret = system(bash_script.c_str()); + if (ret != 0) + { + std::cerr << "Failed to update bb64" << std::endl; + return -1; + } + return 0; } diff --git a/version.h b/version.h index 9fdd53b..9ba7c7e 100644 --- a/version.h +++ b/version.h @@ -1 +1 @@ -static const char *VERSION = "12"; +static const char *VERSION = "13";