diff --git a/source/src/commands/install.cpp b/source/src/commands/install.cpp index 483e016..7000059 100644 --- a/source/src/commands/install.cpp +++ b/source/src/commands/install.cpp @@ -261,25 +261,24 @@ namespace dropshell std::filesystem::create_directories(p); } - // download bb64. + // download bb64 for the host architecture. 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"; int ret = system(cmd.c_str()); if (EXITSTATUSCHECK(ret)) - std::cout << "Downloaded bb64 to " << localpath::agent() << std::endl; + std::cout << "Downloaded local bb64 to " << localpath::agent() << std::endl; 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 { - std::cout << "Updating bb64..." << std::endl; + std::cout << "Updating local bb64..." << std::endl; system((localpath::agent() + "bb64 -u").c_str()); // update. } - - std::cout << "Creating local agent files..." << std::endl; - recreate_agent::recreate_tree(localpath::agent()); + std::cout << "Creating local files to copy to remote agents..." << std::endl; + recreate_agent::recreate_tree(localpath::files_for_remote_agent()); return 0; } @@ -320,25 +319,35 @@ namespace dropshell return 1; } - // first install bb64. - std::cout << "Installing bb64 on " << server << std::endl - << std::flush; + // now create the agent. + // copy across from the local agent files. + 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 = "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 -- " + 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)) std::cerr << "Failed to download bb64 to " << agent_path << " on remote server." << std::endl; else std::cout << "Downloaded bb64 to " << agent_path << " on remote server." << std::endl; - // now create the agent. - // copy across from the local agent files. - #pragma message("TODO: copy across from the local agent files.") + // just test all is ok + std::string output; + 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; } // ------------------------------------------------------------------------------------------------ diff --git a/source/src/service_runner.cpp b/source/src/service_runner.cpp index dfe1cc2..0c890b4 100644 --- a/source/src/service_runner.cpp +++ b/source/src/service_runner.cpp @@ -175,15 +175,6 @@ std::map service_runner::get_all_services_status(std { std::map 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); if (!env.is_valid()) { std::cerr << "Error: Invalid server environment" << std::endl; @@ -191,7 +182,7 @@ std::map service_runner::get_all_services_status(std } 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; std::stringstream ss(output); diff --git a/source/src/utils/directories.cpp b/source/src/utils/directories.cpp index 4be740d..18b4695 100644 --- a/source/src/utils/directories.cpp +++ b/source/src/utils/directories.cpp @@ -66,7 +66,12 @@ namespace localpath { std::string 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"); if (homedir) { diff --git a/source/src/utils/directories.hpp b/source/src/utils/directories.hpp index 7e8ab07..758ebe8 100644 --- a/source/src/utils/directories.hpp +++ b/source/src/utils/directories.hpp @@ -12,7 +12,11 @@ namespace dropshell { // local user config directories // ~/.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 // |-- @@ -56,6 +60,7 @@ namespace dropshell { std::string remote_versions(const std::string &server_name, const std::string &service_name); std::string agent(); + std::string files_for_remote_agent(); std::string current_user_home(); } // namespace local