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

View File

@@ -1,5 +1,6 @@
#include "command_registry.hpp" #include "command_registry.hpp"
#include "config.hpp" //#include "config.hpp"
#include "ordered_env.hpp"
#include "utils/utils.hpp" #include "utils/utils.hpp"
#include "utils/directories.hpp" #include "utils/directories.hpp"
#include "utils/execute.hpp" #include "utils/execute.hpp"
@@ -41,7 +42,7 @@ namespace dropshell
} }
} ssh_command_register; } 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); ServerConfig server_env(server);
if (!server_env.is_valid()) if (!server_env.is_valid())
@@ -49,12 +50,11 @@ namespace dropshell
error << "Server " << server << " is not valid" << std::endl; error << "Server " << server << " is not valid" << std::endl;
return false; 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(remote_path) + "')";
std::string bash_cmd = "ls --color && exec bash --rcfile <(cat ~/.bashrc 2>/dev/null; echo 'cd " + quote(dropshell_dir) + "')";
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; return true;
} }
@@ -86,14 +86,22 @@ namespace dropshell
return false; 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 server_env.run_remote_template_command(service, "ssh", {}, false, {}); // explicitly supports interactive ssh!
return false;
} }
server_env.run_remote_template_command(service, "ssh", {}, false, {}); // explicitly supports interactive ssh! // ssh in without as ssh.sh script.
return true; 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) int ssh_handler(const CommandContext &ctx)
@@ -109,6 +117,7 @@ namespace dropshell
{ {
std::string arg1 = safearg(ctx.args, 0); std::string arg1 = safearg(ctx.args, 0);
std::string server, user; std::string server, user;
ordered_env_vars env_vars;
// parse either user@server or server // parse either user@server or server
if (arg1.find("@") != std::string::npos) if (arg1.find("@") != std::string::npos)
@@ -119,19 +128,25 @@ namespace dropshell
else else
{ {
server = arg1; server = arg1;
}
// get the first user from the server.env file, and ssh in as that user. // get the first user from the server.env file, and ssh in as that user.
ServerConfig server_env(server); ServerConfig server_env(server);
if (!server_env.is_valid()) if (!server_env.is_valid())
{ {
error << "Server " << server << " is not valid" << std::endl; error << "Server " << server << " is not valid" << std::endl;
return 1; return 1;
} }
if (user.empty())
{
ASSERT(server_env.get_users().size() > 0, "Server " + server + " has no users"); ASSERT(server_env.get_users().size() > 0, "Server " + server + " has no users");
user = server_env.get_users()[0].user; 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 else
{ // ssh into a service on the server. { // ssh into a service on the server.

View File

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

View File

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