From c836b266576c5d2531aeb70956459d0fa7aab784 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 27 May 2025 22:01:51 +1200 Subject: [PATCH] dropshell release 2025.0527.2201 --- source/agent-remote/agent-install.sh | 6 +++++ source/src/commands/edit.cpp | 31 ++++++++++++++++++++++++- source/src/commands/install.cpp | 34 ++++++++++++++++------------ source/src/servers.cpp | 2 ++ 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/source/agent-remote/agent-install.sh b/source/agent-remote/agent-install.sh index 97972be..4f1e608 100755 --- a/source/agent-remote/agent-install.sh +++ b/source/agent-remote/agent-install.sh @@ -53,6 +53,12 @@ if ! command -v docker &> /dev/null; then exit 1 fi +# check rsync installation +if ! command -v rsync &> /dev/null; then + echo "Rsync is not installed. Rsync is required for agent installation." + exit 1 +fi + #------------------------------------------------------------------------- diff --git a/source/src/commands/edit.cpp b/source/src/commands/edit.cpp index 41eb7b6..312bd9c 100644 --- a/source/src/commands/edit.cpp +++ b/source/src/commands/edit.cpp @@ -130,6 +130,28 @@ int edit_server(const std::string &server_name) return 0; } +void list_directory(std::string dir, std::string msg) +{ + bool first=true; + std::vector directories; + for (const auto &file : std::filesystem::directory_iterator(dir)) + { + if (first) + { + if (!msg.empty()) + info << msg << std::endl; + first=false; + } + if (std::filesystem::is_directory(file.path())) + directories.push_back(file.path()); + else + info << " " << file.path() << std::endl; + } + + for (const auto &dir : directories) + list_directory(dir, ""); +} + // ------------------------------------------------------------------------------------------------ // edit service config // ------------------------------------------------------------------------------------------------ @@ -143,7 +165,14 @@ int edit_service_config(const std::string &server, const std::string &service) } if (edit_file(config_file, true) && std::filesystem::exists(config_file)) - info << "To apply your changes, run:\n dropshell install " + server + " " + service << std::endl; + info << "Successfully edited service config file at " << config_file << std::endl; + + std::string service_dir = localpath::service(server, service); + list_directory(service_dir, "You may wish to edit the other files in " + service_dir); + + info << "Then to apply your changes, run:" << std::endl; + info << " dropshell uninstall " + server + " " + service << std::endl; + info << " dropshell install " + server + " " + service << std::endl; return 0; } diff --git a/source/src/commands/install.cpp b/source/src/commands/install.cpp index 06e4a84..819241c 100644 --- a/source/src/commands/install.cpp +++ b/source/src/commands/install.cpp @@ -69,7 +69,26 @@ 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) || !service_info.service_template_hash_match) + if (!SIvalid(service_info)) + { + error << "Failed to install - service information not valid." << std::endl; + return false; + } + + if (!server_env.is_valid()) + return false; // should never hit this. + + + std::string user = server_env.get_user_for_service(service); + std::string remote_service_path = remotepath(server,user).service(service); + + if (server_env.check_remote_dir_exists(remote_service_path, user)) + { // uninstall the old service before we update the config or template! + info << "Service " << service << " is already installed on " << server << std::endl; + shared_commands::uninstall_service(server_env, service); + } + + if (!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)) @@ -88,9 +107,6 @@ namespace dropshell maketitle("Installing " + service + " (" + service_info.template_name + ") on " + server); - if (!server_env.is_valid()) - return false; // should never hit this. - // Check if template exists template_info tinfo = gTemplateManager().get_template_info(service_info.template_name); if (!tinfo.is_set()) @@ -103,8 +119,6 @@ namespace dropshell } // Create service directory - std::string user = server_env.get_user_for_service(service); - std::string remote_service_path = remotepath(server,user).service(service); std::string mkdir_cmd = "mkdir -p " + quote(remote_service_path); if (!execute_ssh_command(server_env.get_SSH_INFO(user), sCommand("", mkdir_cmd, {}), cMode::Silent)) { @@ -112,14 +126,6 @@ namespace dropshell return false; } - // Check if rsync is installed on remote host - std::string check_rsync_cmd = "which rsync"; - if (!execute_ssh_command(server_env.get_SSH_INFO(user), sCommand("", check_rsync_cmd, {}), cMode::Silent)) - { - std::cerr << "rsync is not installed on the remote host" << std::endl; - return false; - } - // Copy template files debug << "Copying: [LOCAL] " << tinfo.local_template_path() << std::endl << std::string(8, ' ') << "[REMOTE] " << remotepath(server,user).service_template(service) << "/" << std::endl; diff --git a/source/src/servers.cpp b/source/src/servers.cpp index 430fb66..cd78781 100644 --- a/source/src/servers.cpp +++ b/source/src/servers.cpp @@ -345,6 +345,8 @@ namespace dropshell return std::nullopt; } + env_vars["HOST_NAME"] = get_SSH_HOST(); + std::string argstr = ""; for (const auto &arg : args) {