feat: Update 4 files
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 59s
Build-Test-Publish / build (linux/arm64) (push) Successful in 1m40s

This commit is contained in:
2025-10-08 17:57:00 +13:00
parent 709937bc61
commit e9a6998761
4 changed files with 39 additions and 24 deletions

View File

@@ -4,7 +4,7 @@
#include "utils/directories.hpp"
#include "templates.hpp"
#include "shared_commands.hpp"
#include "utils/hash.hpp"
//#include "utils/hash.hpp"
#include "autogen/_agent-local.hpp"
#include "autogen/_agent-remote.hpp"
#include "services.hpp"
@@ -15,7 +15,7 @@
#include <unistd.h>
#include <cstring>
#include <iostream>
#include <sstream>
//#include <sstream>
#include <filesystem>
#include <libassert/assert.hpp>
#include "servers.hpp"

View File

@@ -1,5 +1,6 @@
#include "command_registry.hpp"
#include "config.hpp"
//#include "config.hpp"
#include "ordered_env.hpp"
#include "utils/utils.hpp"
#include "utils/directories.hpp"
#include "utils/execute.hpp"
@@ -41,7 +42,7 @@ namespace dropshell
}
} ssh_command_register;
bool ssh_into_server(const std::string &server, std::string user)
bool ssh_into_server(const std::string &server, std::string user, const ordered_env_vars & env_vars, std::string remote_path)
{
ServerConfig server_env(server);
if (!server_env.is_valid())
@@ -49,12 +50,11 @@ namespace dropshell
error << "Server " << server << " is not valid" << std::endl;
return false;
}
std::string dropshell_dir = remotepath(server, user).DROPSHELL_DIR();
std::string bash_cmd = "ls --color && exec bash --rcfile <(cat ~/.bashrc 2>/dev/null; echo 'cd " + quote(dropshell_dir) + "')";
std::string bash_cmd = "ls --color && exec bash --rcfile <(cat ~/.bashrc 2>/dev/null; echo 'cd " + quote(remote_path) + "')";
info << "SSHing into " << server << ":" << dropshell_dir << " as user " << user << std::endl;
info << "SSHing into " << server << ":" << remote_path << " as user " << user << std::endl;
execute_ssh_command(server_env.get_SSH_INFO(user), sCommand(dropshell_dir, bash_cmd, {}), cMode::Interactive);
execute_ssh_command(server_env.get_SSH_INFO(user), sCommand(remote_path, bash_cmd, env_vars), cMode::Interactive);
return true;
}
@@ -86,14 +86,22 @@ namespace dropshell
return false;
}
if (!gTemplateManager().template_command_exists(sinfo.template_name, "ssh"))
if (gTemplateManager().template_command_exists(sinfo.template_name, "ssh"))
{
error << "Template " << sinfo.template_name << " does not have an ssh command" << std::endl;
return false;
return server_env.run_remote_template_command(service, "ssh", {}, false, {}); // explicitly supports interactive ssh!
}
server_env.run_remote_template_command(service, "ssh", {}, false, {}); // explicitly supports interactive ssh!
return true;
// ssh in without as ssh.sh script.
ordered_env_vars env_vars;
if (!get_all_service_env_vars(server, service, env_vars))
{
error << "Failed to get all service env vars for " << service << std::endl;
return false;
}
set_var(env_vars, "HOST_NAME", server_env.get_SSH_HOST());
std::string service_dir = remotepath(server, sinfo.user).service_template(service);
return ssh_into_server(server, sinfo.user, env_vars, service_dir);
}
int ssh_handler(const CommandContext &ctx)
@@ -109,6 +117,7 @@ namespace dropshell
{
std::string arg1 = safearg(ctx.args, 0);
std::string server, user;
ordered_env_vars env_vars;
// parse either user@server or server
if (arg1.find("@") != std::string::npos)
@@ -119,6 +128,7 @@ namespace dropshell
else
{
server = arg1;
}
// get the first user from the server.env file, and ssh in as that user.
ServerConfig server_env(server);
@@ -127,11 +137,16 @@ namespace dropshell
error << "Server " << server << " is not valid" << std::endl;
return 1;
}
if (user.empty())
{
ASSERT(server_env.get_users().size() > 0, "Server " + server + " has no users");
user = server_env.get_users()[0].user;
}
return ssh_into_server(server, user) ? 0 : 1;
set_var(env_vars, "HOST_NAME", server_env.get_SSH_HOST());
std::string dropshell_dir = remotepath(server, user).DROPSHELL_DIR();
return ssh_into_server(server, user, env_vars, dropshell_dir) ? 0 : 1;
}
else
{ // ssh into a service on the server.

View File

@@ -10,7 +10,7 @@
#include "config.hpp"
#include <iostream>
#include <memory>
//#include <memory>
#include <filesystem>
#include <fstream>
#include <sys/wait.h>
@@ -476,7 +476,7 @@ namespace dropshell
if (server_existing_dir.empty())
return false;
if (std::filesystem::exists(server_existing_dir));
if (std::filesystem::exists(server_existing_dir))
return true;
return false;
}

View File

@@ -4,7 +4,7 @@
#include <string>
#include <vector>
#include <set>
#include <map>
//#include <map>
#include "utils/ordered_env.hpp"
namespace dropshell {