bb64 release v13
This commit is contained in:
parent
90c22fea00
commit
798e95dca4
42
bb64.cpp
42
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user