From d95500f679b2337cd13c9ac102d5269e49c7f4aa Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 26 Apr 2025 21:57:26 +1200 Subject: [PATCH] hmm --- src/servers.cpp | 10 ++++++---- src/services.cpp | 44 ++++++++++++++++++++++++++++---------------- src/services.hpp | 2 +- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/servers.cpp b/src/servers.cpp index ff70659..0991680 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -170,10 +170,12 @@ void create_server(const std::string &server_name) server_env_file.close(); // 4. add dropshell-agent service to server - std::string service_dir = server_dir + "/dropshell-agent"; - std::filesystem::create_directory(service_dir); - std::string service_env_path = service_dir + "/service.env"; - std::filesystem::copy(get_local_system_templates_path() + "/dropshell-agent/example/service.env", service_env_path); + create_service(server_name, "dropshell-agent", "dropshell-agent", true); // silently create service. + + // std::string service_dir = server_dir + "/dropshell-agent"; + // std::filesystem::create_directory(service_dir); + // std::string service_env_path = service_dir + "/service.env"; + // std::filesystem::copy(get_local_system_templates_path() + "/dropshell-agent/example/service.env", service_env_path); std::cout << "Server created successfully: " << server_name << std::endl; std::cout << "Please complete the installation:" < list_backups(const std::string &service_name) return backups; } -bool create_service(const std::string &server_name, const std::string &template_name, const std::string &service_name) +bool create_service(const std::string &server_name, const std::string &template_name, const std::string &service_name, bool silent) { if (server_name.empty() || template_name.empty() || service_name.empty()) return false; @@ -143,27 +143,36 @@ bool create_service(const std::string &server_name, const std::string &template_ if (service_dir.empty()) { - std::cerr << "Error: Couldn't locate server " << server_name << " in any config directory" << std::endl; - std::cerr << "Please check the server name is correct and try again" << std::endl; - std::cerr << "You can list all servers with 'dropshell servers'" << std::endl; - std::cerr << "You can create a new server with 'dropshell create-server " << server_name << "'" << std::endl; + if (!silent) + { + std::cerr << "Error: Couldn't locate server " << server_name << " in any config directory" << std::endl; + std::cerr << "Please check the server name is correct and try again" << std::endl; + std::cerr << "You can list all servers with 'dropshell servers'" << std::endl; + std::cerr << "You can create a new server with 'dropshell create-server " << server_name << "'" << std::endl; + } return false; } if (fs::exists(service_dir)) { - std::cerr << "Error: Service already exists: " << service_name << std::endl; - std::cerr << "Current service path: " << service_dir << std::endl; + if (!silent) + { + std::cerr << "Error: Service already exists: " << service_name << std::endl; + std::cerr << "Current service path: " << service_dir << std::endl; + } return false; } template_info tinfo; if (!get_template_info(template_name, tinfo)) { - std::cerr << "Error: Template '" << template_name << "' not found" << std::endl; - std::cerr << "Please check the template name is correct and try again" << std::endl; - std::cerr << "You can list all templates with 'dropshell templates'" << std::endl; - std::cerr << "You can create a new template with 'dropshell create-template " << template_name << "'" << std::endl; + if (!silent) + { + std::cerr << "Error: Template '" << template_name << "' not found" << std::endl; + std::cerr << "Please check the template name is correct and try again" << std::endl; + std::cerr << "You can list all templates with 'dropshell templates'" << std::endl; + std::cerr << "You can create a new template with 'dropshell create-template " << template_name << "'" << std::endl; + } return false; } @@ -173,11 +182,14 @@ bool create_service(const std::string &server_name, const std::string &template_ // copy the template example files to the service directory recursive_copy(tinfo.local_template_path+"/example", service_dir); - std::cout << "Service " << service_name <<" created successfully"< list_backups(const std::string& service_name); - bool create_service(const std::string& server_name, const std::string& template_name, const std::string& service_name); + bool create_service(const std::string& server_name, const std::string& template_name, const std::string& service_name, bool silent=false); } // namespace dropshell