From b3398582ca09894f3a0faecb0bf47ed46dc3ce61 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 24 May 2025 13:14:51 +1200 Subject: [PATCH] dropshell release 2025.0524.1314 --- source/src/commands/create-service.cpp | 22 +++++++++++++++++----- source/src/commands/install.cpp | 13 +++++++++---- source/src/services.cpp | 13 +++++++------ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/source/src/commands/create-service.cpp b/source/src/commands/create-service.cpp index 9c82dd2..3a57425 100644 --- a/source/src/commands/create-service.cpp +++ b/source/src/commands/create-service.cpp @@ -152,8 +152,9 @@ namespace dropshell recursive_copy(tinfo.local_template_path() / "config", service_dir); // append TEMPLATE_HASH to the .template_info.env file - std::string template_info_env_file = service_dir + "/" + filenames::template_info_env; - std::ofstream template_info_env_file_out(template_info_env_file); + std::string template_info_env_file = localfile::template_info_env(server_name,service_name); + ASSERT(std::filesystem::exists(template_info_env_file), "Template info env file not found: " + template_info_env_file); + std::ofstream template_info_env_file_out(template_info_env_file, std::ios::app); // append to the file. template_info_env_file_out << "TEMPLATE_HASH=" << tinfo.hash() << std::endl; template_info_env_file_out.close(); @@ -249,9 +250,20 @@ namespace dropshell ASSERT(tinfo.is_set(), "Failed to load template " + service_info.template_name); // copy across .template_info.env file - std::string template_service_env_file = ""; - std::string target_service_env_file = localfile::template_info_env(server_name, service_name); - ASSERT(std::filesystem::exists(template_service_env_file), "Template service env file not found: " + template_service_env_file); + std::string template_info_env_file = tinfo.local_template_path() / "config" / filenames::template_info_env; + std::string target_template_info_env_file = localfile::template_info_env(server_name, service_name); + ASSERT(std::filesystem::exists(template_info_env_file), "Template service env file not found: " + template_info_env_file); + std::filesystem::remove(target_template_info_env_file); + std::filesystem::copy(template_info_env_file, target_template_info_env_file); + + #pragma message("TODO: merge the template info env file") + + // update hash in template info env file + // append TEMPLATE_HASH to the .template_info.env file + ASSERT(std::filesystem::exists(target_template_info_env_file), "Template info env file not found: " + target_template_info_env_file); + std::ofstream template_info_env_file_out(target_template_info_env_file, std::ios::app); // append to the file. + template_info_env_file_out << "TEMPLATE_HASH=" << tinfo.hash() << std::endl; + template_info_env_file_out.close(); return true; } diff --git a/source/src/commands/install.cpp b/source/src/commands/install.cpp index f10591a..ae3de15 100644 --- a/source/src/commands/install.cpp +++ b/source/src/commands/install.cpp @@ -67,10 +67,8 @@ namespace dropshell { std::string server = server_env.get_server_name(); LocalServiceInfo service_info = get_service_info(server_env.get_server_name(), service); - if (!SIvalid(service_info)) - return false; - if (!service_info.service_template_hash_match) + if (!SIvalid(service_info) || !service_info.service_template_hash_match) { warning << "Service " << service << " is using an old template. Updating. " << std::endl; if (!merge_updated_service_template(server_env.get_server_name(), service)) @@ -78,6 +76,13 @@ namespace dropshell error << "Failed to merge updated service template. " << std::endl; return false; } + + service_info = get_service_info(server_env.get_server_name(), service); + if (!SIvalid(service_info) || !service_info.service_template_hash_match) + { + error << "Merged updated service template, but it is still not valid. " << std::endl; + return false; + } } maketitle("Installing " + service + " (" + service_info.template_name + ") on " + server); @@ -276,7 +281,7 @@ namespace dropshell info << "Installing agent for user " << user.user << " on " << server.get_server_name() << std::endl; std::string agent_path = remotepath(server.get_server_name(),user.user).agent(); - ASSERT(agent_path == user.dir, "Agent path does not match user directory for "+user.user+"@" + server.get_server_name() + " : " + agent_path + " != " + user.dir); + ASSERT(agent_path == user.dir+"/agent", "Agent path does not match user directory for "+user.user+"@" + server.get_server_name() + " : " + agent_path + " != " + user.dir); ASSERT(!agent_path.empty(), "Agent path is empty for " + user.user + "@" + server.get_server_name()); // now create the agent. diff --git a/source/src/services.cpp b/source/src/services.cpp index 4100d16..23f5ebf 100644 --- a/source/src/services.cpp +++ b/source/src/services.cpp @@ -14,7 +14,7 @@ namespace fs = std::filesystem; namespace dropshell { -#pragma TODO : Smart test that the service is fully valid. +#pragma message("TODO : Smart test that the service is fully valid.") bool SIvalid(const LocalServiceInfo &service_info) { return !service_info.service_name.empty() && @@ -102,7 +102,7 @@ namespace dropshell auto it = variables.find("TEMPLATE"); if (it == variables.end()) { - error << "Error: TEMPLATE variable not defined in service " << service_name << " on server " << server_name << std::endl; + error << "TEMPLATE variable not defined in service " << service_name << " on server " << server_name << std::endl; return LocalServiceInfo(); } service.template_name = it->second; @@ -136,12 +136,13 @@ namespace dropshell { // determine if the service template hash matches the template hash. auto it = variables.find("TEMPLATE_HASH"); if (it == variables.end()) + error << "Variable TEMPLATE_HASH not found in the service " << filenames::template_info_env << std::endl; + else { - error << "TEMPLATE_HASH variable not defined in service " << service_name << " on server " << server_name << std::endl; - return LocalServiceInfo(); + uint64_t service_template_hash = std::stoull(it->second); + service.service_template_hash_match = (service_template_hash == tinfo.hash()); + //debug << "Service template hash: " << service_template_hash << " == " << tinfo.hash() << std::endl; } - uint64_t service_template_hash = std::stoull(it->second); - service.service_template_hash_match = (service_template_hash == tinfo.hash()); } return service;