tidying
This commit is contained in:
parent
3c50260ed3
commit
c6665f3044
@ -28,7 +28,6 @@ configure_file(
|
||||
)
|
||||
|
||||
# Find required packages
|
||||
find_package(Boost REQUIRED COMPONENTS program_options filesystem system)
|
||||
find_package(Curses REQUIRED)
|
||||
find_package(TBB REQUIRED)
|
||||
|
||||
|
@ -41,7 +41,7 @@ print_status "Detected OS: $OS $VER"
|
||||
case $OS in
|
||||
"Ubuntu"|"Debian GNU/Linux")
|
||||
# Common packages for both Ubuntu and Debian
|
||||
PACKAGES="cmake make g++ libboost-all-dev devscripts debhelper"
|
||||
PACKAGES="cmake make g++ devscripts debhelper libtbb-dev"
|
||||
;;
|
||||
*)
|
||||
print_error "Unsupported distribution: $OS"
|
||||
@ -82,11 +82,17 @@ for tool in cmake make g++; do
|
||||
fi
|
||||
done
|
||||
|
||||
# Check Boost installation
|
||||
if [ ! -d "/usr/include/boost" ]; then
|
||||
print_error "Boost headers not found"
|
||||
# Check TBB installation
|
||||
if [ ! -d "/usr/include/tbb" ]; then
|
||||
print_error "TBB headers not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# # Check Boost installation
|
||||
# if [ ! -d "/usr/include/boost" ]; then
|
||||
# print_error "Boost headers not found"
|
||||
# exit 1
|
||||
# fi
|
||||
|
||||
print_status "All dependencies installed successfully!"
|
||||
print_status "You can now run ./build.sh to build the project"
|
@ -22,7 +22,7 @@ config::~config() {
|
||||
}
|
||||
|
||||
bool config::load_config() {
|
||||
std::string config_path = get_local_dropshell_config_path();
|
||||
std::string config_path = get_local_dropshell_config_file();
|
||||
if (config_path.empty() || !std::filesystem::exists(config_path))
|
||||
return false;
|
||||
|
||||
@ -56,7 +56,10 @@ void config::save_config()
|
||||
return;
|
||||
}
|
||||
|
||||
std::string config_path = get_local_dropshell_config_path();
|
||||
std::string parent_path = get_local_dropshell_config_parent_path();
|
||||
std::filesystem::create_directories(parent_path);
|
||||
|
||||
std::string config_path = get_local_dropshell_config_file();
|
||||
envmanager config_env(config_path);
|
||||
|
||||
config_env.set_variable("local.config.directories", multi2string(mLocalConfigPaths));
|
||||
|
23
src/main.cpp
23
src/main.cpp
@ -10,6 +10,7 @@
|
||||
#include "autocomplete.hpp"
|
||||
#include "main_commands.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -25,7 +26,9 @@ void print_help() {
|
||||
std::cout << std::endl;
|
||||
std::cout << "dropshell ..." << std::endl;
|
||||
std::cout << " help Show this help message" << std::endl;
|
||||
std::cout << " init DIR Add DIR as a local configuration directory for dropshell (can add several)" << std::endl;
|
||||
std::cout << " init DIR Add DIR as a local server config directory (can add several)" << std::endl;
|
||||
|
||||
if (get_global_config()->is_config_set()) {
|
||||
std::cout << " server NAME Show details for specific server" << std::endl;
|
||||
std::cout << " templates List all available templates" << std::endl;
|
||||
std::cout << std::endl;
|
||||
@ -44,6 +47,12 @@ void print_help() {
|
||||
std::cout << " create-template TEMPLATE" << std::endl;
|
||||
std::cout << " create-server SERVER" << std::endl;
|
||||
std::cout << " create-service SERVER TEMPLATE SERVICE" << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cout << " edit Edit the configuration of dropshell" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Other commands available once initialised." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
||||
@ -99,6 +108,12 @@ int main(int argc, char* argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cmd == "edit" && argc < 3) {
|
||||
std::filesystem::create_directories(dropshell::get_local_dropshell_config_parent_path());
|
||||
dropshell::edit_file(dropshell::get_local_dropshell_config_file(), "Please ensure any directories you have introduced in the config file exist.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// from here we require the config file to be loaded.
|
||||
if (!cfg->is_config_set()) {
|
||||
@ -173,10 +188,8 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
if (cmd == "edit" && argc < 4) {
|
||||
if (argc < 3)
|
||||
dropshell::edit_file(dropshell::get_local_dropshell_config_path(), "Please ensure any directories you have introduced in the config file exist.");
|
||||
else
|
||||
dropshell::edit_server(argv[2]);
|
||||
ASSERT_ALWAYS(argc>=3);
|
||||
dropshell::edit_server(argv[2]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ int init(const std::vector<std::string> &args)
|
||||
}
|
||||
try {
|
||||
if (!cfg->add_local_config_directory(args[2]))
|
||||
return 1; // error already reported
|
||||
return 1; // error already reported
|
||||
|
||||
cfg->save_config();
|
||||
std::cout << "Config directory added: " << cfg->get_local_config_directories().back() << std::endl;
|
||||
|
@ -91,7 +91,7 @@ std::string server_env::construct_ssh_cmd() const {
|
||||
return ssh_cmd.str();
|
||||
}
|
||||
|
||||
std::string server_env::construct_standard_command_run_cmd(const std::string &service_name, const std::string &command) const
|
||||
std::string server_env::construct_standard_command_run_cmd(const std::string &service_name, const std::string &command, std::vector<std::string> args) const
|
||||
{
|
||||
std::string remote_service_template_path = get_remote_service_template_path(mServer_name,service_name);
|
||||
std::string remote_service_config_path = get_remote_service_config_path(mServer_name,service_name);
|
||||
@ -144,6 +144,12 @@ bool server_env::execute_ssh_command(const std::string& command, const std::stri
|
||||
return execute_local_command(full_cmd, error_msg);
|
||||
}
|
||||
|
||||
bool server_env::run_remote_template_command(const std::string &service_name, const std::string &command, std::vector<std::string> args, const std::string &error_msg) const
|
||||
{
|
||||
std::string full_cmd = construct_standard_command_run_cmd(service_name, command, args);
|
||||
return execute_ssh_command(full_cmd, error_msg);
|
||||
}
|
||||
|
||||
bool server_env::execute_local_command(const std::string& command, const std::string& error_msg) {
|
||||
bool okay = (system(command.c_str()) == 0);
|
||||
|
||||
|
@ -34,17 +34,22 @@ class server_env {
|
||||
|
||||
// helper functions
|
||||
public:
|
||||
std::string construct_ssh_cmd() const;
|
||||
std::string construct_standard_command_run_cmd(const std::string& service_name, const std::string& command) const;
|
||||
bool check_remote_items_exist(const std::vector<std::string>& file_paths) const;
|
||||
bool execute_ssh_command(const std::string& command, const std::string& error_msg) const;
|
||||
|
||||
static bool execute_local_command(const std::string& command, const std::string& error_msg);
|
||||
bool execute_ssh_command(const std::string& command, const std::string& error_msg="") const;
|
||||
bool run_remote_template_command(const std::string& service_name, const std::string& command, std::vector<std::string> args, const std::string& error_msg="") const;
|
||||
|
||||
static bool execute_local_command(const std::string& command, const std::string& error_msg="");
|
||||
static bool execute_local_command_and_capture_output(const std::string& command, std::string & output);
|
||||
|
||||
bool check_remote_dir_exists(const std::string &dir_path) const;
|
||||
bool check_remote_file_exists(const std::string& file_path) const;
|
||||
|
||||
std::string construct_ssh_cmd() const;
|
||||
|
||||
private:
|
||||
std::string construct_standard_command_run_cmd(const std::string& service_name, const std::string& command, std::vector<std::string> args) const;
|
||||
|
||||
|
||||
private:
|
||||
std::string mServer_name;
|
||||
std::map<std::string, std::string> variables;
|
||||
|
@ -87,10 +87,8 @@ bool service_runner::install() {
|
||||
|
||||
// Run install script
|
||||
{
|
||||
std::string install_cmd = m_server_env.construct_standard_command_run_cmd(m_service_info.service_name, "install");
|
||||
bool ok= m_server_env.execute_ssh_command(install_cmd, "Failed to run install script");
|
||||
if (!ok)
|
||||
return false;
|
||||
std::vector<std::string> args; // not passed through yet.
|
||||
m_server_env.run_remote_template_command(m_service_info.service_name, "install", args);
|
||||
}
|
||||
|
||||
// print health tick
|
||||
@ -114,10 +112,11 @@ bool service_runner::uninstall() {
|
||||
bool script_exists = m_server_env.check_remote_file_exists(uninstall_script);
|
||||
|
||||
if (script_exists) {
|
||||
std::string uninstall_cmd = m_server_env.construct_standard_command_run_cmd(m_service_info.service_name, "uninstall");
|
||||
if (!m_server_env.execute_ssh_command(uninstall_cmd, "Failed to run uninstall script")) {
|
||||
std::vector<std::string> args; // not passed through yet.
|
||||
if (!m_server_env.run_remote_template_command(m_service_info.service_name, "uninstall", args)) {
|
||||
std::cerr << "Warning: Uninstall script failed, but continuing with directory removal" << std::endl;
|
||||
}
|
||||
|
||||
} else {
|
||||
std::cerr << "Warning: No uninstall script found. Unable to uninstall service." << std::endl;
|
||||
return false;
|
||||
@ -188,8 +187,8 @@ bool service_runner::run_command(const std::string& command) {
|
||||
}
|
||||
|
||||
// Run the generic command
|
||||
std::string run_cmd = m_server_env.construct_standard_command_run_cmd(m_service_info.service_name, command);
|
||||
return m_server_env.execute_ssh_command(run_cmd, "Command returned error code: " + script_path);
|
||||
std::vector<std::string> args; // not passed through yet.
|
||||
return m_server_env.run_remote_template_command(m_service_info.service_name, command, args);
|
||||
}
|
||||
|
||||
|
||||
@ -280,11 +279,9 @@ HealthStatus service_runner::is_healthy()
|
||||
}
|
||||
|
||||
// Run status script, does not display output.
|
||||
std::string run_cmd = m_server_env.construct_standard_command_run_cmd(m_service_info.service_name, "status");
|
||||
bool ok = m_server_env.execute_ssh_command(run_cmd, "");
|
||||
if (!ok)
|
||||
std::vector<std::string> args; // not passed through yet.
|
||||
if (!m_server_env.run_remote_template_command(m_service_info.service_name, "status", args))
|
||||
return HealthStatus::UNHEALTHY;
|
||||
|
||||
return HealthStatus::HEALTHY;
|
||||
}
|
||||
|
||||
@ -408,8 +405,8 @@ void service_runner::interactive_ssh_service()
|
||||
return;
|
||||
}
|
||||
|
||||
std::string command = m_server_env.construct_standard_command_run_cmd(m_service_info.service_name, "ssh");
|
||||
interactive_ssh(m_server_name, "/bin/bash -c '"+command+"'");
|
||||
std::vector<std::string> args; // not passed through yet.
|
||||
m_server_env.run_remote_template_command(m_service_info.service_name, "ssh", args);
|
||||
}
|
||||
|
||||
void service_runner::edit_service_config()
|
||||
|
@ -11,18 +11,26 @@ namespace dropshell {
|
||||
|
||||
|
||||
|
||||
std::string get_local_dropshell_config_path()
|
||||
std::string get_local_dropshell_config_parent_path()
|
||||
{
|
||||
// Try ~/.config/dropshell/dropshell.conf
|
||||
const char* home = std::getenv("HOME");
|
||||
if (home) {
|
||||
fs::path user_path = fs::path(home) / ".config" / "dropshell" / "dropshell.env";
|
||||
fs::path user_path = fs::path(home) / ".config" / "dropshell";
|
||||
return user_path.string();
|
||||
}
|
||||
std::cerr << "Warning: Couldn't determine user directory" << std::endl;
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string get_local_dropshell_config_file()
|
||||
{
|
||||
std::string parent_path = get_local_dropshell_config_parent_path();
|
||||
if (parent_path.empty())
|
||||
return std::string();
|
||||
return parent_path + "/dropshell.conf";
|
||||
}
|
||||
|
||||
std::string get_local_system_templates_path()
|
||||
{
|
||||
return "/opt/dropshell/templates";
|
||||
|
@ -6,7 +6,8 @@
|
||||
namespace dropshell {
|
||||
|
||||
// local paths - return empty string on failure
|
||||
std::string get_local_dropshell_config_path();
|
||||
std::string get_local_dropshell_config_parent_path();
|
||||
std::string get_local_dropshell_config_file();
|
||||
std::string get_local_system_templates_path();
|
||||
|
||||
std::string get_local_backup_path();
|
||||
|
@ -37,7 +37,7 @@ load_env() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
env_file="$1"
|
||||
env_file="$1/service.env"
|
||||
|
||||
if [ ! -f "$env_file" ]; then
|
||||
echo "Warning: service.env file not found at $1"
|
||||
|
Loading…
x
Reference in New Issue
Block a user