From b260c9813ef1ee458f8c8e3553566b6045325f56 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 13 May 2025 20:16:39 +1200 Subject: [PATCH] Making install work. --- .../remote}/_allservicesstatus.sh | 0 .../shared => agent/remote}/_autocommands.sh | 0 .../shared => agent/remote}/_common.sh | 0 .../remote}/_nuke_other.sh | 0 src/commands/command_registry.cpp | 9 +- src/commands/command_registry.hpp | 3 +- src/commands/help.cpp | 1 + src/commands/install.cpp | 297 ++++++++++-------- src/commands/shared_commands.hpp | 3 +- src/commands/standard_autocomplete.cpp | 9 +- src/config.cpp | 6 +- src/config.hpp | 2 +- src/main.cpp | 6 + src/utils/directories.cpp | 28 +- src/utils/directories.hpp | 6 +- src/utils/execute.cpp | 15 +- src/utils/execute.hpp | 4 +- templates/dropshell-agent/README.txt | 3 - templates/dropshell-agent/_default.env | 1 - .../dropshell-agent/config/.template_info.env | 4 - templates/dropshell-agent/config/service.env | 0 templates/dropshell-agent/install.sh | 60 ---- templates/dropshell-agent/uninstall.sh | 1 - 23 files changed, 224 insertions(+), 234 deletions(-) rename {templates/dropshell-agent/shared => agent/remote}/_allservicesstatus.sh (100%) rename {templates/dropshell-agent/shared => agent/remote}/_autocommands.sh (100%) rename {templates/dropshell-agent/shared => agent/remote}/_common.sh (100%) rename {templates/dropshell-agent => agent/remote}/_nuke_other.sh (100%) delete mode 100644 templates/dropshell-agent/README.txt delete mode 100644 templates/dropshell-agent/_default.env delete mode 100644 templates/dropshell-agent/config/.template_info.env delete mode 100644 templates/dropshell-agent/config/service.env delete mode 100755 templates/dropshell-agent/install.sh delete mode 100755 templates/dropshell-agent/uninstall.sh diff --git a/templates/dropshell-agent/shared/_allservicesstatus.sh b/agent/remote/_allservicesstatus.sh similarity index 100% rename from templates/dropshell-agent/shared/_allservicesstatus.sh rename to agent/remote/_allservicesstatus.sh diff --git a/templates/dropshell-agent/shared/_autocommands.sh b/agent/remote/_autocommands.sh similarity index 100% rename from templates/dropshell-agent/shared/_autocommands.sh rename to agent/remote/_autocommands.sh diff --git a/templates/dropshell-agent/shared/_common.sh b/agent/remote/_common.sh similarity index 100% rename from templates/dropshell-agent/shared/_common.sh rename to agent/remote/_common.sh diff --git a/templates/dropshell-agent/_nuke_other.sh b/agent/remote/_nuke_other.sh similarity index 100% rename from templates/dropshell-agent/_nuke_other.sh rename to agent/remote/_nuke_other.sh diff --git a/src/commands/command_registry.cpp b/src/commands/command_registry.cpp index b82d6ad..6798a19 100644 --- a/src/commands/command_registry.cpp +++ b/src/commands/command_registry.cpp @@ -1,5 +1,6 @@ #include "command_registry.hpp" #include "utils/utils.hpp" +#include "config.hpp" namespace dropshell { @@ -37,7 +38,13 @@ std::vector CommandRegistry::list_primary_commands(bool include_hid for (const auto& cmd : all_commands_) { if (!cmd->hidden || include_hidden) { if (cmd->names.size() > 0) - out.insert(cmd->names[0]); + { + if (cmd->requires_config && !gConfig().is_config_set()) + continue; + if (cmd->requires_install && !gConfig().is_agent_installed()) + continue; + out.insert(cmd->names[0]); + } } } return std::vector(out.begin(), out.end()); diff --git a/src/commands/command_registry.hpp b/src/commands/command_registry.hpp index a59cfe9..114e098 100644 --- a/src/commands/command_registry.hpp +++ b/src/commands/command_registry.hpp @@ -24,7 +24,8 @@ struct CommandInfo { std::function handler; std::function autocomplete; // optional bool hidden = false; - bool requires_config = false; + bool requires_config = true; + bool requires_install = true; int min_args = 0; int max_args = -1; // -1 = unlimited std::string help_usage; // install SERVER [SERVICE] diff --git a/src/commands/help.cpp b/src/commands/help.cpp index e2fba72..6a054bd 100644 --- a/src/commands/help.cpp +++ b/src/commands/help.cpp @@ -28,6 +28,7 @@ struct HelpCommandRegister { help_autocomplete, false, // hidden false, // requires_config + false, // requires_install 0, // min_args (after command) 1, // max_args (after command) "help [COMMAND]", diff --git a/src/commands/install.cpp b/src/commands/install.cpp index 4636792..097341a 100644 --- a/src/commands/install.cpp +++ b/src/commands/install.cpp @@ -12,151 +12,178 @@ #include #include -namespace dropshell { +namespace dropshell +{ -int install_handler(const CommandContext& ctx); + int install_handler(const CommandContext &ctx); -static std::vector install_name_list={"install"}; + static std::vector install_name_list = {"install"}; -// Static registration -struct InstallCommandRegister { - InstallCommandRegister() { - CommandRegistry::instance().register_command({ - install_name_list, - install_handler, - std_autocomplete, - false, // hidden - false, // requires_config - 1, // min_args (after command) - 2, // max_args (after command) - "install SERVER [SERVICE]", - "Install/reinstall/update service(s). Safe/non-destructive.", - // heredoc - R"( - Install a service(s) on a server. - install (re)install the given service on the given server. - install (re)install all configured services on the given server. + // Static registration + struct InstallCommandRegister + { + InstallCommandRegister() + { + CommandRegistry::instance().register_command({install_name_list, + install_handler, + std_autocomplete_allowallservices, + false, // hidden + false, // requires_config + false, // requires_install + 1, // min_args (after command) + 2, // max_args (after command) + "install SERVER [SERVICE]", + "Install/reinstall/update service(s). Safe/non-destructive.", + // heredoc + R"( + Install components on a server. This is safe to re-run (non-destructive) and used to update + servers and their services. + + install (re)install dropshell components on this computer. + install SERVER (re)install dropshell agent on the given server. + install SERVER [SERVICE|*] (re)install the given service (or all services) on the given server. Note you need to create the service first with: dropshell create-service