feat: Update 7 files
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 35s
Build-Test-Publish / build (linux/arm64) (push) Successful in 3m15s

This commit is contained in:
j
2026-01-02 22:27:40 +13:00
parent 767692160d
commit ae5a6fabe9
7 changed files with 95 additions and 2 deletions

View File

@@ -171,6 +171,13 @@ namespace dropshell
// Run all_status.sh on the remote server to get all service statuses in one call
std::string agent_path = remotepath(server_name, user).agent();
std::string script_path = agent_path + "/all_status.sh";
// Pass expected agent hash as argument for version checking
std::string expected_hash = get_local_agent_hash();
if (!expected_hash.empty()) {
script_path += " " + expected_hash;
}
std::string output;
sCommand cmd(agent_path, script_path, {});
@@ -185,6 +192,17 @@ namespace dropshell
try {
nlohmann::json json_response = nlohmann::json::parse(output);
// Check agent hash match
if (json_response.contains("agent_match") && json_response["agent_match"].is_boolean()) {
if (!json_response["agent_match"].get<bool>()) {
std::string remote_hash = json_response.contains("agent_hash") ?
json_response["agent_hash"].get<std::string>() : "unknown";
warning << "Agent mismatch on " << server_name << " (remote: " << remote_hash.substr(0, 8)
<< "..., expected: " << expected_hash.substr(0, 8) << "...)" << std::endl;
warning << "Run 'ds install " << server_name << "' to update the agent" << std::endl;
}
}
if (!json_response.contains("services") || !json_response["services"].is_array()) {
debug << "Invalid JSON response from all_status.sh" << std::endl;
return status;

View File

@@ -312,6 +312,11 @@ namespace dropshell
if (!scommand.has_value())
return false;
// Add agent hash for version checking on remote
std::string agent_hash = get_local_agent_hash();
if (!agent_hash.empty())
scommand->add_env_var("AGENT_HASH", agent_hash);
// add the extra env vars to the command
for (const auto &[key, value] : extra_env_vars)
scommand->add_env_var(key, value);

View File

@@ -4,6 +4,7 @@
#include "output.hpp"
#include <iostream>
#include <fstream>
#include <string>
#include <filesystem>
@@ -37,8 +38,31 @@ namespace dropshell
return localpath::agent_local() + "/bb64";
}
std::string agent_hash()
{
return localpath::agent_remote() + "/agent.hash";
}
} // namespace localfile
std::string get_local_agent_hash()
{
std::string hash_file = localfile::agent_hash();
if (!std::filesystem::exists(hash_file))
return "";
std::ifstream f(hash_file);
if (!f.is_open())
return "";
std::string hash;
std::getline(f, hash);
// Trim whitespace
hash.erase(0, hash.find_first_not_of(" \t\n\r"));
hash.erase(hash.find_last_not_of(" \t\n\r") + 1);
return hash;
}
// ------------------------------------------------------------------------------------------
namespace localpath

View File

@@ -56,8 +56,12 @@ namespace dropshell {
std::string server_json(const std::string &server_name);
std::string service_env(const std::string &server_name, const std::string &service_name);
std::string bb64();
std::string agent_hash(); // Returns path to agent.hash file
} // namespace localfile
// Get the content of the local agent hash (empty string if not found)
std::string get_local_agent_hash();
namespace localpath {
std::string dropshell_dir();