Compare commits

...

4 Commits

Author SHA1 Message Date
434a2bc6da dropshell release 2025.0518.2245
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
2025-05-18 22:45:25 +12:00
cf8738aee9 dropshell release 2025.0518.2236
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
2025-05-18 22:37:00 +12:00
d80820db15 Back to issue from pre-refactor!
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
2025-05-18 20:23:15 +12:00
fb6974b51a Working on backup/restore.
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
2025-05-18 20:19:47 +12:00
13 changed files with 686 additions and 551 deletions

View File

@ -61,7 +61,7 @@ _autocommandrun_path() {
fi fi
;; ;;
restore) restore)
echo "Restoring path ${path}" echo "Restoring path ${path} from backup file ${backup_folder}/backup.tgz"
tar -xzvf ${backup_folder}/backup.tgz -C ${path} --strip-components=1 tar -xzvf ${backup_folder}/backup.tgz -C ${path} --strip-components=1
;; ;;
esac esac

View File

@ -162,71 +162,72 @@ bool recreate_tree(std::string destination_folder) {
"cC50Z3ogLUMgL3BhdGggLiAmJiBjaG93biAtUiAkTVlJRDokTVlHUlAgL2JhY2t1cCIKICAgICAg"\ "cC50Z3ogLUMgL3BhdGggLiAmJiBjaG93biAtUiAkTVlJRDokTVlHUlAgL2JhY2t1cCIKICAgICAg"\
"ICAgICAgZWxzZQogICAgICAgICAgICAgICAgZWNobyAiUGF0aCAke3BhdGh9IGRvZXMgbm90IGV4"\ "ICAgICAgZWxzZQogICAgICAgICAgICAgICAgZWNobyAiUGF0aCAke3BhdGh9IGRvZXMgbm90IGV4"\
"aXN0IC0gbm90aGluZyB0byBiYWNrdXAiCiAgICAgICAgICAgIGZpCiAgICAgICAgICAgIDs7CiAg"\ "aXN0IC0gbm90aGluZyB0byBiYWNrdXAiCiAgICAgICAgICAgIGZpCiAgICAgICAgICAgIDs7CiAg"\
"ICAgICAgcmVzdG9yZSkKICAgICAgICAgICAgZWNobyAiUmVzdG9ya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iZSBvbmUgb2Ygdm9sdW1lLCBwYXRo"\ "YWNrdXBfdGVtcF9wYXRofS8ke2Jmb2xkZXJ9IgogICAgICAgIG1rZGlyIC1wICR7dGFyZ2V0cGF0"\
"IG9yIGZpbGUKICAgICAgICBjYXNlICIka2V5IiBpbgogICAgICAgICAgICB2b2x1bWUpCiAgICAg"\ "aH0KCiAgICAgICAgIyBLZXkgbXVzdCBiZSBvbmUgb2Ygdm9sdW1lLCBwYXRoIG9yIGZpbGUKICAg"\
"ICAgICAgICAgICBfYXV0b2NvbW1hbmRydW5fdm9sdW1lICIkY29tbWFuZCIgIiR2YWx1ZSIgIiR0"\ "ICAgICBjYXNlICIka2V5IiBpbgogICAgICAgICAgICB2b2x1bWUpCiAgICAgICAgICAgICAgICBf"\
"YXJnZXRwYXRoIgogICAgICAgICAgICAgICAgOzsKICAgICAgICAgICAgcGF0aCkKICAgICAgICAg"\ "YXV0b2NvbW1hbmRydW5fdm9sdW1lICIkY29tbWFuZCIgIiR2YWx1ZSIgIiR0YXJnZXRwYXRoIgog"\
"ICAgICAgIF9hdXRvY29tbWFuZHJ1bl9wYXRoICIkY29tbWFuZCIgIiR2YWx1ZSIgIiR0YXJnZXRw"\ "ICAgICAgICAgICAgICAgOzsKICAgICAgICAgICAgcGF0aCkKICAgICAgICAgICAgICAgIF9hdXRv"\
"YXRoIgogICAgICAgICAgICAgICAgOzsKICAgICAgICAgICAgZmlsZSkKICAgICAgICAgICAgICAg"\ "Y29tbWFuZHJ1bl9wYXRoICIkY29tbWFuZCIgIiR2YWx1ZSIgIiR0YXJnZXRwYXRoIgogICAgICAg"\
"IF9hdXRvY29tbWFuZHJ1bl9maWxlICIkY29tbWFuZCIgIiR2YWx1ZSIgIiR0YXJnZXRwYXRoIgog"\ "ICAgICAgICAgOzsKICAgICAgICAgICAgZmlsZSkKICAgICAgICAgICAgICAgIF9hdXRvY29tbWFu"\
"ICAgICAgICAgICAgICAgOzsKICAgICAgICAgICAgKikKICAgICAgICAgICAg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CiAgICBlY2hvICJfYXV0b2NvbW1hbmRwYXJzZSBb"\
"IC1wICIkQkFDS1VQX1RFTVBfUEFUSCIKICAgIHRhciB6eHZmICIkQkFDS1VQX0ZJTEUiIC1DICIk"\ "cmVzdG9yZV0gWyRCQUNLVVBfVEVNUF9QQVRIXSBbJEBdIgoKICAgIG1rZGlyIC1wICIkQkFDS1VQ"\
"QkFDS1VQX1RFTVBfUEFUSCIgLS1zdHJpcC1jb21wb25lbnRzPTEKCiAgICBfYXV0b2NvbW1hbmRw"\ "X1RFTVBfUEFUSCIKICAgIHRhciB6eHZmICIkQkFDS1VQX0ZJTEUiIC1DICIkQkFDS1VQX1RFTVBf"\
"YXJzZSByZXN0b3JlICIkQkFDS1VQX1RFTVBfUEFUSCIgIiRAIgp9Cg=="; "UEFUSCIgLS1zdHJpcC1jb21wb25lbnRzPTEKCiAgICBfYXV0b2NvbW1hbmRwYXJzZSByZXN0b3Jl"\
"ICIkQkFDS1VQX1RFTVBfUEFUSCIgIiRAIgp9Cg==";
// Decode Base64 data // Decode Base64 data
size_t decoded_size = (strlen(filedata_base64) * 3) / 4; size_t decoded_size = (strlen(filedata_base64) * 3) / 4;
@ -234,7 +235,7 @@ bool recreate_tree(std::string destination_folder) {
size_t actual_size; size_t actual_size;
base64_decode(filedata_base64, strlen(filedata_base64), decoded_data, &actual_size); base64_decode(filedata_base64, strlen(filedata_base64), decoded_data, &actual_size);
bool file_written = _recreate_file_(outpath, 6443138635497166205ULL, std::filesystem::perms(493), decoded_data, actual_size); bool file_written = _recreate_file_(outpath, 10759194710819511084ULL, std::filesystem::perms(493), decoded_data, actual_size);
delete[] decoded_data; delete[] decoded_data;
any_written = any_written || file_written; any_written = any_written || file_written;
} }

