Refaaaacttt00000rr
This commit is contained in:
@ -12,14 +12,13 @@ namespace dropshell {
|
||||
|
||||
namespace localfile {
|
||||
|
||||
std::string dropshell_env() {
|
||||
// Try ~/.config/dropshell/dropshell.env
|
||||
const char* home = std::getenv("HOME");
|
||||
if (home) {
|
||||
fs::path user_path = fs::path(home) / ".config" / "dropshell" / "dropshell.env";
|
||||
std::string dropshell_json() {
|
||||
// Try ~/.config/dropshell/dropshell.json
|
||||
std::string homedir = localpath::current_user_home();
|
||||
if (!homedir.empty()) {
|
||||
fs::path user_path = fs::path(homedir) / ".config" / "dropshell" / "dropshell.json";
|
||||
return user_path.string();
|
||||
}
|
||||
std::cerr << "Warning: Couldn't determine user directory" << std::endl;
|
||||
return std::string();
|
||||
}
|
||||
|
||||
@ -39,60 +38,46 @@ namespace localfile {
|
||||
return (servicepath.empty() ? "" : (fs::path(servicepath) / ".template_info.env").string());
|
||||
}
|
||||
|
||||
std::string service_hash(const std::string &server_name, const std::string &service_name) {
|
||||
std::string config_path = localpath::config();
|
||||
if (server_name.empty() || service_name.empty() || config_path.empty())
|
||||
return std::string();
|
||||
return (fs::path(config_path) / ".remote_versions" / server_name / (service_name + ".hash.env")).string();
|
||||
}
|
||||
|
||||
} // namespace localfile
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
|
||||
namespace localpath {
|
||||
// /opt/dropshell/templates
|
||||
std::string system_templates() {
|
||||
return "/opt/dropshell/templates";
|
||||
}
|
||||
|
||||
// configured by user - defaults to first config_path/backups.
|
||||
std::string backups_path() {
|
||||
return gConfig().get_local_backup_path();
|
||||
}
|
||||
|
||||
int num_config_directories() {
|
||||
return gConfig().get_local_config_directories().size();
|
||||
}
|
||||
|
||||
std::string config(int index) {
|
||||
return (num_config_directories()>index) ? gConfig().get_local_config_directories()[index] : "";
|
||||
}
|
||||
|
||||
std::string config_templates(int index) {
|
||||
return (num_config_directories()>index) ? (gConfig().get_local_config_directories()[index]+"/templates") : "";
|
||||
}
|
||||
|
||||
std::string config_servers(int index) {
|
||||
return (num_config_directories()>index) ? (gConfig().get_local_config_directories()[index]+"/servers") : "";
|
||||
}
|
||||
|
||||
std::string server(const std::string &server_name) {
|
||||
if (server_name.empty()) return "";
|
||||
for (auto &dir : gConfig().get_local_config_directories())
|
||||
if (fs::exists(dir + "/servers/" + server_name))
|
||||
return dir + "/servers/" + server_name;
|
||||
for (auto &dir : gConfig().get_local_server_definition_paths())
|
||||
if (fs::exists(dir + server_name))
|
||||
return dir + server_name;
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string service(const std::string &server_name, const std::string &service_name) {
|
||||
std::string serverpath = localpath::server(server_name);
|
||||
return (serverpath.empty() || service_name.empty() ? "" : (serverpath+"/"+service_name));
|
||||
return ((serverpath.empty() || service_name.empty()) ? "" : (serverpath+"/"+service_name));
|
||||
}
|
||||
|
||||
std::string remote_versions(const std::string &server_name, const std::string &service_name)
|
||||
{
|
||||
std::string template_cache_path = gConfig().get_local_template_cache_path();
|
||||
return ((template_cache_path.empty() || service_name.empty()) ? "" :
|
||||
(template_cache_path+"/remote_versions/"+service_name+".json"));
|
||||
}
|
||||
std::string local_bin(){
|
||||
return current_user_home() + "/.local/bin";
|
||||
}
|
||||
std::string current_user_home(){
|
||||
char * homedir = std::getenv("HOME");
|
||||
if (homedir)
|
||||
{
|
||||
std::filesystem::path homedir_path(homedir);
|
||||
return fs::canonical(homedir_path).string();
|
||||
}
|
||||
std::cerr << "Warning: Couldn't determine user directory" << std::endl;
|
||||
return std::string();
|
||||
}
|
||||
} // namespace localpath
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
|
||||
// remote paths
|
||||
|
Reference in New Issue
Block a user