code tidying
This commit is contained in:
parent
32da3d5fbc
commit
194bde1a0d
8
debian/changelog
vendored
8
debian/changelog
vendored
@ -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
|
15
debian/control
vendored
15
debian/control
vendored
@ -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.
|
26
debian/copyright
vendored
26
debian/copyright
vendored
@ -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.
|
14
debian/rules
vendored
14
debian/rules
vendored
@ -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
|
@ -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<<makesafecmd(safearg(argc,argv,2))<<std::endl)
|
||||
HAPPYEXIT("version", printversion())
|
||||
BOOLEXIT("test-template", test_template(safearg(argc,argv,2)))
|
||||
ASSERT_MSG(safearg(argc,argv,1) != "assert", "Hello! Here is an assert.");
|
||||
|
||||
try {
|
||||
|
@ -209,18 +209,15 @@ void get_all_service_env_vars(const std::string &server_name, const std::string
|
||||
all_env_vars["SERVER"] = server_name;
|
||||
all_env_vars["SERVICE"] = service_name;
|
||||
|
||||
std::vector<std::string> 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.
|
||||
for (const auto& file : env_files) {
|
||||
// load service.env from the service on this machine.
|
||||
std::map<std::string, std::string> 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<std::string, std::string> env_vars;
|
||||
envmanager env_manager(localfile::template_info_env(server_name,service_name));
|
||||
envmanager env_manager(file);
|
||||
env_manager.load();
|
||||
env_manager.get_all_variables(env_vars);
|
||||
all_env_vars.merge(env_vars);
|
||||
@ -229,10 +226,11 @@ void get_all_service_env_vars(const std::string &server_name, const std::string
|
||||
// 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
|
||||
|
@ -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<std::string, std::string> & all_env_vars);
|
||||
|
||||
|
||||
// list all backups for a given service (across all servers)
|
||||
std::set<std::string> list_backups(const std::string& server_name, const std::string& service_name);
|
||||
|
||||
|
@ -1,7 +1,3 @@
|
||||
#include "templates.hpp"
|
||||
#include "config.hpp"
|
||||
#include "utils/directories.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
@ -9,6 +5,13 @@
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
|
||||
#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<std::string> 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<std::string, std::string> all_env_vars;
|
||||
std::vector<std::string> 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<std::string, std::string> 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
|
||||
|
@ -33,4 +33,7 @@ class template_info {
|
||||
|
||||
bool get_all_template_config_directories(std::vector<std::string>& template_config_directories);
|
||||
|
||||
|
||||
bool test_template(const std::string& template_path);
|
||||
|
||||
} // namespace dropshell
|
||||
|
Loading…
x
Reference in New Issue
Block a user