View File

@ -16,18 +16,19 @@
#include "utils/directories.hpp" #include "utils/directories.hpp"
#include "shared_commands.hpp" #include "shared_commands.hpp"
namespace dropshell
{
namespace dropshell { int backupdata_handler(const CommandContext &ctx);
int backupdata_handler(const CommandContext& ctx); static std::vector<std::string> backupdata_name_list = {"backupdata", "bd", "backup", "bup"};
static std::vector<std::string> backupdata_name_list={"backupdata","bd","backup","bup"}; // Static registration
struct BackupDataCommandRegister
// Static registration {
struct BackupDataCommandRegister { BackupDataCommandRegister()
BackupDataCommandRegister() { {
CommandRegistry::instance().register_command({ CommandRegistry::instance().register_command({backupdata_name_list,
backupdata_name_list,
backupdata_handler, backupdata_handler,
shared_commands::std_autocomplete_allowall, shared_commands::std_autocomplete_allowall,
false, // hidden false, // hidden
@ -45,14 +46,15 @@ struct BackupDataCommandRegister {
Note: This command will not create any data or configuration. Note: This command will not create any data or configuration.
It will simply backup the data on the remote server, saving it to a local file. It will simply backup the data on the remote server, saving it to a local file.
Restore the data with restore. Restore the data with restore.
)" )"});
});
} }
} backupdata_command_register; } backupdata_command_register;
namespace shared_commands
{
bool backupdata_service(const std::string& server, const std::string& service) bool backupdata_service(const std::string &server, const std::string &service)
{ {
server_env_manager server_env(server); server_env_manager server_env(server);
if (!server_env.is_valid()) if (!server_env.is_valid())
{ {
@ -69,7 +71,8 @@ bool backupdata_service(const std::string& server, const std::string& service)
const std::string command = "backup"; const std::string command = "backup";
if (!gTemplateManager().template_command_exists(sinfo.template_name, command)) { if (!gTemplateManager().template_command_exists(sinfo.template_name, command))
{
info << service << " has no data to backup" << std::endl; info << service << " has no data to backup" << std::endl;
debug << "(no backup script for " << sinfo.template_name << ")" << std::endl; debug << "(no backup script for " << sinfo.template_name << ")" << std::endl;
return true; // nothing to back up. return true; // nothing to back up.
@ -79,11 +82,9 @@ bool backupdata_service(const std::string& server, const std::string& service)
std::string remote_service_template_path = remotepath::service_template(server, service); std::string remote_service_template_path = remotepath::service_template(server, service);
std::string remote_command_script_file = remote_service_template_path + "/" + command + ".sh"; std::string remote_command_script_file = remote_service_template_path + "/" + command + ".sh";
std::string remote_service_config_path = remotepath::service_config(server, service); std::string remote_service_config_path = remotepath::service_config(server, service);
if (!server_env.check_remote_items_exist({ if (!server_env.check_remote_items_exist({remotepath::service(server, service),
remotepath::service(server, service),
remote_command_script_file, remote_command_script_file,
remotefile::service_env(server, service)}) remotefile::service_env(server, service)}))
)
{ {
error << "Error: Required service directories not found on remote server" << std::endl; error << "Error: Required service directories not found on remote server" << std::endl;
info << "Is the service installed?" << std::endl; info << "Is the service installed?" << std::endl;
@ -92,16 +93,18 @@ bool backupdata_service(const std::string& server, const std::string& service)
// Create backups directory on server if it doesn't exist // Create backups directory on server if it doesn't exist
std::string remote_backups_dir = remotepath::backups(server); std::string remote_backups_dir = remotepath::backups(server);
debug << "Remote backups directory on "<< server <<": " << remote_backups_dir << std::endl; debug << "Remote backups directory on " << server << ": " << remote_backups_dir << std::endl;
std::string mkdir_cmd = "mkdir -p " + quote(remote_backups_dir); std::string mkdir_cmd = "mkdir -p " + quote(remote_backups_dir);
if (!execute_ssh_command(server_env.get_SSH_INFO(), sCommand("",mkdir_cmd, {}), cMode::Defaults)) { if (!execute_ssh_command(server_env.get_SSH_INFO(), sCommand("", mkdir_cmd, {}), cMode::Defaults))
{
error << "Failed to create backups directory on server" << std::endl; error << "Failed to create backups directory on server" << std::endl;
return false; return false;
} }
// Create backups directory locally if it doesn't exist // Create backups directory locally if it doesn't exist
std::string local_backups_dir = gConfig().get_local_backup_path(); std::string local_backups_dir = gConfig().get_local_backup_path();
if (local_backups_dir.empty()) { if (local_backups_dir.empty())
{
error << "Error: Local backups directory not found" << std::endl; error << "Error: Local backups directory not found" << std::endl;
info << "Run 'dropshell edit' to configure DropShell" << std::endl; info << "Run 'dropshell edit' to configure DropShell" << std::endl;
return false; return false;
@ -111,7 +114,8 @@ bool backupdata_service(const std::string& server, const std::string& service)
// Get current datetime for backup filename // Get current datetime for backup filename
shared_commands::cBackupFileName backup_filename_construction(server, service, sinfo.template_name); shared_commands::cBackupFileName backup_filename_construction(server, service, sinfo.template_name);
if (!backup_filename_construction.is_valid()) { if (!backup_filename_construction.is_valid())
{
error << "Invalid backup filename" << std::endl; error << "Invalid backup filename" << std::endl;
return false; return false;
} }
@ -126,47 +130,45 @@ bool backupdata_service(const std::string& server, const std::string& service)
{ // Run backup script { // Run backup script
shared_commands::cRemoteTempFolder remote_temp_folder(server_env); shared_commands::cRemoteTempFolder remote_temp_folder(server_env);
if (!server_env.run_remote_template_command(service, command, {}, false, {{"BACKUP_FILE", remote_backup_file_path}, {"TEMP_DIR", remote_temp_folder.path()}})) { if (!server_env.run_remote_template_command(service, command, {}, false, {{"BACKUP_FILE", remote_backup_file_path}, {"TEMP_DIR", remote_temp_folder.path()}}))
{
error << "Backup script failed on remote server: " << remote_backup_file_path << std::endl; error << "Backup script failed on remote server: " << remote_backup_file_path << std::endl;
return false; return false;
} }
// Copy backup file from server to local // Copy backup file from server to local
if (!shared_commands::scp_file_from_remote(server_env, remote_backup_file_path, local_backup_file_path, false)) { if (!shared_commands::scp_file_from_remote(server_env, remote_backup_file_path, local_backup_file_path, false))
{
error << "Failed to copy backup file from server" << std::endl; error << "Failed to copy backup file from server" << std::endl;
return false; return false;
} }
} // dtor of remote_temp_folder will clean up the temp folder on the server } // dtor of remote_temp_folder will clean up the temp folder on the server
info << "Backup created successfully. Restore with:"<<std::endl; info << "Backup created successfully. Restore with:" << std::endl;
info << " dropshell restore " << server << " " << service << " " << backup_filename << std::endl; info << " dropshell restore " << server << " " << service << " " << backup_filename << std::endl;
return true; return true;
}
int backupdata_handler(const CommandContext& ctx)
{
if (ctx.args.size() < 1)
{
error << "Server name is required" << std::endl;
return 1;
} }
} // namespace shared_commands
int backupdata_handler(const CommandContext &ctx)
{
ASSERT(ctx.args.size() == 2, "Invalid number of arguments");
std::string server = safearg(ctx.args, 0); std::string server = safearg(ctx.args, 0);
std::string service = safearg(ctx.args, 1);
if (ctx.args.size() < 2) if (service == "all")
{ {
// backup all services on the server // backup all services on the server
maketitle("Backing up data for all services on " + server); maketitle("Backing up data for all services on " + server);
bool okay = true; bool okay = true;
std::vector<LocalServiceInfo> services = get_server_services_info(server); std::vector<LocalServiceInfo> services = get_server_services_info(server);
for (const auto &service : services) for (const LocalServiceInfo &si : services)
okay &= backupdata_service(server, service.service_name); okay &= shared_commands::backupdata_service(server, si.service_name);
return okay ? 0 : 1; return okay ? 0 : 1;
} }
std::string service = safearg(ctx.args, 1); return shared_commands::backupdata_service(server, service) ? 0 : 1;
return backupdata_service(server, service); }
}
} // namespace dropshell } // namespace dropshell

View File

@ -11,7 +11,6 @@ namespace dropshell
{ {
int create_service_handler(const CommandContext &ctx); int create_service_handler(const CommandContext &ctx);
bool create_service(const std::string &server_name, const std::string &template_name, const std::string &service_name, bool silent);
void create_service_autocomplete(const CommandContext &ctx); void create_service_autocomplete(const CommandContext &ctx);
static std::vector<std::string> create_service_name_list = {"create-service"}; static std::vector<std::string> create_service_name_list = {"create-service"};
@ -45,7 +44,7 @@ namespace dropshell
std::string service = safearg(ctx.args, 1); std::string service = safearg(ctx.args, 1);
std::string template_name = safearg(ctx.args, 2); std::string template_name = safearg(ctx.args, 2);
return create_service(server, template_name, service, false) ? 0 : 1; return shared_commands::create_service(server, template_name, service) ? 0 : 1;
} }
void create_service_autocomplete(const CommandContext &ctx) void create_service_autocomplete(const CommandContext &ctx)
@ -58,12 +57,15 @@ namespace dropshell
{ {
std::set<std::string> templates = gTemplateManager().get_template_list(); std::set<std::string> templates = gTemplateManager().get_template_list();
for (const auto &template_name : templates) for (const auto &template_name : templates)
std::cout << template_name << std::endl; rawout << template_name << std::endl;
} }
} }
} }
bool create_service(const std::string &server_name, const std::string &template_name, const std::string &service_name, bool silent) namespace shared_commands
{
bool create_service(const std::string &server_name, const std::string &template_name, const std::string &service_name)
{ {
if (server_name.empty() || template_name.empty() || service_name.empty()) if (server_name.empty() || template_name.empty() || service_name.empty())
return false; return false;
@ -72,44 +74,34 @@ namespace dropshell
if (service_dir.empty()) if (service_dir.empty())
{ {
if (!silent) error << "Couldn't locate server " << server_name << " in any config directory" << std::endl;
{ info << "Please check the server name is correct and try again" << std::endl;
std::cerr << "Error: Couldn't locate server " << server_name << " in any config directory" << std::endl; info << "You can list all servers with 'dropshell servers'" << std::endl;
std::cerr << "Please check the server name is correct and try again" << std::endl; info << "You can create a new server with 'dropshell create-server " << server_name << "'" << std::endl;
std::cerr << "You can list all servers with 'dropshell servers'" << std::endl;
std::cerr << "You can create a new server with 'dropshell create-server " << server_name << "'" << std::endl;
}
return false; return false;
} }
if (std::filesystem::exists(service_dir)) if (std::filesystem::exists(service_dir))
{ {
if (!silent) error << "Service already exists: " << service_name << std::endl;
{ debug << "Current service path: " << service_dir << std::endl;
std::cerr << "Error: Service already exists: " << service_name << std::endl;
std::cerr << "Current service path: " << service_dir << std::endl;
}
return false; return false;
} }
template_info tinfo = gTemplateManager().get_template_info(template_name); template_info tinfo = gTemplateManager().get_template_info(template_name);
if (!tinfo.is_set()) if (!tinfo.is_set())
{ {
if (!silent) error << "Template '" << template_name << "' not found" << std::endl;
{ info << "Please check the template name is correct and try again" << std::endl;
std::cerr << "Error: Template '" << template_name << "' not found" << std::endl; info << "You can list all templates with 'dropshell templates'" << std::endl;
std::cerr << "Please check the template name is correct and try again" << std::endl; info << "You can create a new template with 'dropshell create-template " << template_name << "'" << std::endl;
std::cerr << "You can list all templates with 'dropshell templates'" << std::endl;
std::cerr << "You can create a new template with 'dropshell create-template " << template_name << "'" << std::endl;
}
return false; return false;
} }
// check template is all good. // check template is all good.
if (!gTemplateManager().test_template(tinfo.local_template_path())) if (!gTemplateManager().test_template(tinfo.local_template_path()))
{ {
if (!silent) error << "Template '" << template_name << "' is not valid" << std::endl;
std::cerr << "Error: Template '" << template_name << "' is not valid" << std::endl;
return false; return false;
} }
@ -119,15 +111,14 @@ namespace dropshell
// copy the template config files to the service directory // copy the template config files to the service directory
recursive_copy(tinfo.local_template_path() / "config", service_dir); recursive_copy(tinfo.local_template_path() / "config", service_dir);
if (!silent) info << "Service " << service_name << " created successfully" << std::endl;
{ info << std::endl;
std::cout << "Service " << service_name << " created successfully" << std::endl; info << "To complete the installation, please:" << std::endl;
std::cout << std::endl; info << "1. edit the service config file: dropshell edit " << server_name << " " << service_name << std::endl;
std::cout << "To complete the installation, please:" << std::endl; info << "2. install the remote service: dropshell install " << server_name << " " << service_name << std::endl;
std::cout << "1. edit the service config file: dropshell edit " << server_name << " " << service_name << std::endl;
std::cout << "2. install the remote service: dropshell install " << server_name << " " << service_name << std::endl;
}
return true; return true;
} }
} // namespace shared_commands
} // namespace dropshell } // namespace dropshell

View File

@ -53,11 +53,13 @@ namespace dropshell
} }
} install_command_register; } install_command_register;
namespace shared_commands
{
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// install service over ssh : SHARED COMMAND // install service over ssh : SHARED COMMAND
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool install_service(const std::string &server, const std::string &service, bool silent) bool install_service(const std::string &server, const std::string &service)
{ {
LocalServiceInfo service_info = get_service_info(server, service); LocalServiceInfo service_info = get_service_info(server, service);
if (!SIvalid(service_info)) if (!SIvalid(service_info))
@ -104,7 +106,7 @@ namespace dropshell
debug << "Copying: [LOCAL] " << tinfo.local_template_path() << std::endl debug << "Copying: [LOCAL] " << tinfo.local_template_path() << std::endl
<< std::string(8, ' ') << "[REMOTE] " << remotepath::service_template(server, service) << "/" << std::endl; << std::string(8, ' ') << "[REMOTE] " << remotepath::service_template(server, service) << "/" << std::endl;
if (!shared_commands::rsync_tree_to_remote(tinfo.local_template_path().string(), remotepath::service_template(server, service), if (!shared_commands::rsync_tree_to_remote(tinfo.local_template_path().string(), remotepath::service_template(server, service),
server_env, silent)) server_env, false))
{ {
std::cerr << "Failed to copy template files using rsync" << std::endl; std::cerr << "Failed to copy template files using rsync" << std::endl;
return false; return false;
@ -114,7 +116,7 @@ namespace dropshell
debug << "Copying: [LOCAL] " << localpath::service(server, service) << std::endl debug << "Copying: [LOCAL] " << localpath::service(server, service) << std::endl
<< std::string(8, ' ') << "[REMOTE] " << remotepath::service_config(server, service) << std::endl; << std::string(8, ' ') << "[REMOTE] " << remotepath::service_config(server, service) << std::endl;
if (!shared_commands::rsync_tree_to_remote(localpath::service(server, service), remotepath::service_config(server, service), if (!shared_commands::rsync_tree_to_remote(localpath::service(server, service), remotepath::service_config(server, service),
server_env, silent)) server_env, false))
{ {
std::cerr << "Failed to copy service files using rsync" << std::endl; std::cerr << "Failed to copy service files using rsync" << std::endl;
return false; return false;
@ -123,7 +125,7 @@ namespace dropshell
// Run install script // Run install script
{ {
info << "Running " << service_info.template_name << " install script on " << server << "..." << std::endl; info << "Running " << service_info.template_name << " install script on " << server << "..." << std::endl;
server_env.run_remote_template_command(service, "install", {}, silent, {}); server_env.run_remote_template_command(service, "install", {}, false, {});
} }
// print health tick // print health tick
@ -131,6 +133,7 @@ namespace dropshell
return true; return true;
} }
} // namespace shared_commands
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// update_dropshell // update_dropshell
@ -305,14 +308,15 @@ namespace dropshell
info << "done." << std::endl; info << "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!
info << "Installing bb64 on " << server << "..." << std::endl << std::flush; info << "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 +
" 'mkdir -p " + quote(agent_path) + " && curl -fsSL \"https://gitea.jde.nz/public/bb64/releases/download/latest/install.sh\" | bash -s -- " + " 'mkdir -p " + quote(agent_path) + " && curl -fsSL \"https://gitea.jde.nz/public/bb64/releases/download/latest/install.sh\" | bash -s -- " +
quote(agent_path) + " " + quote("$(id -u " + server_env.get_SSH_USER() + "):$(id -g " + server_env.get_SSH_USER() + ")") + "'"; quote(agent_path) + " " + quote("$(id -u " + server_env.get_SSH_USER() + "):$(id -g " + server_env.get_SSH_USER() + ")") + "'";
//std::cout << "Executing: " << remote_cmd << std::endl; // std::cout << "Executing: " << remote_cmd << std::endl;
if (!execute_local_command("", remote_cmd, {}, nullptr, cMode::Silent)) if (!execute_local_command("", remote_cmd, {}, nullptr, cMode::Silent))
error << "Failed to download bb64 to " << agent_path << " on remote server." << std::endl; error << "Failed to download bb64 to " << agent_path << " on remote server." << std::endl;
else else
@ -362,7 +366,7 @@ namespace dropshell
std::vector<LocalServiceInfo> services = get_server_services_info(server); std::vector<LocalServiceInfo> services = get_server_services_info(server);
for (const auto &service : services) for (const auto &service : services)
{ {
if (!install_service(server, service.service_name, false)) if (!shared_commands::install_service(server, service.service_name))
okay = false; okay = false;
} }
return okay ? 0 : 1; return okay ? 0 : 1;
@ -370,7 +374,7 @@ namespace dropshell
else else
{ // install the specific service. { // install the specific service.
std::string service = safearg(ctx.args, 1); std::string service = safearg(ctx.args, 1);
return install_service(server, service, false) ? 0 : 1; return shared_commands::install_service(server, service) ? 0 : 1;
} }
} }

View File

@ -10,16 +10,18 @@
#include "utils/assert.hpp" #include "utils/assert.hpp"
namespace dropshell { namespace dropshell
{
int nuke_handler(const CommandContext& ctx); int nuke_handler(const CommandContext &ctx);
static std::vector<std::string> nuke_name_list={"nuke"}; static std::vector<std::string> nuke_name_list = {"nuke"};
// Static registration // Static registration
struct NukeCommandRegister { struct NukeCommandRegister
NukeCommandRegister() { {
CommandRegistry::instance().register_command({ NukeCommandRegister()
nuke_name_list, {
CommandRegistry::instance().register_command({nuke_name_list,
nuke_handler, nuke_handler,
shared_commands::std_autocomplete, shared_commands::std_autocomplete,
false, // hidden false, // hidden
@ -41,13 +43,15 @@ struct NukeCommandRegister {
both on the dropshell host and on the remote server. both on the dropshell host and on the remote server.
Use with caution! Use with caution!
)" )"});
});
} }
} nuke_command_register; } nuke_command_register;
int nuke_one(std::string server, std::string service) namespace shared_commands
{ {
bool nuke_service(const std::string &server, const std::string &service)
{
server_env_manager server_env(server); server_env_manager server_env(server);
// step 1 - nuke on remote server. // step 1 - nuke on remote server.
@ -57,7 +61,7 @@ int nuke_one(std::string server, std::string service)
service_info = get_service_info(server, service); service_info = get_service_info(server, service);
if (!SIvalid(service_info)) if (!SIvalid(service_info))
error << "Warning: Invalid service: " << service << std::endl; error << "Invalid service: " << service << std::endl;
if (server_env.check_remote_dir_exists(remotepath::service(server, service))) if (server_env.check_remote_dir_exists(remotepath::service(server, service)))
{ {
@ -107,11 +111,12 @@ int nuke_one(std::string server, std::string service)
info << "Nuked service " << service << " on server " << server << std::endl; info << "Nuked service " << service << " on server " << server << std::endl;
return 0; return true;
} }
} // namespace shared_commands
int nuke_handler(const CommandContext &ctx) int nuke_handler(const CommandContext &ctx)
{ {
ASSERT(ctx.args.size() == 2, "Usage: nuke SERVER SERVICE|all (requires 2 args - you supplied " + std::to_string(ctx.args.size()) + ")"); ASSERT(ctx.args.size() == 2, "Usage: nuke SERVER SERVICE|all (requires 2 args - you supplied " + std::to_string(ctx.args.size()) + ")");
ASSERT(gConfig().is_config_set(), "No configuration found. Please run 'dropshell config' to set up your configuration."); ASSERT(gConfig().is_config_set(), "No configuration found. Please run 'dropshell config' to set up your configuration.");
@ -130,20 +135,20 @@ int nuke_handler(const CommandContext &ctx)
return 1; return 1;
} }
for (const auto& entry : std::filesystem::directory_iterator(server_path)) for (const auto &entry : std::filesystem::directory_iterator(server_path))
{ {
if (entry.is_directory() && entry.path().filename().string().find(".") != 0) if (entry.is_directory() && entry.path().filename().string().find(".") != 0)
{ {
std::string service_name = entry.path().filename().string(); std::string service_name = entry.path().filename().string();
rval |= nuke_one(server, service_name); rval |= (shared_commands::nuke_service(server, service_name) ? 0 : 1);
} }
} }
return rval; return rval;
} }
else else
{ {
return nuke_one(server, service); return (shared_commands::nuke_service(server, service) ? 0 : 1);
}
} }
}
} // namespace dropshell } // namespace dropshell

