From 194bde1a0d2915f2b8477d073877758ac06f31d1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 30 Apr 2025 20:46:18 +1200 Subject: [PATCH] code tidying --- debian/changelog | 8 -- debian/control | 15 ---- debian/copyright | 26 ------- debian/rules | 14 ---- .../{builld_builder.sh => build_builder.sh} | 0 src/main.cpp | 2 + src/services.cpp | 29 ++++---- src/services.hpp | 1 - src/templates.cpp | 74 ++++++++++++++++++- src/templates.hpp | 3 + 10 files changed, 88 insertions(+), 84 deletions(-) delete mode 100644 debian/changelog delete mode 100644 debian/control delete mode 100644 debian/copyright delete mode 100644 debian/rules rename docker/{builld_builder.sh => build_builder.sh} (100%) diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index 19d106b..0000000 --- a/debian/changelog +++ /dev/null @@ -1,8 +0,0 @@ -dropshell (1.0.0-1) unstable; urgency=medium - - * Initial release. - * Converted from bash script to C++ implementation - * Added proper system status monitoring - * Improved server management functionality - - -- j842 Sun, 21 Apr 2025 12:00:00 +0000 \ No newline at end of file diff --git a/debian/control b/debian/control deleted file mode 100644 index 861aa18..0000000 --- a/debian/control +++ /dev/null @@ -1,15 +0,0 @@ -Source: dropshell -Section: utils -Priority: optional -Maintainer: j842 -Build-Depends: debhelper (>= 10), cmake, libboost-all-dev -Standards-Version: 4.5.0 -Homepage: https://github.com/j842/dropshell - -Package: dropshell -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, libboost-program-options1.74.0, libboost-filesystem1.74.0, libboost-system1.74.0 -Description: A system management tool for server operations - dropshell is a command-line tool for managing and monitoring servers. - It provides functionality for checking system status, managing server - configurations, and performing common administrative tasks. \ No newline at end of file diff --git a/debian/copyright b/debian/copyright deleted file mode 100644 index 73c95d3..0000000 --- a/debian/copyright +++ /dev/null @@ -1,26 +0,0 @@ -Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: dropshell -Source: https://github.com/j842/dropshell - -Files: * -Copyright: 2025 j842 -License: MIT - -License: MIT - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - . - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - . - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. \ No newline at end of file diff --git a/debian/rules b/debian/rules deleted file mode 100644 index e3fcd10..0000000 --- a/debian/rules +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/make -f - -%: - dh $@ - -override_dh_auto_configure: - dh_auto_configure -- -DCMAKE_BUILD_TYPE=Release - -override_dh_auto_install: - dh_auto_install - # Install bash completion - install -D -m 644 src/dropshell-completion.bash debian/dropshell/etc/bash_completion.d/dropshell - # Install configuration - install -D -m 644 src/dropshell.conf debian/dropshell/etc/dropshell.conf \ No newline at end of file diff --git a/docker/builld_builder.sh b/docker/build_builder.sh similarity index 100% rename from docker/builld_builder.sh rename to docker/build_builder.sh diff --git a/src/main.cpp b/src/main.cpp index b3e3f90..d2a4d73 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -97,11 +97,13 @@ void printversion() { } #define HAPPYEXIT(CMD, RUNCMD) {if (safearg(argc,argv,1) == CMD) {RUNCMD; return 0;}} +#define BOOLEXIT(CMD, RUNCMD) {if (safearg(argc,argv,1) == CMD) {return (RUNCMD) ? 0 : 1;}} int main(int argc, char* argv[]) { HAPPYEXIT("hash", hash_demo_raw(safearg(argc,argv,2))) HAPPYEXIT("makesafecmd", std::cout< env_files = { + localfile::service_env(server_name,service_name), + localfile::template_info_env(server_name,service_name) + }; - { // load service.env from the service on this machine. - std::map env_vars; - envmanager env_manager(localfile::service_env(server_name,service_name)); - env_manager.load(); - env_manager.get_all_variables(env_vars); - all_env_vars.merge(env_vars); - } - - { // load .template_info.env from the service on this machine. - std::map env_vars; - envmanager env_manager(localfile::template_info_env(server_name,service_name)); - env_manager.load(); - env_manager.get_all_variables(env_vars); - all_env_vars.merge(env_vars); + for (const auto& file : env_files) { + // load service.env from the service on this machine. + std::map env_vars; + envmanager env_manager(file); + env_manager.load(); + env_manager.get_all_variables(env_vars); + all_env_vars.merge(env_vars); } // determine template name. auto it = all_env_vars.find("TEMPLATE"); if (it == all_env_vars.end()) { + std::cerr << std::endl << std::endl; std::cerr << "Error: TEMPLATE variable not defined in service " << service_name << " on server " << server_name << std::endl; std::cerr << "The TEMPLATE variable is required to determine the template name." << std::endl; std::cerr << "Please check the service.env file and the .template_info.env file in:" << std::endl; - std::cerr << " " << localpath::service(server_name, service_name) << std::endl; + std::cerr << " " << localpath::service(server_name, service_name) << std::endl << std::endl; return; } std::string template_name = it->second; @@ -257,5 +255,4 @@ void get_all_service_env_vars(const std::string &server_name, const std::string } - } // namespace dropshell diff --git a/src/services.hpp b/src/services.hpp index 3f75ed5..6727a91 100644 --- a/src/services.hpp +++ b/src/services.hpp @@ -22,7 +22,6 @@ namespace dropshell { // get all env vars for a given service void get_all_service_env_vars(const std::string& server_name, const std::string& service_name, std::map & all_env_vars); - // list all backups for a given service (across all servers) std::set list_backups(const std::string& server_name, const std::string& service_name); diff --git a/src/templates.cpp b/src/templates.cpp index 15b1e42..f46dcef 100644 --- a/src/templates.cpp +++ b/src/templates.cpp @@ -1,7 +1,3 @@ - #include "templates.hpp" - #include "config.hpp" - #include "utils/directories.hpp" - #include "utils/utils.hpp" #include #include #include @@ -9,6 +5,13 @@ #include #include #include + #include + + #include "utils/envmanager.hpp" + #include "utils/directories.hpp" + #include "utils/utils.hpp" + #include "templates.hpp" + #include "config.hpp" namespace dropshell { @@ -189,4 +192,67 @@ return true; } + bool required_file(std::string path, std::string template_name) + { + if (!std::filesystem::exists(path)) { + std::cerr << "Error: " << path << " file not found in template " << template_name << std::endl; + return false; + } + return true; + } + + bool test_template(const std::string &template_path) + { + std::string template_name = std::filesystem::path(template_path).filename().string(); + + std::vector required_files = { + "example/service.env", + "example/.template_info.env", + "_default.env", + "install.sh", + "uninstall.sh" + }; + + for (const auto& file : required_files) { + if (!required_file(template_path + "/" + file, template_name)) + return false; + } + + // ------------------------------------------------------------ + // check TEMPLATE= line. + std::map all_env_vars; + std::vector env_files = { + "example/service.env", + "example/.template_info.env" + }; + for (const auto& file : env_files) { + { // load service.env from the service on this machine. + std::map env_vars; + envmanager env_manager(template_path + "/" + file); + env_manager.load(); + env_manager.get_all_variables(env_vars); + all_env_vars.merge(env_vars); + } + + // determine template name. + auto it = all_env_vars.find("TEMPLATE"); + if (it == all_env_vars.end()) { + std::cerr << "Error: TEMPLATE variable not found in " << file << std::endl; + return false; + } + + std::string env_template_name = it->second; + if (env_template_name.empty()) { + std::cerr << "Error: TEMPLATE variable is empty in " << file << std::endl; + return false; + } + + if (env_template_name != template_name) { + std::cerr << "Error: TEMPLATE variable is wrong in " << file << std::endl; + return false; + } + + return true; + } + } // namespace dropshell diff --git a/src/templates.hpp b/src/templates.hpp index fc44d36..b0649b7 100644 --- a/src/templates.hpp +++ b/src/templates.hpp @@ -33,4 +33,7 @@ class template_info { bool get_all_template_config_directories(std::vector& template_config_directories); + + bool test_template(const std::string& template_path); + } // namespace dropshell