.
This commit is contained in:
@@ -134,14 +134,24 @@ std::string get_local_service_env_path(const std::string &server_name, const std
|
||||
return env.get_DROPSHELL_DIR();
|
||||
}
|
||||
|
||||
std::string get_remote_service_path(const std::string &server_name, const std::string &service_name)
|
||||
std::string get_remote_services_path(const std::string &server_name)
|
||||
{
|
||||
if (server_name.empty() || service_name.empty())
|
||||
if (server_name.empty())
|
||||
return std::string();
|
||||
std::string dropshell_path = get_remote_DROPSHELL_path(server_name);
|
||||
if (dropshell_path.empty())
|
||||
return std::string();
|
||||
return (fs::path(dropshell_path) / service_name).string();
|
||||
return (fs::path(dropshell_path) / "services").string();
|
||||
}
|
||||
|
||||
std::string get_remote_service_path(const std::string &server_name, const std::string &service_name)
|
||||
{
|
||||
if (server_name.empty() || service_name.empty())
|
||||
return std::string();
|
||||
std::string services_path = get_remote_services_path(server_name);
|
||||
if (services_path.empty())
|
||||
return std::string();
|
||||
return (fs::path(services_path) / service_name).string();
|
||||
}
|
||||
|
||||
std::string get_remote_service_config_path(const std::string &server_name, const std::string &service_name)
|
||||
|
@@ -23,14 +23,16 @@ namespace dropshell {
|
||||
|
||||
// remote paths
|
||||
// DROPSHELL_DIR
|
||||
// |-- service name
|
||||
// |-- config
|
||||
// |-- service.env
|
||||
// |-- (user config files)
|
||||
// |-- template
|
||||
// |-- (script files)
|
||||
// |-- backups
|
||||
// |-- backups
|
||||
// |-- services
|
||||
// |-- service name
|
||||
// |-- config <-- this is passed as argument to all scripts
|
||||
// |-- service.env
|
||||
// |-- (user config files)
|
||||
// |-- template
|
||||
// |-- (script files)
|
||||
std::string get_remote_DROPSHELL_path(const std::string &server_name);
|
||||
std::string get_remote_services_path(const std::string &server_name);
|
||||
std::string get_remote_service_path(const std::string &server_name, const std::string &service_name);
|
||||
std::string get_remote_service_config_path(const std::string &server_name, const std::string &service_name);
|
||||
std::string get_remote_service_template_path(const std::string &server_name, const std::string &service_name);
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#include "utils.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
namespace dropshell {
|
||||
|
||||
@@ -10,4 +12,34 @@ void maketitle(const std::string& title) {
|
||||
std::cout << std::string(title.length() + 4, '-') << std::endl;
|
||||
}
|
||||
|
||||
bool replace_line_in_file(const std::string& file_path, const std::string& search_string, const std::string& replacement_line) {
|
||||
std::ifstream input_file(file_path);
|
||||
std::vector<std::string> file_lines;
|
||||
std::string line;
|
||||
|
||||
if (!input_file.is_open()) {
|
||||
std::cerr << "Error: Unable to open file: " << file_path << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
while (std::getline(input_file, line)) {
|
||||
if (line.find(search_string) != std::string::npos)
|
||||
file_lines.push_back(replacement_line);
|
||||
else
|
||||
file_lines.push_back(line);
|
||||
}
|
||||
input_file.close();
|
||||
|
||||
std::ofstream output_file(file_path);
|
||||
if (!output_file.is_open())
|
||||
{
|
||||
std::cerr << "Error: Unable to open file: " << file_path << std::endl;
|
||||
return false;
|
||||
}
|
||||
for (const auto& modified_line : file_lines)
|
||||
output_file << modified_line << "\n";
|
||||
output_file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
@@ -11,4 +11,6 @@ namespace dropshell {
|
||||
*/
|
||||
void maketitle(const std::string& title);
|
||||
|
||||
bool replace_line_in_file(const std::string& file_path, const std::string& search_string, const std::string& replacement_line);
|
||||
|
||||
} // namespace dropshell
|
Reference in New Issue
Block a user