Tidying
This commit is contained in:
@@ -529,6 +529,17 @@ complete -F _dropshell_completions ds
|
||||
server, false, user.user);
|
||||
info << "done." << std::endl;
|
||||
|
||||
// create server_info.env
|
||||
info << "Creating server_info.env on remote server... " <<std::flush;
|
||||
std::string rsiep = remotefile(server.get_server_name(),user.user).server_info_env();
|
||||
sCommand cmd("","echo 'SERVER=\""+server.get_server_name()+"\"' > "+rsiep,{});
|
||||
if (! execute_ssh_command(server.get_SSH_INFO(user.user),cmd,cMode::Defaults | cMode::NoBB64, nullptr))
|
||||
{
|
||||
error << std::endl << "Failed to create " << rsiep << " on " << server.get_server_name() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
info << "done." << std::endl;
|
||||
|
||||
// run the agent installer. Can't use BB64 yet, as we're installing it on the remote server.
|
||||
bool okay = execute_ssh_command(server.get_SSH_INFO(user.user), sCommand(agent_path, "agent-install.sh",{}), cMode::Defaults | cMode::NoBB64, nullptr);
|
||||
if (!okay)
|
||||
@@ -537,7 +548,6 @@ complete -F _dropshell_completions ds
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
info << "Installation on " << server.get_server_name() << " complete." << std::endl;
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -170,6 +170,11 @@ namespace dropshell
|
||||
return remotepath(mServer_name, mUser).DROPSHELL_DIR() + "/" + filenames::server_json;
|
||||
}
|
||||
|
||||
std::string remotefile::server_info_env()
|
||||
{
|
||||
return remotepath(mServer_name, mUser).DROPSHELL_DIR() + "/" + filenames::server_info_env;
|
||||
}
|
||||
|
||||
remotepath::remotepath(const std::string &server_name, const std::string &user) : mServer_name(server_name), mUser(user) {}
|
||||
|
||||
std::string remotepath::DROPSHELL_DIR() const
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace dropshell {
|
||||
// |-- (...other config files for specific server&service...)
|
||||
|
||||
namespace filenames {
|
||||
static const std::string server_info_env = "server_info.env";
|
||||
static const std::string template_info_env = "template_info.env";
|
||||
static const std::string service_env = "service.env";
|
||||
static const std::string readme = "README.txt";
|
||||
@@ -80,6 +81,7 @@ namespace dropshell {
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// remote paths
|
||||
// DROPSHELL_DIR
|
||||
// |-- server_info.env
|
||||
// |-- server.json
|
||||
// |-- backups
|
||||
// |-- temp_files
|
||||
@@ -102,6 +104,7 @@ namespace dropshell {
|
||||
remotefile(const std::string &server_name, const std::string &user);
|
||||
std::string service_env(const std::string &service_name) const;
|
||||
std::string server_json();
|
||||
std::string server_info_env();
|
||||
private:
|
||||
std::string mServer_name;
|
||||
std::string mUser;
|
||||
|
||||
@@ -235,52 +235,45 @@ namespace dropshell
|
||||
return "";
|
||||
|
||||
// need to construct to change directory and set environment variables
|
||||
std::string cmdstr;
|
||||
|
||||
if (!bb64path.empty())
|
||||
{
|
||||
if (!mDir.empty())
|
||||
cmdstr += "cd " + quote(mDir) + " && ";
|
||||
|
||||
if (!mVars.empty())
|
||||
{
|
||||
// Export variables so they're available for expansion in the command
|
||||
for (const auto &env_var : mVars)
|
||||
{
|
||||
// Basic sanity check - skip invalid variable names
|
||||
if (!is_valid_env_var_name(env_var.first))
|
||||
{
|
||||
error << "Skipping invalid environment variable name: " << env_var.first << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Very basic check for completely broken values that could break the command
|
||||
// We still use quote() for proper escaping, but warn about suspicious values
|
||||
const std::string &value = env_var.second;
|
||||
if (value.find('\0') != std::string::npos)
|
||||
{
|
||||
error << "Skipping environment variable with null byte: " << env_var.first << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
cmdstr += "export " + env_var.first + "=" + quote(dequote(trim(value))) + " && ";
|
||||
}
|
||||
}
|
||||
|
||||
cmdstr += mCmd;
|
||||
|
||||
cmdstr = makesafecmd(bb64path, cmdstr);
|
||||
}
|
||||
else
|
||||
if (bb64path.empty())
|
||||
{ // raw! bootstrapping only.
|
||||
ASSERT(mVars.empty(), "Bootstrapping command must not have environment variables");
|
||||
if (!mDir.empty())
|
||||
cmdstr += mDir + "/" + mCmd;
|
||||
else
|
||||
cmdstr += mCmd;
|
||||
return (mDir.empty() ? mCmd : mDir + "/" + mCmd);
|
||||
}
|
||||
|
||||
return cmdstr;
|
||||
std::string cmdstr;
|
||||
if (!mDir.empty())
|
||||
cmdstr += "cd " + quote(mDir) + " && ";
|
||||
|
||||
if (!mVars.empty())
|
||||
{
|
||||
// Export variables so they're available for expansion in the command
|
||||
for (const auto &env_var : mVars)
|
||||
{
|
||||
// Basic sanity check - skip invalid variable names
|
||||
if (!is_valid_env_var_name(env_var.first))
|
||||
{
|
||||
error << "Skipping invalid environment variable name: " << env_var.first << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Very basic check for completely broken values that could break the command
|
||||
// We still use quote() for proper escaping, but warn about suspicious values
|
||||
const std::string &value = env_var.second;
|
||||
if (value.find('\0') != std::string::npos)
|
||||
{
|
||||
error << "Skipping environment variable with null byte: " << env_var.first << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
cmdstr += "export " + env_var.first + "=" + quote(dequote(trim(value))) + " && ";
|
||||
}
|
||||
}
|
||||
|
||||
cmdstr += mCmd;
|
||||
|
||||
return makesafecmd(bb64path, cmdstr);
|
||||
}
|
||||
|
||||
bool sSSHInfo::valid() const
|
||||
|
||||
Reference in New Issue
Block a user