diff --git a/publish.sh b/publish.sh index 9d7eaa5..148a35c 100755 --- a/publish.sh +++ b/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}" < #include "servers.hpp" #include +#include 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