This commit is contained in:
parent
22e37b212a
commit
2cc00244c6
89
make_createagent.sh
Normal file
89
make_createagent.sh
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script creates two files:
|
||||||
|
# src/utils/createagent.hpp
|
||||||
|
# src/utils/createagent.cpp
|
||||||
|
#
|
||||||
|
|
||||||
|
SCRIPT_DIR=$(dirname "$0")
|
||||||
|
|
||||||
|
|
||||||
|
# heredoc to create the createagent.hpp file.
|
||||||
|
cat <<EOF > "$SCRIPT_DIR/src/utils/createagent.hpp"
|
||||||
|
#ifndef CREATEAGENT_HPP
|
||||||
|
#define CREATEAGENT_HPP
|
||||||
|
|
||||||
|
namespace dropshell {
|
||||||
|
int create_agent(const std::string &server_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CREATEAGENT_HPP
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
# heredoc to create the createagent.cpp file.
|
||||||
|
cat <<CPPEOF > "$SCRIPT_DIR/src/utils/createagent.cpp"
|
||||||
|
#include "createagent.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace dropshell {
|
||||||
|
|
||||||
|
void load_agent_file_contents(std::vector<std::AgentFile> &agent_file_contents);
|
||||||
|
|
||||||
|
|
||||||
|
struct AgentFile {
|
||||||
|
std::string filename;
|
||||||
|
std::string content;
|
||||||
|
};
|
||||||
|
|
||||||
|
int remote_write_file(const SSH_INFO &ssh_info, AgentFile &file);
|
||||||
|
|
||||||
|
int create_agent(const std::string &server_name) {
|
||||||
|
// create the sh file on the remote server.
|
||||||
|
server_env_manager server_env(server_name);
|
||||||
|
if (!server_env.is_valid()) {
|
||||||
|
std::cerr << "Invalid server environment for " << server_name << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the agent directory.
|
||||||
|
std::string agent_dir = remotepath::agent(server_name);
|
||||||
|
remote_create_directory(server_env.get_SSH_INFO(), agent_dir);
|
||||||
|
|
||||||
|
std::vector<AgentFile> agent_files;
|
||||||
|
load_agent_file_contents(agent_files);
|
||||||
|
|
||||||
|
// create the sh file on the remote server.
|
||||||
|
for (const auto &file : agent_files) {
|
||||||
|
// write out the file contents in the file.
|
||||||
|
remote_write_file(server_env.get_SSH_INFO(), file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int remote_write_file(const SSH_INFO &ssh_info, AgentFile &file)
|
||||||
|
{
|
||||||
|
std::string generate_command = "cat <<'GENERATE_EOF' > " + file.filename + "\n" + file.content + "\nGENERATE_EOF\n"; // use heredoc to write the file.
|
||||||
|
return execute_ssh_command(ssh_info, sCommand(generate_command), cMode::Defaults);
|
||||||
|
}
|
||||||
|
|
||||||
|
// auto generated load_agent_file_contents function goes here, followed by closing } for namespace dropshell.
|
||||||
|
int load_agent_file_contents(std::vector<AgentFile> &agent_files)
|
||||||
|
{
|
||||||
|
agent_files={
|
||||||
|
CPPEOF
|
||||||
|
|
||||||
|
AGENT_SOURCE_FOLDER="$SCRIPT_DIR/agent"
|
||||||
|
|
||||||
|
# find all the files in the agent source folder.
|
||||||
|
find "$AGENT_SOURCE_FOLDER" -type f | while read -r file; do
|
||||||
|
# get the filename without the path.
|
||||||
|
filename=$(basename "$file")
|
||||||
|
echo " AgentFile { \"$filename\", R\"AGENTFILE(" >> "$SCRIPT_DIR/src/utils/createagent.cpp"
|
||||||
|
cat "$file" >> "$SCRIPT_DIR/src/utils/createagent.cpp"
|
||||||
|
echo ")AGENTFILE\" }," >> "$SCRIPT_DIR/src/utils/createagent.cpp"
|
||||||
|
done
|
||||||
|
|
||||||
|
# close the namespace dropshell.
|
||||||
|
echo "}; return 0;} // namespace dropshell" >> "$SCRIPT_DIR/src/utils/createagent.cpp"
|
@ -66,6 +66,8 @@ namespace dropshell {
|
|||||||
// |-- backups
|
// |-- backups
|
||||||
// |-- temp_files
|
// |-- temp_files
|
||||||
// |-- agent
|
// |-- agent
|
||||||
|
// | |-- bb64
|
||||||
|
// | |-- (other agent files, including _allservicesstatus.sh)
|
||||||
// |-- services
|
// |-- services
|
||||||
// |-- service name
|
// |-- service name
|
||||||
// |-- config
|
// |-- config
|
||||||
|
Loading…
x
Reference in New Issue
Block a user