View File

@ -16,21 +16,21 @@
#include "utils/directories.hpp" #include "utils/directories.hpp"
#include "shared_commands.hpp" #include "shared_commands.hpp"
namespace dropshell
{
namespace dropshell { int restoredata_handler(const CommandContext &ctx);
int restoredata_handler(const CommandContext& ctx); void restoredata_autocomplete(const CommandContext &ctx);
void restoredata_autocomplete(const CommandContext& ctx); static std::vector<std::string> restoredata_name_list = {"restoredata", "rd", "restore", "rest"};
// Static registration
static std::vector<std::string> restoredata_name_list={"restoredata","rd","restore","rest"}; struct RestoreDataCommandRegister
{
// Static registration RestoreDataCommandRegister()
struct RestoreDataCommandRegister { {
RestoreDataCommandRegister() { CommandRegistry::instance().register_command({restoredata_name_list,
CommandRegistry::instance().register_command({
restoredata_name_list,
restoredata_handler, restoredata_handler,
restoredata_autocomplete, restoredata_autocomplete,
false, // hidden false, // hidden
@ -38,100 +38,214 @@ struct RestoreDataCommandRegister {
true, // requires_install true, // requires_install
3, // min_args (after command) 3, // min_args (after command)
3, // max_args (after command) 3, // max_args (after command)
"restoredata SERVER SERVICE BACKUP_FILE", "restoredata SERVER SERVICE BACKUP_FILE|latest",
"Restore data for a service on a server, overwriting the existing data.", "Restore data for a service on a server, overwriting the existing data.",
// heredoc // heredoc
R"( R"(
restoredata SERVER SERVICE BACKUP_FILE Restore data to a service on a server. Destructive. restoredata SERVER SERVICE BACKUP_FILE Restore data to a service on a server. Destructive.
restoredata SERVER SERVICE latest Restore the latest backup for the given service.
Note: This command will not create any service configuration, you need Note: This command will not create any service configuration, you need
to have a valid service installed first. to have a valid service installed first.
The backup file must be in the local backups directory. The backup file must be in the local backups directory.
WARNING: This will permanently overwrite the service's data on the remote server! WARNING: This will permanently overwrite the service's data on the remote server!
)" )"});
});
} }
} restoredata_command_register; } restoredata_command_register;
std::vector<shared_commands::cBackupFileName> get_backup_files(const std::string &server, const std::string &match_service = "", const std::string &match_template_name = "")
{
std::string local_backups_dir = gConfig().get_local_backup_path();
if (local_backups_dir.empty() || !std::filesystem::exists(local_backups_dir))
{
error << "Error: Local backups directory not found: " << local_backups_dir << std::endl;
return {};
}
int restoredata_handler(const CommandContext& ctx) std::vector<shared_commands::cBackupFileName> backups;
{ for (const auto &entry : std::filesystem::directory_iterator(local_backups_dir))
ASSERT(ctx.args.size() == 2, "Invalid number of arguments"); {
if (!entry.is_regular_file())
continue;
std::string filename = entry.path().filename().string();
shared_commands::cBackupFileName backup_details(filename);
if (backup_details.is_valid())
if (match_service.empty() || backup_details.get_service() == match_service)
if (match_template_name.empty() || backup_details.get_template_name() == match_template_name)
backups.push_back(backup_details);
}
// sort backups by datetime
std::sort(backups.begin(), backups.end(), [](const shared_commands::cBackupFileName &a, const shared_commands::cBackupFileName &b)
{ return a.get_datetime() > b.get_datetime(); });
return backups;
}
int restoredata_handler(const CommandContext &ctx)
{
ASSERT(ctx.args.size() == 3, "Invalid number of arguments");
std::string server = ctx.args[0]; std::string server = ctx.args[0];
std::string service = ctx.args[1]; std::string service = ctx.args[1];
std::string backup_file = ctx.args[2]; std::string backup_arg = ctx.args[2];
server_env_manager server_env(server); server_env_manager server_env(server);
if (!server_env.is_valid()) { if (!server_env.is_valid())
{
error << "Server " << server << " is not valid" << std::endl; error << "Server " << server << " is not valid" << std::endl;
return 1; return 1;
} }
LocalServiceInfo service_info = get_service_info(server, service);
shared_commands::cBackupFileName backup_details(backup_file); if (!SIvalid(service_info))
if (!backup_details.is_valid()) { {
error << "Invalid backup file: " << backup_file << std::endl; error << "Service " << service << " is not valid" << std::endl;
return 1; return 1;
} }
std::optional<shared_commands::cBackupFileName> backup_details;
if (backup_arg == "latest")
{ // special case.
std::vector<shared_commands::cBackupFileName> backups = get_backup_files(server, service, service_info.template_name); // this service only (and also match template in case something changed there!).
if (backups.empty())
{
error << "No backups found for " << server << "/" << service << std::endl;
debug << "Template also has to match with the service template: " << service_info.template_name << std::endl;
return 1;
}
backup_details = backups[0];
} else {
backup_details = shared_commands::cBackupFileName(backup_arg);
if (!backup_details->is_valid())
{
error << "Invalid backup file: " << backup_arg << std::endl;
return 1;
}
}
ASSERT(backup_details.has_value() && backup_details->is_valid(), "Invalid backup file.");
std::string local_backups_dir = gConfig().get_local_backup_path();
if (local_backups_dir.empty() || !std::filesystem::exists(local_backups_dir))
{
error << "Error: Local backups directory not found: " << local_backups_dir << std::endl;
return 1;
}
std::string local_backup_file_path = (std::filesystem::path(local_backups_dir) / backup_details->get_filename()).string();
if (!std::filesystem::exists(local_backup_file_path))
{
error << "Error: Backup file not found at " << local_backup_file_path << std::endl;
return 1;
}
if (backup_details->get_template_name() != service_info.template_name)
{
error << "Error: Backup template does not match service template. Can't restore." << std::endl;
debug << "Backup template: " << backup_details->get_template_name() << std::endl;
debug << "Service template: " << service_info.template_name << std::endl;
debug << "Backup file: " << local_backup_file_path << std::endl;
return 1;
}
info << "Restoring " << backup_details->get_datetime() << " backup of " << backup_details->get_service() << " taken from " << backup_details->get_server() << ", onto " << server << "/" << service << std::endl;
info << std::endl;
warning << "*** ALL DATA FOR " << server << "/" << service << " WILL BE OVERWRITTEN! ***" << std::endl;
// run the restore script
info << "OK, here goes..." << std::endl;
{ // backup existing service
info << "1) Backing up old service... " << std::endl;
if (!shared_commands::backupdata_service(server, service))
{
error << "Error: Backup failed, restore aborted." << std::endl;
error << "You can try using dropshell install " << server << " " << service << " to install the service afresh." << std::endl;
error << "Otherwise, stop the service, create and initialise a new one, then restore to that." << std::endl;
return 1;
}
info << "Backup complete." << std::endl;
}
{ // nuke the old service
info << "2) Nuking old service..." << std::endl;
if (!shared_commands::nuke_service(server, service))
return 1;
}
{ // create the new service
info << "3) Creating new service..." << std::endl;
if (!shared_commands::create_service(server, service_info.template_name, service))
return 1;
}
{ // installing fresh service
info << "4) Install of fresh service..." << std::endl;
if (!shared_commands::install_service(server, service))
return 1;
}
{ // restore service from backup
info << "5) Restoring service data from backup..." << std::endl;
std::string remote_backups_dir = remotepath::backups(server);
std::string remote_backup_file_path = remote_backups_dir + "/" + backup_details->get_filename();
// Copy backup file from local to server
if (!shared_commands::scp_file_to_remote(server_env, local_backup_file_path, remote_backup_file_path, false))
{
error << "Failed to copy backup file from local to server" << std::endl;
return 1;
}
shared_commands::cRemoteTempFolder remote_temp_folder(server_env);
server_env.run_remote_template_command(service, "restore", {}, false, {{"BACKUP_FILE", remote_backup_file_path}, {"TEMP_DIR", remote_temp_folder.path()}});
} // dtor of remote_temp_folder will clean up the temp folder on the server
{ // healthcheck the service
info << "5) Healthchecking service..." << std::endl;
std::string green_tick = "\033[32m✓\033[0m";
std::string red_cross = "\033[31m✗\033[0m";
bool healthy = (server_env.run_remote_template_command(service, "status", {}, false, {}));
info << (healthy ? green_tick : red_cross) << " Service is " << (healthy ? "healthy" : "NOT healthy") << std::endl;
}
return 0;
}
void restoredata_autocomplete(const CommandContext &ctx)
return 0; {
}
void restoredata_autocomplete(const CommandContext& ctx)
{
shared_commands::std_autocomplete(ctx); shared_commands::std_autocomplete(ctx);
if (ctx.args.size() == 2) // next arg is the backup file if (ctx.args.size() == 2) // next arg is the backup file
{ {
std::string server = ctx.args[0]; std::string server = ctx.args[0];
std::string service = ctx.args[1]; std::string service = ctx.args[1];
std::vector<shared_commands::cBackupFileName> backups;
LocalServiceInfo service_info = get_service_info(server, service); LocalServiceInfo service_info = get_service_info(server, service);
if (!SIvalid(service_info)) { if (!SIvalid(service_info))
{
error << "Service " << service << " is not valid" << std::endl; error << "Service " << service << " is not valid" << std::endl;
return; return;
} }
std::string template_name = service_info.template_name; std::string template_name = service_info.template_name;
std::string local_backups_dir = gConfig().get_local_backup_path(); std::vector<shared_commands::cBackupFileName> backups = get_backup_files(server, "", template_name); // any service, but must match template.
if (local_backups_dir.empty() || !std::filesystem::exists(local_backups_dir)) {
error << "Error: Local backups directory not found: " << local_backups_dir << std::endl;
return;
}
for (const auto& entry : std::filesystem::directory_iterator(local_backups_dir)) {
if (!entry.is_regular_file()) continue;
std::string filename = entry.path().filename().string();
shared_commands::cBackupFileName backup_details(filename);
if (backup_details.is_valid()) {
if (backup_details.get_template_name() == template_name) {
backups.push_back(backup_details);
}
}
}
// sort backups by datetime
std::sort(backups.begin(), backups.end(), [](const shared_commands::cBackupFileName& a, const shared_commands::cBackupFileName& b) {
return a.get_datetime() > b.get_datetime();
});
// print most recent backup for each {host,service} pair // print most recent backup for each {host,service} pair
std::map<std::string, std::string> unique_backups; std::map<std::string, std::string> unique_backups;
for (const auto& backup : backups) { for (const auto &backup : backups)
{
std::string key = backup.get_server() + "-" + backup.get_service(); std::string key = backup.get_server() + "-" + backup.get_service();
if (unique_backups.find(key) == unique_backups.end()) { if (unique_backups.find(key) == unique_backups.end())
unique_backups[key] = backup.get_filename(); unique_backups[key] = backup.get_filename();
} }
} for (const auto &[key, value] : unique_backups)
for (const auto& [key, value] : unique_backups) {
rawout << value << std::endl; rawout << value << std::endl;
} }
} }
}
} // namespace dropshell } // namespace dropshell

View File

@ -81,6 +81,21 @@ namespace dropshell
bool scp_file_to_remote(const server_env_manager &server_env, const std::string &local_path, const std::string &remote_path, bool silent); bool scp_file_to_remote(const server_env_manager &server_env, const std::string &local_path, const std::string &remote_path, bool silent);
bool scp_file_from_remote(const server_env_manager &server_env, const std::string &remote_path, const std::string &local_path, bool silent); bool scp_file_from_remote(const server_env_manager &server_env, const std::string &remote_path, const std::string &local_path, bool silent);
// defined in backupdata.cpp, used by restoredata.cpp.
bool backupdata_service(const std::string& server, const std::string& service);
// defined in uninstall.cpp
bool uninstall_service(const std::string &server, const std::string &service);
// defined in nuke.cpp
bool nuke_service(const std::string &server, const std::string &service);
// defined in install.cpp
bool install_service(const std::string &server, const std::string &service);
// defined in create-service.cpp
bool create_service(const std::string &server_name, const std::string &template_name, const std::string &service_name);
} // namespace shared_commands } // namespace shared_commands
} // namespace dropshell } // namespace dropshell
#endif #endif

