...
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled

This commit is contained in:
Your Name 2025-05-17 11:12:33 +12:00
parent 93e563948f
commit 985153377f
4 changed files with 37 additions and 27 deletions

View File

@ -261,25 +261,24 @@ namespace dropshell
std::filesystem::create_directories(p); std::filesystem::create_directories(p);
} }
// download bb64. // download bb64 for the host architecture.
if (!std::filesystem::exists(localpath::agent() + "bb64")) if (!std::filesystem::exists(localpath::agent() + "bb64"))
{ {
std::string cmd = "cd " + localpath::agent() + " && curl -fsSL -o bb64 https://gitea.jde.nz/public/bb64/releases/download/latest/bb64.amd64 && chmod a+x bb64"; std::string cmd = "cd " + localpath::agent() + " && curl -fsSL -o bb64 https://gitea.jde.nz/public/bb64/releases/download/latest/bb64.amd64 && chmod a+x bb64";
int ret = system(cmd.c_str()); int ret = system(cmd.c_str());
if (EXITSTATUSCHECK(ret)) if (EXITSTATUSCHECK(ret))
std::cout << "Downloaded bb64 to " << localpath::agent() << std::endl; std::cout << "Downloaded local bb64 to " << localpath::agent() << std::endl;
else else
std::cerr << "Failed to download bb64 to " << localpath::agent() << std::endl; std::cerr << "Failed to download local bb64 to " << localpath::agent() << std::endl;
} }
else else
{ {
std::cout << "Updating bb64..." << std::endl; std::cout << "Updating local bb64..." << std::endl;
system((localpath::agent() + "bb64 -u").c_str()); // update. system((localpath::agent() + "bb64 -u").c_str()); // update.
} }
std::cout << "Creating local files to copy to remote agents..." << std::endl;
std::cout << "Creating local agent files..." << std::endl; recreate_agent::recreate_tree(localpath::files_for_remote_agent());
recreate_agent::recreate_tree(localpath::agent());
return 0; return 0;
} }
@ -320,25 +319,35 @@ namespace dropshell
return 1; return 1;
} }
// first install bb64. // now create the agent.
std::cout << "Installing bb64 on " << server << std::endl // copy across from the local agent files.
<< std::flush; rsync_tree_to_remote(localpath::files_for_remote_agent(), agent_path, server_env, false);
// add in bb64. We can't use execute_remote_command() here, as that relies on bb64 which we're installing!
std::cout << "Installing bb64 on " << server << std::endl << std::flush;
std::string remote_cmd = std::string remote_cmd =
"ssh -p " + server_env.get_SSH_INFO().port + " " + server_env.get_SSH_INFO().user + "@" + server_env.get_SSH_INFO().host + "ssh -p " + server_env.get_SSH_INFO().port + " " + server_env.get_SSH_INFO().user + "@" + server_env.get_SSH_INFO().host +
" 'mkdir -p " + quote(agent_path) + " && curl -fsSL \"https://gitea.jde.nz/public/bb64/releases/download/latest/install.sh\" | bash -s -- " + " 'mkdir -p " + quote(agent_path) + " && curl -fsSL \"https://gitea.jde.nz/public/bb64/releases/download/latest/install.sh\" | bash -s -- " +
quote(agent_path) + " " + quote("$(id -u " + server_env.get_SSH_USER() + "):$(id -g " + server_env.get_SSH_USER() + ")") + "'"; quote(agent_path) + " " + quote("$(id -u " + server_env.get_SSH_USER() + "):$(id -g " + server_env.get_SSH_USER() + ")") + "'";
std::cout << "Executing: " << remote_cmd << std::endl; //std::cout << "Executing: " << remote_cmd << std::endl;
if (!execute_local_command(remote_cmd, nullptr, cMode::Silent)) if (!execute_local_command(remote_cmd, nullptr, cMode::Silent))
std::cerr << "Failed to download bb64 to " << agent_path << " on remote server." << std::endl; std::cerr << "Failed to download bb64 to " << agent_path << " on remote server." << std::endl;
else else
std::cout << "Downloaded bb64 to " << agent_path << " on remote server." << std::endl; std::cout << "Downloaded bb64 to " << agent_path << " on remote server." << std::endl;
// now create the agent. // just test all is ok
// copy across from the local agent files. std::string output;
#pragma message("TODO: copy across from the local agent files.") bool okay = execute_ssh_command(server_env.get_SSH_INFO(), sCommand(agent_path, "bb64 -i QkI2NCBpcyBjb3JyZWN0bHkgaW5zdGFsbGVk", {}), cMode::CaptureOutput, &output);
if (!okay)
{
std::cerr << "Failed to install bb64 on " << server << std::endl;
return 1;
}
return 0; // NOTIMPL std::cout << output << std::endl;
return 0;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -175,15 +175,6 @@ std::map<std::string, ServiceStatus> service_runner::get_all_services_status(std
{ {
std::map<std::string, ServiceStatus> status; std::map<std::string, ServiceStatus> status;
std::string command = "_allservicesstatus";
std::string service_name = "dropshell-agent";
if (!gTemplateManager().template_command_exists(service_name, "shared/"+command))
{
std::cerr << "Error: " << service_name << " does not contain the " << command << " script" << std::endl;
return status;
}
server_env_manager env(server_name); server_env_manager env(server_name);
if (!env.is_valid()) { if (!env.is_valid()) {
std::cerr << "Error: Invalid server environment" << std::endl; std::cerr << "Error: Invalid server environment" << std::endl;
@ -191,7 +182,7 @@ std::map<std::string, ServiceStatus> service_runner::get_all_services_status(std
} }
std::string output; std::string output;
if (!env.run_remote_template_command_and_capture_output(service_name, "shared/"+command, {}, output, true, {})) if (!execute_ssh_command(env.get_SSH_INFO(), sCommand(remotepath::agent(server_name), "_allservicesstatus.sh", {}), cMode::CaptureOutput, &output))
return status; return status;
std::stringstream ss(output); std::stringstream ss(output);

View File

@ -66,7 +66,12 @@ namespace localpath {
std::string agent(){ std::string agent(){
return current_user_home() + "/.local/dropshell_agent"; return current_user_home() + "/.local/dropshell_agent";
} }
std::string current_user_home(){ std::string files_for_remote_agent()
{
return agent() + "/files_for_remote_agent";
}
std::string current_user_home()
{
char * homedir = std::getenv("HOME"); char * homedir = std::getenv("HOME");
if (homedir) if (homedir)
{ {

View File

@ -12,7 +12,11 @@ namespace dropshell {
// local user config directories // local user config directories
// ~/.config/dropshell/dropshell.json // ~/.config/dropshell/dropshell.json
// ~/.local/dropshell_agent/bb64
// ~/.local/dropshell_agent
// |-- bb64 (only used locally, as it's for the local machine's architecture!)
// |-- files_for_remote_agent
// |-- (other agent files, including _allservicesstatus.sh)
// server_definition_path // server_definition_path
// |-- <server_name> // |-- <server_name>
@ -56,6 +60,7 @@ 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();
std::string files_for_remote_agent();
std::string current_user_home(); std::string current_user_home();
} // namespace local } // namespace local