From 80450aadcc0a16684bf5490e57e05a28ec6e4aa2 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 30 Dec 2025 10:23:08 +1300 Subject: [PATCH] docs: Update 7 files --- source/CMakeLists.txt | 35 ++++++++++++++++++------- source/agent-remote/agent-install.sh | 6 +++++ source/cmake_prebuild.sh | 4 --- source/src/commands/install.cpp | 11 ++++---- source/src/commands/shared_commands.cpp | 2 +- source/src/servers.cpp | 14 ++++++++++ source/src/servers.hpp | 2 ++ 7 files changed, 54 insertions(+), 20 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index f67d197..cf73bf7 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -46,28 +46,45 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) file(GLOB_RECURSE SOURCES "src/*.cpp") file(GLOB_RECURSE HEADERS "src/*.hpp") -# Add custom target to run cmake_prebuild.sh at the start of the build process -add_custom_target(run_prebuild_script ALL +# Define the generated output files +set(AGENT_REMOTE_CPP ${CMAKE_CURRENT_SOURCE_DIR}/src/autogen/_agent-remote.cpp) +set(AGENT_LOCAL_CPP ${CMAKE_CURRENT_SOURCE_DIR}/src/autogen/_agent-local.cpp) + +# Get list of input files that trigger regeneration +file(GLOB AGENT_REMOTE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/agent-remote/*") +file(GLOB AGENT_LOCAL_FILES "${CMAKE_CURRENT_SOURCE_DIR}/agent-local/*") + +# Custom command with proper dependency tracking +# Runs cmake_prebuild.sh only when input files change or outputs are missing +add_custom_command( + OUTPUT ${AGENT_REMOTE_CPP} ${AGENT_LOCAL_CPP} COMMAND ${CMAKE_COMMAND} -E echo "Running cmake_prebuild.sh..." - COMMAND ${CMAKE_COMMAND} -E env bash ${CMAKE_CURRENT_SOURCE_DIR}/cmake_prebuild.sh + COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/cmake_prebuild.sh + DEPENDS + ${AGENT_REMOTE_FILES} + ${AGENT_LOCAL_FILES} + ${CMAKE_CURRENT_SOURCE_DIR}/cmake_prebuild.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Generating agent source files from agent-remote/ and agent-local/" ) +# Custom target for manual invocation (e.g., "ninja run_prebuild_script") +add_custom_target(run_prebuild_script DEPENDS ${AGENT_REMOTE_CPP} ${AGENT_LOCAL_CPP}) + # Add executable add_executable(dropshell ${SOURCES}) -add_dependencies(dropshell run_prebuild_script) # Mark the generated files as GENERATED so CMake knows they'll be created during build set_source_files_properties( - ${CMAKE_CURRENT_SOURCE_DIR}/src/autogen/_agent-remote.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/autogen/_agent-local.cpp + ${AGENT_REMOTE_CPP} + ${AGENT_LOCAL_CPP} PROPERTIES GENERATED TRUE ) -# Explicitly add the generated agent files, as they might not be in the source directory when globbed at the start. +# Explicitly add the generated agent files target_sources(dropshell PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/src/autogen/_agent-remote.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/autogen/_agent-local.cpp + ${AGENT_REMOTE_CPP} + ${AGENT_LOCAL_CPP} ) # Set include directories diff --git a/source/agent-remote/agent-install.sh b/source/agent-remote/agent-install.sh index a5d5676..8cd0d4a 100755 --- a/source/agent-remote/agent-install.sh +++ b/source/agent-remote/agent-install.sh @@ -71,6 +71,8 @@ install_bb64 # confirm we're in a good state. +echo "Confirming state..." + required_files=( "$AGENT_PATH/bb64" "$AGENT_PATH/common.sh" @@ -87,6 +89,10 @@ done #------------------------------------------------------------------------- +chmod a+x ${AGENT_PATH}/*.sh + +#------------------------------------------------------------------------- + echo "Completed dropshell agent installation." #------------------------------------------------------------------------- diff --git a/source/cmake_prebuild.sh b/source/cmake_prebuild.sh index e1e3d18..efd5ab5 100755 --- a/source/cmake_prebuild.sh +++ b/source/cmake_prebuild.sh @@ -4,10 +4,6 @@ set -e # CMake pre-build script. # Runs before the build process. -# This script creates two files: -# src/utils/createagent.hpp -# src/utils/createagent.cpp - SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Create temporary directory for dehydrate diff --git a/source/src/commands/install.cpp b/source/src/commands/install.cpp index a5a26e5..e4aefe6 100644 --- a/source/src/commands/install.cpp +++ b/source/src/commands/install.cpp @@ -531,13 +531,12 @@ complete -F _dropshell_completions ds // create server_info.env info << "Creating server_info.env on remote server... " < "+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; - } + shared_commands::rsync_file_to_remote(lsiep,rsiep,server,false,user.user); + if (std::filesystem::exists(lsiep)) std::filesystem::remove(lsiep); info << "done." << std::endl; // run the agent installer. Can't use BB64 yet, as we're installing it on the remote server. diff --git a/source/src/commands/shared_commands.cpp b/source/src/commands/shared_commands.cpp index 2dc9422..a1dfd66 100644 --- a/source/src/commands/shared_commands.cpp +++ b/source/src/commands/shared_commands.cpp @@ -83,7 +83,7 @@ namespace dropshell std::string user) { ASSERT(!local_path.empty() && !remote_path.empty(), "Local or remote path not specified. Can't rsync."); - ASSERT(std::filesystem::is_block_file(local_path), "Local path is not a file. Can't rsync."); + ASSERT(std::filesystem::is_regular_file(local_path), "Local path "+local_path+" is not a file. Can't rsync."); std::string rsync_cmd = "rsync --mkpath -zpc -e 'ssh -p " + server_env.get_SSH_PORT() + "' " + quote(local_path) + " " + diff --git a/source/src/servers.cpp b/source/src/servers.cpp index 667efff..0ec105c 100644 --- a/source/src/servers.cpp +++ b/source/src/servers.cpp @@ -202,6 +202,20 @@ namespace dropshell return it != mUsers.end(); } + bool ServerConfig::createServerInfoEnv(std::string filepath) const + { + std::ofstream ofs(filepath); + if (!ofs.is_open()) + { + error << "Couldn't write to " << filepath << std::endl; + return false; + } + ofs << "# Autogenerated file by dropshell on installation." << std::endl; + ofs << "SERVER=\"" << mServerName << "\"" << std::endl; + ofs.close(); + return true; + } + bool ServerConfig::check_remote_dir_exists(const std::string &dir_path, std::string user) const { if (user.empty()) diff --git a/source/src/servers.hpp b/source/src/servers.hpp index 8f9ce35..8ea7e4e 100644 --- a/source/src/servers.hpp +++ b/source/src/servers.hpp @@ -64,6 +64,8 @@ namespace dropshell // helper functions bool hasUser(const std::string &user) const; + bool createServerInfoEnv(std::string filepath) const; + public: bool check_remote_dir_exists(const std::string &dir_path, std::string user) const; bool check_remote_file_exists(const std::string &file_path, std::string user) const;