feat: Update 2 files
This commit is contained in:
17
publish.sh
17
publish.sh
@@ -40,20 +40,9 @@ trap 'rm -rf "${TEMP_DIR}"' EXIT
|
||||
curl -L -o "${SOS}" "https://getbin.xyz/sos"
|
||||
chmod +x "${SOS}"
|
||||
|
||||
# Create metadata file with version information
|
||||
METADATA_FILE="${TEMP_DIR}/metadata.json"
|
||||
cat > "${METADATA_FILE}" <<EOF
|
||||
{
|
||||
"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}"
|
||||
# Upload arch-specific binary
|
||||
# sos will automatically run "dropshell version" and store it in metadata
|
||||
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/output/${PROJECT}" "${PROJECT}:latest-${ARCH}"
|
||||
|
||||
# Also upload with version-specific tag for direct version access
|
||||
"${SOS}" upload "getbin.xyz" "${SCRIPT_DIR}/output/${PROJECT}" "${PROJECT}:${VERSION}-${ARCH}"
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include <libassert/assert.hpp>
|
||||
#include "servers.hpp"
|
||||
#include <sys/stat.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace dropshell
|
||||
{
|
||||
@@ -275,55 +276,54 @@ complete -F _dropshell_completions ds
|
||||
info << "Current version: " << currentver << 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;
|
||||
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
|
||||
bool should_download = true;
|
||||
if (!download_file("https://getbin.xyz/sos", sos_path))
|
||||
if (download_file(version_url, version_file))
|
||||
{
|
||||
warning << "Failed to download sos utility, proceeding with direct download." << std::endl;
|
||||
try {
|
||||
// Read and parse the JSON response
|
||||
std::ifstream vf(version_file);
|
||||
nlohmann::json version_json;
|
||||
vf >> version_json;
|
||||
|
||||
// Check if the response was successful and has a version field
|
||||
if (version_json.contains("result") && version_json["result"] == "success" &&
|
||||
version_json.contains("version"))
|
||||
{
|
||||
std::string remote_version = version_json["version"];
|
||||
remote_version = trim(remote_version);
|
||||
|
||||
info << "Latest available version: " << remote_version << std::endl;
|
||||
|
||||
// Compare versions (both in YYYY.MMDD.HHMM format)
|
||||
if (!remote_version.empty() && currentver >= remote_version)
|
||||
{
|
||||
info << "Dropshell is already up to date." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!remote_version.empty() && currentver < remote_version)
|
||||
{
|
||||
info << "New version available, downloading..." << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
debug << "Version check failed or version field not found, proceeding with download." << std::endl;
|
||||
}
|
||||
}
|
||||
catch (const nlohmann::json::exception& e)
|
||||
{
|
||||
debug << "Failed to parse version JSON: " << e.what() << ", proceeding with download." << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
chmod(sos_path.c_str(), 0755);
|
||||
|
||||
// Use sos to get metadata about the remote dropshell binary
|
||||
std::string info_cmd = sos_path.string() + " info getbin.xyz dropshell:latest-" + arch;
|
||||
std::string info_output = _exec(info_cmd.c_str());
|
||||
|
||||
// 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);
|
||||
remote_version = remote_version.substr(0, remote_version.find('\n'));
|
||||
remote_version = trim(remote_version);
|
||||
|
||||
info << "Latest available version: " << remote_version << std::endl;
|
||||
|
||||
// Compare versions (both in YYYY.MMDD.HHMM format)
|
||||
if (!remote_version.empty() && currentver >= remote_version)
|
||||
{
|
||||
info << "Dropshell is already up to date." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!remote_version.empty() && currentver < remote_version)
|
||||
{
|
||||
info << "New version available, downloading..." << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
debug << "Version information not found in metadata, proceeding with download." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (!should_download)
|
||||
{
|
||||
return 0;
|
||||
warning << "Failed to check version from server, proceeding with download." << std::endl;
|
||||
}
|
||||
|
||||
// Download new version from getbin.xyz
|
||||
|
Reference in New Issue
Block a user