From 891f0d023f71eff9fe5abeda54d24cfc9377908f Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 17 May 2025 20:41:17 +1200 Subject: [PATCH] Self-test. --- source/CMakeLists.txt | 1 - source/agent/selftest.sh | 7 +++++++ source/src/autogen/_agent.cpp | 16 ++++++++++++++++ source/src/commands/install.cpp | 11 ++++++++--- 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100755 source/agent/selftest.sh diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 4203b79..3ae29e4 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -51,7 +51,6 @@ add_dependencies(dropshell run_createagent) # Set include directories # build dir goes first so that we can use the generated version.hpp target_include_directories(dropshell PRIVATE - $ $ ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/utils diff --git a/source/agent/selftest.sh b/source/agent/selftest.sh new file mode 100755 index 0000000..594d586 --- /dev/null +++ b/source/agent/selftest.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo "Running remote agent self-test..." + +echo "Completed remote agent self-test." + +exit 0 diff --git a/source/src/autogen/_agent.cpp b/source/src/autogen/_agent.cpp index cb3836e..94b0370 100644 --- a/source/src/autogen/_agent.cpp +++ b/source/src/autogen/_agent.cpp @@ -105,6 +105,22 @@ static bool _recreate_file_(const std::filesystem::path& outpath, uint64_t file_ bool recreate_tree(std::string destination_folder) { namespace fs = std::filesystem; 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 fs::path outpath = fs::path(destination_folder) / "datacommands.sh"; diff --git a/source/src/commands/install.cpp b/source/src/commands/install.cpp index 71f2339..4d2d7fd 100644 --- a/source/src/commands/install.cpp +++ b/source/src/commands/install.cpp @@ -298,10 +298,12 @@ namespace dropshell // now create the agent. // 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); + 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! - std::cout << "Installing bb64 on " << server << std::endl << std::flush; + 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 + @@ -315,11 +317,14 @@ namespace dropshell std::cout << "Downloaded bb64 to " << agent_path << " on remote server." << std::endl; // just test all is ok + + // run the self-test. 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) { - 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; }