View File

@ -41,9 +41,9 @@ namespace dropshell
} }
} uninstall_command_register; } uninstall_command_register;
bool uninstall_service(const std::string &server, const std::string &service, bool silent = false) namespace shared_commands {
bool uninstall_service(const std::string &server, const std::string &service)
{ {
if (!silent)
maketitle("Uninstalling " + service + " on " + server); maketitle("Uninstalling " + service + " on " + server);
server_env_manager server_env(server); server_env_manager server_env(server);
@ -62,24 +62,22 @@ namespace dropshell
// 3. Run uninstall script if it exists // 3. Run uninstall script if it exists
std::string uninstall_script = remotepath::service_template(server, service) + "/uninstall.sh"; std::string uninstall_script = remotepath::service_template(server, service) + "/uninstall.sh";
if (!server_env.run_remote_template_command(service, "uninstall", {}, silent, {})) if (!server_env.run_remote_template_command(service, "uninstall", {}, false, {}))
if (!silent)
warning << "Uninstall script failed, but continuing with directory removal" << std::endl; warning << "Uninstall script failed, but continuing with directory removal" << std::endl;
// 4. Remove the service directory from the server, running in a docker container as root. // 4. Remove the service directory from the server, running in a docker container as root.
if (server_env.remove_remote_dir(remotepath::service(server, service), silent)) if (server_env.remove_remote_dir(remotepath::service(server, service), false))
{ {
ASSERT(!server_env.check_remote_dir_exists(remotepath::service(server, service)), "Service directory still found on server after uninstall"); ASSERT(!server_env.check_remote_dir_exists(remotepath::service(server, service)), "Service directory still found on server after uninstall");
if (!silent)
info << "Removed remote service directory " << remotepath::service(server, service) << std::endl; info << "Removed remote service directory " << remotepath::service(server, service) << std::endl;
} }
else if (!silent) else
warning << "Failed to remove remote service directory" << std::endl; warning << "Failed to remove remote service directory" << std::endl;
if (!silent)
info << "Completed service " << service << " uninstall on " << server << std::endl; info << "Completed service " << service << " uninstall on " << server << std::endl;
return true; return true;
} }
} // namespace shared_commands
int uninstall_handler(const CommandContext &ctx) int uninstall_handler(const CommandContext &ctx)
{ {
@ -98,14 +96,14 @@ namespace dropshell
std::vector<LocalServiceInfo> services = get_server_services_info(server); std::vector<LocalServiceInfo> services = get_server_services_info(server);
for (const auto &service : services) for (const auto &service : services)
{ {
if (!uninstall_service(server, service.service_name)) if (!shared_commands::uninstall_service(server, service.service_name))
okay = false; okay = false;
} }
return okay ? 0 : 1; return okay ? 0 : 1;
} }
std::string service = safearg(ctx.args, 1); std::string service = safearg(ctx.args, 1);
return uninstall_service(server, service) ? 0 : 1; return shared_commands::uninstall_service(server, service) ? 0 : 1;
} }
} // namespace dropshell } // namespace dropshell

