dropshell release 2025.0521.2125
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
This commit is contained in:
parent
270d6ef792
commit
b3a57f13dc
@ -50,7 +50,7 @@ function install_bb64() {
|
|||||||
_die "Curl is not installed. Curl is required for agent installation."
|
_die "Curl is not installed. Curl is required for agent installation."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
curl -fsSL "https://gitea.jde.nz/public/bb64/releases/download/latest/install.sh" | bash -s -- "$AGENT_PATH" "$(id -u $USER):$(id -g $USER)"
|
curl -fsSL "https://gitea.jde.nz/public/bb64/releases/download/latest/install.sh" | bash -s -- "$AGENT_LOCAL_PATH" "$(id -u $USER):$(id -g $USER)"
|
||||||
|
|
||||||
# test result code from curl
|
# test result code from curl
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
@ -58,7 +58,7 @@ function install_bb64() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# test if bb64 is installed
|
# test if bb64 is installed
|
||||||
"$AGENT_PATH/bb64" -v
|
"$AGENT_LOCAL_PATH/bb64" -v
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
_die "bb64 did not install correctly."
|
_die "bb64 did not install correctly."
|
||||||
fi
|
fi
|
||||||
@ -71,11 +71,11 @@ function install_bb64() {
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
set -a
|
set -a
|
||||||
AGENT_PATH="$SCRIPT_DIR"
|
AGENT_LOCAL_PATH="$SCRIPT_DIR"
|
||||||
set +a
|
set +a
|
||||||
|
|
||||||
_check_required_env_vars "AGENT_PATH"
|
_check_required_env_vars "AGENT_LOCAL_PATH"
|
||||||
echo "Installing host agent into $AGENT_PATH"
|
echo "Installing host agent into $AGENT_LOCAL_PATH"
|
||||||
|
|
||||||
_check_docker_installed || _die "Docker is required."
|
_check_docker_installed || _die "Docker is required."
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ struct CreateServerCommandRegister {
|
|||||||
create_server_handler,
|
create_server_handler,
|
||||||
create_server_autocomplete,
|
create_server_autocomplete,
|
||||||
false, // hidden
|
false, // hidden
|
||||||
false, // requires_config
|
true, // requires_config
|
||||||
false, // requires_install
|
true, // requires_install
|
||||||
0, // min_args (after command)
|
1, // min_args (after command)
|
||||||
1, // max_args (after command)
|
1, // max_args (after command)
|
||||||
"create-server [SERVER]",
|
"create-server [SERVER]",
|
||||||
"Create a new server entry on this host.",
|
"Create a new server entry on this host.",
|
||||||
|
63
source/src/commands/create-template.cpp
Normal file
63
source/src/commands/create-template.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#include "command_registry.hpp"
|
||||||
|
#include "config.hpp"
|
||||||
|
#include "utils/utils.hpp"
|
||||||
|
#include "utils/directories.hpp"
|
||||||
|
#include "shared_commands.hpp"
|
||||||
|
#include "version.hpp"
|
||||||
|
#include "utils/assert.hpp"
|
||||||
|
#include "templates.hpp"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
namespace dropshell {
|
||||||
|
|
||||||
|
void create_template_autocomplete(const CommandContext& ctx);
|
||||||
|
int create_template_handler(const CommandContext& ctx);
|
||||||
|
|
||||||
|
static std::vector<std::string> create_template_name_list={"create-template"};
|
||||||
|
|
||||||
|
// Static registration
|
||||||
|
struct CreateTemplateCommandRegister {
|
||||||
|
CreateTemplateCommandRegister() {
|
||||||
|
CommandRegistry::instance().register_command({
|
||||||
|
create_template_name_list,
|
||||||
|
create_template_handler,
|
||||||
|
create_template_autocomplete,
|
||||||
|
false, // hidden
|
||||||
|
true, // requires_config
|
||||||
|
true, // requires_install
|
||||||
|
1, // min_args (after command)
|
||||||
|
1, // max_args (after command)
|
||||||
|
"create-template TEMPLATE",
|
||||||
|
"Create a new template.",
|
||||||
|
// heredoc
|
||||||
|
R"(
|
||||||
|
Create a new template.
|
||||||
|
|
||||||
|
create-template TEMPLATE
|
||||||
|
)"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} create_template_command_register;
|
||||||
|
|
||||||
|
|
||||||
|
void create_template_autocomplete(const CommandContext& ctx) {
|
||||||
|
return; // can't autocomplete as it's a new server!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int create_template_handler(const CommandContext& ctx) {
|
||||||
|
// create a new server entry on this host
|
||||||
|
if (ctx.args.size() == 0) {
|
||||||
|
error << "No template name provided" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
bool ok = gTemplateManager().create_template(ctx.args[0]);
|
||||||
|
return ok ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace dropshell
|
@ -45,7 +45,7 @@ struct HelpCommandRegister {
|
|||||||
|
|
||||||
|
|
||||||
void help_autocomplete(const CommandContext& ctx) {
|
void help_autocomplete(const CommandContext& ctx) {
|
||||||
if (ctx.args.size() == 1) {
|
if (ctx.args.size() == 0) {
|
||||||
// list all commands
|
// list all commands
|
||||||
for (const auto& cmd : CommandRegistry::instance().list_primary_commands(false)) {
|
for (const auto& cmd : CommandRegistry::instance().list_primary_commands(false)) {
|
||||||
rawout << cmd << std::endl;
|
rawout << cmd << std::endl;
|
||||||
|
@ -238,17 +238,22 @@ namespace dropshell
|
|||||||
{
|
{
|
||||||
maketitle("Installing dropshell agent on this computer...");
|
maketitle("Installing dropshell agent on this computer...");
|
||||||
|
|
||||||
|
// clear out old cruft.
|
||||||
|
std::filesystem::remove_all(localpath::agent_local());
|
||||||
|
std::filesystem::remove_all(localpath::agent_remote());
|
||||||
|
|
||||||
|
// recreate the directories.
|
||||||
localpath::create_directories();
|
localpath::create_directories();
|
||||||
|
|
||||||
// create the agent-local directory.
|
// populate the agent-local directory.
|
||||||
recreate_agent_local::recreate_tree(localpath::agent());
|
recreate_agent_local::recreate_tree(localpath::agent_local());
|
||||||
|
|
||||||
// run the local agent installer.
|
// run the local agent installer.
|
||||||
execute_local_command(localpath::agent(), "agent-install.sh",{}, nullptr, cMode::Defaults | cMode::NoBB64);
|
execute_local_command(localpath::agent_local(), "agent-install.sh",{}, nullptr, cMode::Defaults | cMode::NoBB64);
|
||||||
|
|
||||||
// create the agent-remote directory.
|
// populate the agent-remote directory.
|
||||||
info << "Creating local files to copy to remote agents..." << std::endl;
|
info << "Creating local files to copy to remote agents..." << std::endl;
|
||||||
recreate_agent_remote::recreate_tree(localpath::files_for_remote_agent());
|
recreate_agent_remote::recreate_tree(localpath::agent_remote());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -275,7 +280,7 @@ namespace dropshell
|
|||||||
// now create the agent.
|
// now create the agent.
|
||||||
// copy across from the local agent files.
|
// copy across from the local agent files.
|
||||||
info << "Copying local agent files to remote server... " << std::flush;
|
info << "Copying local agent files to remote server... " << std::flush;
|
||||||
shared_commands::rsync_tree_to_remote(localpath::files_for_remote_agent(), agent_path, server_env, false);
|
shared_commands::rsync_tree_to_remote(localpath::agent_remote(), agent_path, server_env, false);
|
||||||
info << "done." << std::endl;
|
info << "done." << std::endl;
|
||||||
|
|
||||||
// run the agent installer. Can't use BB64 yet, as we're installing it on the remote server.
|
// run the agent installer. Can't use BB64 yet, as we're installing it on the remote server.
|
||||||
|
@ -114,7 +114,7 @@ bool config::is_config_set() const
|
|||||||
|
|
||||||
bool config::is_agent_installed()
|
bool config::is_agent_installed()
|
||||||
{
|
{
|
||||||
return std::filesystem::exists(localpath::agent() + "/bb64");
|
return std::filesystem::exists(localfile::bb64());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> config::get_template_registry_urls() {
|
std::vector<std::string> config::get_template_registry_urls() {
|
||||||
|
@ -41,6 +41,16 @@ namespace localfile {
|
|||||||
return (servicepath.empty() ? "" : (fs::path(servicepath) / ".template_info.env").string());
|
return (servicepath.empty() ? "" : (fs::path(servicepath) / ".template_info.env").string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string template_example()
|
||||||
|
{
|
||||||
|
return localpath::agent_local() + "/template_example";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string bb64()
|
||||||
|
{
|
||||||
|
return localpath::agent_local() + "/bb64";
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace localfile
|
} // namespace localfile
|
||||||
|
|
||||||
|
|
||||||
@ -66,12 +76,13 @@ namespace localpath {
|
|||||||
return ((template_cache_path.empty() || service_name.empty()) ? "" :
|
return ((template_cache_path.empty() || service_name.empty()) ? "" :
|
||||||
(template_cache_path+"/remote_versions/"+service_name+".json"));
|
(template_cache_path+"/remote_versions/"+service_name+".json"));
|
||||||
}
|
}
|
||||||
std::string agent(){
|
std::string agent_local()
|
||||||
return current_user_home() + "/.local/dropshell_agent";
|
|
||||||
}
|
|
||||||
std::string files_for_remote_agent()
|
|
||||||
{
|
{
|
||||||
return agent() + "/files_for_remote_agent";
|
return current_user_home()+"/.local/dropshell_agent/agent-local";
|
||||||
|
}
|
||||||
|
std::string agent_remote()
|
||||||
|
{
|
||||||
|
return current_user_home() + "/.local/dropshell_agent/agent-remote";
|
||||||
}
|
}
|
||||||
std::string current_user_home()
|
std::string current_user_home()
|
||||||
{
|
{
|
||||||
@ -110,15 +121,17 @@ namespace localpath {
|
|||||||
{
|
{
|
||||||
std::vector<std::filesystem::path> paths = {
|
std::vector<std::filesystem::path> paths = {
|
||||||
dropshell_files(),
|
dropshell_files(),
|
||||||
|
agent_local(),
|
||||||
|
agent_remote(),
|
||||||
template_cache(),
|
template_cache(),
|
||||||
backups(),
|
backups(),
|
||||||
temp_files(),
|
temp_files()
|
||||||
agent()};
|
};
|
||||||
for (auto &p : gConfig().get_local_server_definition_paths())
|
for (auto &p : gConfig().get_local_server_definition_paths())
|
||||||
paths.push_back(p);
|
paths.push_back(p);
|
||||||
|
|
||||||
for (auto &p : paths)
|
for (auto &p : paths)
|
||||||
if (!std::filesystem::exists(p))
|
if (!p.empty() && !std::filesystem::exists(p))
|
||||||
{
|
{
|
||||||
info << "Creating directory: " << p << std::endl;
|
info << "Creating directory: " << p << std::endl;
|
||||||
std::filesystem::create_directories(p);
|
std::filesystem::create_directories(p);
|
||||||
|
@ -14,9 +14,12 @@ namespace dropshell {
|
|||||||
// ~/.config/dropshell/dropshell.json
|
// ~/.config/dropshell/dropshell.json
|
||||||
|
|
||||||
// ~/.local/dropshell_agent
|
// ~/.local/dropshell_agent
|
||||||
// |-- bb64 (only used locally, as it's for the local machine's architecture!)
|
// |-- agent-local
|
||||||
// |-- files_for_remote_agent
|
// |-- agent-install.sh
|
||||||
// |-- (other agent files, including _allservicesstatus.sh)
|
// |-- bb64 (only used locally, as it's for the local machine's architecture!)
|
||||||
|
// |-- template_example
|
||||||
|
// |-- agent-remote
|
||||||
|
// |-- (remote agent files, including _allservicesstatus.sh)
|
||||||
|
|
||||||
// ~/.local/dropshell_files
|
// ~/.local/dropshell_files
|
||||||
// |-- backups
|
// |-- backups
|
||||||
@ -52,6 +55,8 @@ namespace dropshell {
|
|||||||
std::string server_json(const std::string &server_name);
|
std::string server_json(const std::string &server_name);
|
||||||
std::string service_env(const std::string &server_name, const std::string &service_name);
|
std::string service_env(const std::string &server_name, const std::string &service_name);
|
||||||
std::string template_info_env(const std::string &server_name, const std::string &service_name);
|
std::string template_info_env(const std::string &server_name, const std::string &service_name);
|
||||||
|
std::string template_example();
|
||||||
|
std::string bb64();
|
||||||
} // namespace localfile
|
} // namespace localfile
|
||||||
|
|
||||||
namespace localpath {
|
namespace localpath {
|
||||||
@ -60,8 +65,8 @@ namespace dropshell {
|
|||||||
|
|
||||||
std::string remote_versions(const std::string &server_name, const std::string &service_name);
|
std::string remote_versions(const std::string &server_name, const std::string &service_name);
|
||||||
|
|
||||||
std::string agent();
|
std::string agent_local();
|
||||||
std::string files_for_remote_agent();
|
std::string agent_remote();
|
||||||
std::string current_user_home();
|
std::string current_user_home();
|
||||||
|
|
||||||
std::string dropshell_files();
|
std::string dropshell_files();
|
||||||
@ -69,7 +74,6 @@ namespace dropshell {
|
|||||||
std::string temp_files();
|
std::string temp_files();
|
||||||
std::string template_cache();
|
std::string template_cache();
|
||||||
|
|
||||||
|
|
||||||
bool create_directories();
|
bool create_directories();
|
||||||
} // namespace local
|
} // namespace local
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ namespace dropshell
|
|||||||
{
|
{
|
||||||
if (command.get_command_to_run().empty())
|
if (command.get_command_to_run().empty())
|
||||||
return false;
|
return false;
|
||||||
std::string full_command = command.construct_cmd(localpath::agent()+"/bb64"); // Get the command string
|
std::string full_command = command.construct_cmd(localfile::bb64()); // Get the command string
|
||||||
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ namespace dropshell
|
|||||||
|
|
||||||
std::string full_cmd;
|
std::string full_cmd;
|
||||||
if (!hasFlag(mode, cMode::NoBB64))
|
if (!hasFlag(mode, cMode::NoBB64))
|
||||||
full_cmd = command.construct_cmd(localpath::agent()+"/bb64");
|
full_cmd = command.construct_cmd(localfile::bb64());
|
||||||
else
|
else
|
||||||
full_cmd = command.construct_cmd("");
|
full_cmd = command.construct_cmd("");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user