#include "command_registry.hpp" #include "shared_commands.hpp" #include "config.hpp" #include "services.hpp" #include "server_env_manager.hpp" #include "utils/directories.hpp" #include "servers.hpp" #include "templates.hpp" #include #pragma TODO("Fix issues with Nuke below.") /* j@twelve:~/code/dropshell$ ds nuke localhost test-squashkiwi --------------------------------------- | Nuking test-squashkiwi on localhost | --------------------------------------- --------------------------------------------- | Uninstalling test-squashkiwi on localhost | --------------------------------------------- Service is not installed: test-squashkiwi bash: line 1: cd: /home/dropshell/dropshell_deploy/services/test-squashkiwi/template: Permission denied bash: line 1: /home/dropshell/dropshell_deploy/services/test-squashkiwi/template/nuke.sh: Permission denied Warning: Failed to run nuke script: test-squashkiwi */ namespace dropshell { int nuke_handler(const CommandContext& ctx); static std::vector nuke_name_list={"nuke"}; // Static registration struct NukeCommandRegister { NukeCommandRegister() { CommandRegistry::instance().register_command({ nuke_name_list, nuke_handler, std_autocomplete, false, // hidden true, // requires_config 2, // min_args (after command) 2, // max_args (after command) "nuke SERVER SERVICE", "Nuke a service on a server. Destroys everything, both local and remote!", // heredoc R"( Nuke a service on a server. Destroys everything, both local and remote! nuke nuke the given service on the given server. )" }); } } nuke_command_register; int nuke_handler(const CommandContext &ctx) { ASSERT(ctx.args.size() > 1, "Usage: nuke "); ASSERT(gConfig().is_config_set(), "No configuration found. Please run 'dropshell config' to set up your configuration."); std::string server = safearg(ctx.args, 0); std::string service = safearg(ctx.args, 1); maketitle("Nuking " + service + " on " + server); server_env_manager server_env(server); LocalServiceInfo service_info; if (server_env.is_valid()) { service_info = get_service_info(server, service); if (!SIvalid(service_info)) std::cerr << "Warning: Invalid service: " << service << std::endl; if (!uninstall_service(server, service, false)) std::cerr << "Warning: Failed to uninstall service: " << service << std::endl; // run the nuke script on the remote server if it exists. if (gTemplateManager().template_command_exists(service_info.template_name, "nuke")) { if (!server_env.run_remote_template_command(service, "nuke", {}, false, {})) std::cerr << "Warning: Failed to run nuke script: " << service << std::endl; } } else std::cerr << "Warning: Invalid server: " << server << std::endl; // remove the local service directory std::string local_service_path = service_info.local_service_path; if (local_service_path.empty() || !std::filesystem::exists(local_service_path)) { std::cerr << "Warning: Local service directory not found: " << local_service_path << std::endl; return 1; } auto ret = std::filesystem::remove_all(local_service_path); if (ret != 0) std::cerr << "Warning: Failed to remove local service directory" << std::endl; return ret == 0 ? 0 : 1; } } // namespace dropshell