View File

@ -6,6 +6,9 @@
#include "utils/json.hpp" #include "utils/json.hpp"
#include <filesystem> #include <filesystem>
#include "utils/execute.hpp" #include "utils/execute.hpp"
#include "output.hpp"
namespace dropshell { namespace dropshell {
@ -150,7 +153,7 @@ std::vector<std::string> config::get_local_server_definition_paths() {
if (path.is_string() && !path.empty()) if (path.is_string() && !path.empty())
paths.push_back(path); paths.push_back(path);
else else
std::cerr << "Warning: Invalid server definition path: " << path << std::endl; warning << "Invalid server definition path: " << path << std::endl;
} }
return paths; return paths;
} }

View File

@ -121,12 +121,12 @@ bool service_runner::nuke(bool silent)
std::string remote_service_path = remotepath::service(mServer, mService); std::string remote_service_path = remotepath::service(mServer, mService);
std::cout << "Service " << mService << " successfully nuked from " << mServer << std::endl; info << "Service " << mService << " successfully nuked from " << mServer << std::endl;
if (!silent) { if (!silent) {
std::cout << "There's nothing left on the remote server." << std::endl; info << "There's nothing left on the remote server." << std::endl;
std::cout << "You can remove the local files with:" << std::endl; info << "You can remove the local files with:" << std::endl;
std::cout << " rm -rf " << localpath::service(mServer,mService) << std::endl; info << " rm -rf " << localpath::service(mServer,mService) << std::endl;
} }
return true; return true;
} }
@ -135,19 +135,19 @@ bool service_runner::fullnuke()
{ {
if (!nuke(true)) if (!nuke(true))
{ {
std::cerr << "Warning: Nuke script failed, aborting fullnuke!" << std::endl; warning << "Nuke script failed, aborting." << std::endl;
return false; return false;
} }
std::string local_service_path = mServiceInfo.local_service_path; std::string local_service_path = mServiceInfo.local_service_path;
if (local_service_path.empty() || !fs::exists(local_service_path)) { if (local_service_path.empty() || !fs::exists(local_service_path)) {
std::cerr << "Error: Service directory not found: " << local_service_path << std::endl; error << "Service directory not found: " << local_service_path << std::endl;
return false; return false;
} }
std::string rm_cmd = "rm -rf " + quote(local_service_path); std::string rm_cmd = "rm -rf " + quote(local_service_path);
if (!execute_local_command("", rm_cmd, {}, nullptr, cMode::Silent)) { if (!execute_local_command("", rm_cmd, {}, nullptr, cMode::Silent)) {
std::cerr << "Failed to remove service directory" << std::endl; error << "Failed to remove service directory" << std::endl;
return false; return false;
} }

View File

@ -47,7 +47,7 @@ std::vector<LocalServiceInfo> get_server_services_info(const std::string& server
if (!service.local_service_path.empty()) if (!service.local_service_path.empty())
services.push_back(service); services.push_back(service);
else else
std::cerr << "Warning: Failed to get service info for " << dirname << " on server " << server_name << std::endl; warning << "Failed to get service info for " << dirname << " on server " << server_name << std::endl;
} }
} // end of for } // end of for
} }
@ -188,7 +188,7 @@ bool get_all_service_env_vars(const std::string &server_name, const std::string
all_env_vars.merge(env_vars); all_env_vars.merge(env_vars);
} }
else else
std::cout << "Warning: Expected environment file not found: " << file << std::endl; warning << "Expected environment file not found: " << file << std::endl;
}; };
// Load environment files // Load environment files
@ -198,11 +198,10 @@ bool get_all_service_env_vars(const std::string &server_name, const std::string
// determine template name. // determine template name.
auto it = all_env_vars.find("TEMPLATE"); auto it = all_env_vars.find("TEMPLATE");
if (it == all_env_vars.end()) { if (it == all_env_vars.end()) {
std::cerr << std::endl << std::endl; error << "TEMPLATE variable not defined in service " << service_name << " on server " << server_name << std::endl;
std::cerr << "Error: TEMPLATE variable not defined in service " << service_name << " on server " << server_name << std::endl; info << "The TEMPLATE variable is required to determine the template name." << std::endl;
std::cerr << "The TEMPLATE variable is required to determine the template name." << std::endl; info << "Please check the service.env file and the .template_info.env file in:" << std::endl;
std::cerr << "Please check the service.env file and the .template_info.env file in:" << std::endl; info << " " << localpath::service(server_name, service_name) << std::endl << std::endl;
std::cerr << " " << localpath::service(server_name, service_name) << std::endl << std::endl;
return false; return false;
} }
template_info tinfo = gTemplateManager().get_template_info(it->second); template_info tinfo = gTemplateManager().get_template_info(it->second);

View File

@ -1,10 +1,13 @@
#include "directories.hpp" #include "directories.hpp"
#include "config.hpp" #include "config.hpp"
#include "server_env_manager.hpp" #include "server_env_manager.hpp"
#include "output.hpp"
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <filesystem> #include <filesystem>
namespace fs = std::filesystem; namespace fs = std::filesystem;
namespace dropshell { namespace dropshell {
@ -78,7 +81,7 @@ namespace localpath {
std::filesystem::path homedir_path(homedir); std::filesystem::path homedir_path(homedir);
return fs::canonical(homedir_path).string(); return fs::canonical(homedir_path).string();
} }
std::cerr << "Warning: Couldn't determine user directory" << std::endl; warning << "Couldn't determine user directory" << std::endl;
return std::string(); return std::string();
} }
} // namespace localpath } // namespace localpath