feat: Update 2 files
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 44s
Build-Test-Publish / build (linux/arm64) (push) Successful in 1m13s

This commit is contained in:
j842
2025-08-17 22:00:04 +12:00
parent d5bbd16b16
commit e1c002568a
2 changed files with 46 additions and 57 deletions

View File

@@ -40,20 +40,9 @@ trap 'rm -rf "${TEMP_DIR}"' EXIT
curl -L -o "${SOS}" "https://getbin.xyz/sos" curl -L -o "${SOS}" "https://getbin.xyz/sos"
chmod +x "${SOS}" chmod +x "${SOS}"
# Create metadata file with version information # Upload arch-specific binary
METADATA_FILE="${TEMP_DIR}/metadata.json" # sos will automatically run "dropshell version" and store it in metadata
cat > "${METADATA_FILE}" <<EOF "${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/output/${PROJECT}" "${PROJECT}:latest-${ARCH}"
{
"version": "${VERSION}",
"architecture": "${ARCH}",
"project": "${PROJECT}"
}
EOF
# upload arch-specific binary with metadata
# The sos tool should support --metadata flag or similar for version info
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/output/${PROJECT}" "${PROJECT}:latest-${ARCH}" \
--metadata "version=${VERSION}"
# Also upload with version-specific tag for direct version access # Also upload with version-specific tag for direct version access
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/output/${PROJECT}" "${PROJECT}:${VERSION}-${ARCH}" "${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/output/${PROJECT}" "${PROJECT}:${VERSION}-${ARCH}"

View File

@@ -19,6 +19,7 @@
#include <libassert/assert.hpp> #include <libassert/assert.hpp>
#include "servers.hpp" #include "servers.hpp"
#include <sys/stat.h> #include <sys/stat.h>
#include <nlohmann/json.hpp>
namespace dropshell namespace dropshell
{ {
@@ -275,30 +276,25 @@ complete -F _dropshell_completions ds
info << "Current version: " << currentver << std::endl; info << "Current version: " << currentver << std::endl;
info << "Checking for updates..." << std::endl; info << "Checking for updates..." << std::endl;
// Check version using the /version endpoint
// The simple-object-server returns JSON: {"result":"success","version":"YYYY.MMDD.HHMM"}
std::string version_url = "https://getbin.xyz/version/dropshell:latest-" + arch;
shared_commands::cLocalTempFolder local_temp_folder; shared_commands::cLocalTempFolder local_temp_folder;
std::filesystem::path sos_path = local_temp_folder.path() / "sos"; std::filesystem::path version_file = local_temp_folder.path() / "version.json";
// Download sos to check metadata if (download_file(version_url, version_file))
bool should_download = true;
if (!download_file("https://getbin.xyz/sos", sos_path))
{ {
warning << "Failed to download sos utility, proceeding with direct download." << std::endl; try {
} // Read and parse the JSON response
else std::ifstream vf(version_file);
{ nlohmann::json version_json;
chmod(sos_path.c_str(), 0755); vf >> version_json;
// Use sos to get metadata about the remote dropshell binary // Check if the response was successful and has a version field
std::string info_cmd = sos_path.string() + " info getbin.xyz dropshell:latest-" + arch; if (version_json.contains("result") && version_json["result"] == "success" &&
std::string info_output = _exec(info_cmd.c_str()); version_json.contains("version"))
// Parse the version from the info output
// The metadata should contain version in format: "version: YYYY.MMDD.HHMM"
std::size_t version_pos = info_output.find("version: ");
if (version_pos != std::string::npos)
{ {
std::string remote_version = info_output.substr(version_pos + 9); std::string remote_version = version_json["version"];
remote_version = remote_version.substr(0, remote_version.find('\n'));
remote_version = trim(remote_version); remote_version = trim(remote_version);
info << "Latest available version: " << remote_version << std::endl; info << "Latest available version: " << remote_version << std::endl;
@@ -317,13 +313,17 @@ complete -F _dropshell_completions ds
} }
else else
{ {
debug << "Version information not found in metadata, proceeding with download." << std::endl; debug << "Version check failed or version field not found, proceeding with download." << std::endl;
} }
} }
catch (const nlohmann::json::exception& e)
if (!should_download)
{ {
return 0; debug << "Failed to parse version JSON: " << e.what() << ", proceeding with download." << std::endl;
}
}
else
{
warning << "Failed to check version from server, proceeding with download." << std::endl;
} }
// Download new version from getbin.xyz // Download new version from getbin.xyz