Self-test.
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled

This commit is contained in:
Your Name 2025-05-17 20:41:17 +12:00
parent 91f706ffcd
commit 891f0d023f
4 changed files with 31 additions and 4 deletions

View File

@ -51,7 +51,6 @@ add_dependencies(dropshell run_createagent)
# Set include directories # Set include directories
# build dir goes first so that we can use the generated version.hpp # build dir goes first so that we can use the generated version.hpp
target_include_directories(dropshell PRIVATE target_include_directories(dropshell PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/autogen> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/autogen>
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/utils ${CMAKE_CURRENT_SOURCE_DIR}/src/utils

7
source/agent/selftest.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
echo "Running remote agent self-test..."
echo "Completed remote agent self-test."
exit 0

View File

@ -105,6 +105,22 @@ static bool _recreate_file_(const std::filesystem::path& outpath, uint64_t file_
bool recreate_tree(std::string destination_folder) { bool recreate_tree(std::string destination_folder) {
namespace fs = std::filesystem; namespace fs = std::filesystem;
bool any_written = false; bool any_written = false;
{
// File: selftest.sh
fs::path outpath = fs::path(destination_folder) / "selftest.sh";
static const char filedata_base64[] = "IyEvYmluL2Jhc2gKCmVjaG8gIlJ1bm5pbmcgcmVtb3RlIGFnZW50IHNlbGYtdGVzdC4uLiIKCmVj"\
"aG8gIkNvbXBsZXRlZCByZW1vdGUgYWdlbnQgc2VsZi10ZXN0LiIKCmV4aXQgMAo=";
// Decode Base64 data
size_t decoded_size = (strlen(filedata_base64) * 3) / 4;
unsigned char* decoded_data = new unsigned char[decoded_size];
size_t actual_size;
base64_decode(filedata_base64, strlen(filedata_base64), decoded_data, &actual_size);
bool file_written = _recreate_file_(outpath, 11594895391899191874ULL, std::filesystem::perms(493), decoded_data, actual_size);
delete[] decoded_data;
any_written = any_written || file_written;
}
{ {
// File: datacommands.sh // File: datacommands.sh
fs::path outpath = fs::path(destination_folder) / "datacommands.sh"; fs::path outpath = fs::path(destination_folder) / "datacommands.sh";

View File

@ -298,10 +298,12 @@ namespace dropshell
// now create the agent. // now create the agent.
// copy across from the local agent files. // copy across from the local agent files.
std::cout << "Copying local agent files to remote server... " << std::flush;
shared_commands::rsync_tree_to_remote(localpath::files_for_remote_agent(), agent_path, server_env, false); shared_commands::rsync_tree_to_remote(localpath::files_for_remote_agent(), agent_path, server_env, false);
std::cout << "done." << std::endl;
// add in bb64. We can't use execute_remote_command() here, as that relies on bb64 which we're installing! // 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::cout << "Installing bb64 on " << server << "..." << std::endl << std::flush;
std::string remote_cmd = std::string remote_cmd =
"ssh -p " + server_env.get_SSH_INFO().port + " " + server_env.get_SSH_INFO().user + "@" + server_env.get_SSH_INFO().host + "ssh -p " + server_env.get_SSH_INFO().port + " " + server_env.get_SSH_INFO().user + "@" + server_env.get_SSH_INFO().host +
@ -315,11 +317,14 @@ namespace dropshell
std::cout << "Downloaded bb64 to " << agent_path << " on remote server." << std::endl; std::cout << "Downloaded bb64 to " << agent_path << " on remote server." << std::endl;
// just test all is ok // just test all is ok
// run the self-test.
std::string output; std::string output;
bool okay = execute_ssh_command(server_env.get_SSH_INFO(), sCommand(agent_path, "./bb64 -i VGhlIGRyb3BzaGVsbCByZW1vdGUgYWdlbnQgaXMgY29ycmVjdGx5IGluc3RhbGxlZC4=", {}), cMode::CaptureOutput, &output); bool okay = execute_ssh_command(server_env.get_SSH_INFO(), sCommand(agent_path, "./selftest.sh", {}), cMode::Defaults, &output);
if (!okay) if (!okay)
{ {
std::cerr << "Failed to install bb64 on " << server << std::endl; std::cerr << "ERROR: Failed to install remote agent on " << server << std::endl;
std::cerr << "ERROR: Output: " << output << std::endl;
return 1; return 1;
} }