Installs bb64 correctly.
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
ba866494cd
commit
22e37b212a
@ -18,7 +18,7 @@ namespace dropshell
|
||||
|
||||
int install_handler(const CommandContext &ctx);
|
||||
|
||||
static std::vector<std::string> install_name_list = {"install","reinstall","update"};
|
||||
static std::vector<std::string> install_name_list = {"install", "reinstall", "update"};
|
||||
|
||||
// Static registration
|
||||
struct InstallCommandRegister
|
||||
@ -65,7 +65,7 @@ namespace dropshell
|
||||
quote(local_path + "/") + " " +
|
||||
quote(server_env.get_SSH_USER() + "@" + server_env.get_SSH_HOST() + ":" +
|
||||
remote_path + "/");
|
||||
return execute_local_command(rsync_cmd, nullptr, (silent ? cMode::Silent : cMode::None));
|
||||
return execute_local_command(rsync_cmd, nullptr, (silent ? cMode::Silent : cMode::Defaults));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -145,11 +145,11 @@ namespace dropshell
|
||||
{
|
||||
// determine the architecture of the system
|
||||
std::string arch;
|
||||
#ifdef __aarch64__
|
||||
#ifdef __aarch64__
|
||||
arch = "arm64";
|
||||
#elif __x86_64__
|
||||
#elif __x86_64__
|
||||
arch = "amd64";
|
||||
#endif
|
||||
#endif
|
||||
return arch;
|
||||
}
|
||||
|
||||
@ -157,15 +157,17 @@ namespace dropshell
|
||||
// update_dropshell
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
std::string _exec(const char* cmd) {
|
||||
std::string _exec(const char *cmd)
|
||||
{
|
||||
char buffer[128];
|
||||
std::string result = "";
|
||||
FILE* pipe = popen(cmd, "r");
|
||||
if (!pipe) {
|
||||
FILE *pipe = popen(cmd, "r");
|
||||
if (!pipe)
|
||||
{
|
||||
throw std::runtime_error("popen() failed!");
|
||||
}
|
||||
while (!feof(pipe)) {
|
||||
while (!feof(pipe))
|
||||
{
|
||||
if (fgets(buffer, 128, pipe) != nullptr)
|
||||
result += buffer;
|
||||
}
|
||||
@ -225,7 +227,6 @@ namespace dropshell
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
std::string bash_script_2 = "docker run --rm -v " + parent_path.string() + ":/target gitea.jde.nz/public/debian-curl:latest " +
|
||||
"sh -c \"mv /target/dropshell_temp /target/dropshell\"";
|
||||
rval = system(bash_script_2.c_str());
|
||||
@ -249,8 +250,7 @@ namespace dropshell
|
||||
gConfig().get_local_template_cache_path(),
|
||||
gConfig().get_local_backup_path(),
|
||||
gConfig().get_local_tempfiles_path(),
|
||||
localpath::agent()
|
||||
};
|
||||
localpath::agent()};
|
||||
for (auto &p : gConfig().get_local_server_definition_paths())
|
||||
paths.push_back(p);
|
||||
|
||||
@ -262,7 +262,7 @@ namespace dropshell
|
||||
}
|
||||
|
||||
// download bb64.
|
||||
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";
|
||||
int ret = system(cmd.c_str());
|
||||
@ -270,9 +270,11 @@ namespace dropshell
|
||||
std::cout << "Downloaded bb64 to " << localpath::agent() << std::endl;
|
||||
else
|
||||
std::cerr << "Failed to download bb64 to " << localpath::agent() << std::endl;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Updating bb64..." << std::endl;
|
||||
system((localpath::agent()+"bb64 -u").c_str()); // update.
|
||||
system((localpath::agent() + "bb64 -u").c_str()); // update.
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -294,7 +296,6 @@ namespace dropshell
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int install_server(const std::string &server)
|
||||
{
|
||||
// install the dropshell agent on the given server.
|
||||
@ -308,23 +309,27 @@ namespace dropshell
|
||||
}
|
||||
|
||||
server_env_manager server_env(server);
|
||||
if (!server_env.is_valid()) {
|
||||
if (!server_env.is_valid())
|
||||
{
|
||||
std::cerr << "Invalid server environment for " << server << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// first install bb64.
|
||||
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()+")")+"'";
|
||||
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;
|
||||
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;
|
||||
} else {
|
||||
else
|
||||
std::cout << "Downloaded bb64 to " << agent_path << " on remote server." << std::endl;
|
||||
}
|
||||
|
||||
|
||||
return 0; // NOTIMPL
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,7 @@ bool server_env_manager::remove_remote_dir(const std::string &dir_path, bool sil
|
||||
std::cout << "Running command: " << remote_cmd << std::endl;
|
||||
|
||||
sCommand scommand("", remote_cmd,{});
|
||||
cMode mode = (silent ? cMode::Silent : cMode::None);
|
||||
cMode mode = (silent ? cMode::Silent : cMode::Defaults);
|
||||
|
||||
return execute_ssh_command(get_SSH_INFO(), scommand, mode);
|
||||
}
|
||||
|
@ -262,13 +262,13 @@ bool service_runner::interactive_ssh_service()
|
||||
bool service_runner::scp_file_to_remote(const std::string &local_path, const std::string &remote_path, bool silent)
|
||||
{
|
||||
std::string scp_cmd = "scp -P " + mServerEnv.get_SSH_PORT() + " " + quote(local_path) + " " + mServerEnv.get_SSH_USER() + "@" + mServerEnv.get_SSH_HOST() + ":" + quote(remote_path) + (silent ? " > /dev/null 2>&1" : "");
|
||||
return execute_local_command(scp_cmd, nullptr, (silent ? cMode::Silent : cMode::None));
|
||||
return execute_local_command(scp_cmd, nullptr, (silent ? cMode::Silent : cMode::Defaults));
|
||||
}
|
||||
|
||||
bool service_runner::scp_file_from_remote(const std::string &remote_path, const std::string &local_path, bool silent)
|
||||
{
|
||||
std::string scp_cmd = "scp -P " + mServerEnv.get_SSH_PORT() + " " + mServerEnv.get_SSH_USER() + "@" + mServerEnv.get_SSH_HOST() + ":" + quote(remote_path) + " " + quote(local_path) + (silent ? " > /dev/null 2>&1" : "");
|
||||
return execute_local_command(scp_cmd, nullptr, (silent ? cMode::Silent : cMode::None));
|
||||
return execute_local_command(scp_cmd, nullptr, (silent ? cMode::Silent : cMode::Defaults));
|
||||
}
|
||||
|
||||
bool service_runner::restore(std::string backup_file, bool silent)
|
||||
|
@ -10,7 +10,7 @@ class sCommand;
|
||||
|
||||
// mode bitset
|
||||
enum class cMode {
|
||||
None = 0,
|
||||
Defaults = 0,
|
||||
Interactive = 1,
|
||||
Silent = 2,
|
||||
CaptureOutput = 4
|
||||
@ -31,9 +31,9 @@ typedef struct sSSHInfo {
|
||||
std::string server_ID; // dropshell name for server.
|
||||
} sSSHInfo;
|
||||
|
||||
bool execute_local_command(std::string command, std::string * output = nullptr, cMode mode = cMode::None);
|
||||
bool execute_local_command(std::string directory_to_run_in, std::string command_to_run, const std::map<std::string, std::string> & env_vars, std::string * output = nullptr, cMode mode = cMode::None);
|
||||
bool execute_ssh_command(const sSSHInfo & ssh_info, const sCommand & remote_command, cMode mode = cMode::None, std::string * output = nullptr);
|
||||
bool execute_local_command(std::string command, std::string * output = nullptr, cMode mode = cMode::Defaults);
|
||||
bool execute_local_command(std::string directory_to_run_in, std::string command_to_run, const std::map<std::string, std::string> & env_vars, std::string * output = nullptr, cMode mode = cMode::Defaults);
|
||||
bool execute_ssh_command(const sSSHInfo & ssh_info, const sCommand & remote_command, cMode mode = cMode::Defaults, std::string * output = nullptr);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user