change 'example' to 'config'.

This commit is contained in:
Your Name 2025-05-04 14:05:14 +12:00
parent 5286ec542a
commit 0bc78f353f
9 changed files with 23 additions and 73 deletions

View File

@ -52,10 +52,9 @@ void dropshell::autocomplete(const std::vector<std::string> &args)
if (cmd=="create-service") if (cmd=="create-service")
{ // create-service <server> <template> <service> { // create-service <server> <template> <service>
std::vector<template_info> templates; auto templates = dropshell::gTemplateManager().get_template_list();
get_templates(templates);
for (const auto& t : templates) for (const auto& t : templates)
std::cout << t.template_name << std::endl; std::cout << t << std::endl;
return; return;
} }

View File

@ -77,14 +77,14 @@ LocalServiceInfo get_service_info(const std::string &server_name, const std::str
} }
service.template_name = it->second; service.template_name = it->second;
template_info tinfo; template_info tinfo = gTemplateManager().get_template_info(service.template_name);
if (!get_template_info(service.template_name, tinfo)) { if (!tinfo.is_set()) {
std::cerr << "Error: Template '" << service.template_name << "' not found" << std::endl; std::cerr << "Error: Template '" << service.template_name << "' not found" << std::endl;
return LocalServiceInfo(); return LocalServiceInfo();
} }
// find the template path // find the template path
service.local_template_path = tinfo.local_template_path; service.local_template_path = tinfo.local_template_path();
return service; return service;
} }
@ -170,8 +170,8 @@ bool create_service(const std::string &server_name, const std::string &template_
return false; return false;
} }
template_info tinfo; template_info tinfo = gTemplateManager().get_template_info(template_name);
if (!get_template_info(template_name, tinfo)) if (!tinfo.is_set())
{ {
if (!silent) if (!silent)
{ {
@ -186,8 +186,8 @@ bool create_service(const std::string &server_name, const std::string &template_
// create the service directory // create the service directory
fs::create_directory(service_dir); fs::create_directory(service_dir);
// copy the template example files to the service directory // copy the template config files to the service directory
recursive_copy(tinfo.local_template_path+"/example", service_dir); recursive_copy(tinfo.local_template_path()/"config", service_dir);
if (!silent) if (!silent)
{ {
@ -244,9 +244,9 @@ void get_all_service_env_vars(const std::string &server_name, const std::string
std::cerr << " " << localpath::service(server_name, service_name) << std::endl << std::endl; std::cerr << " " << localpath::service(server_name, service_name) << std::endl << std::endl;
return; return;
} }
template_info tinfo; template_info tinfo = gTemplateManager().get_template_info(it->second);
if (get_template_info(it->second, tinfo)) if (tinfo.is_set())
load_env_file(tinfo.local_template_path + "/_default.env"); load_env_file(tinfo.local_template_path()/"_default.env");
else else
std::cerr << "Error: Template '" << it->second << "' not found" << std::endl; std::cerr << "Error: Template '" << it->second << "' not found" << std::endl;
} }

View File

@ -137,7 +137,7 @@
// modify the TEMPLATE=example line in the .template_info.env file to TEMPLATE=<template_name> // modify the TEMPLATE=example line in the .template_info.env file to TEMPLATE=<template_name>
std::string search_string = "TEMPLATE="; std::string search_string = "TEMPLATE=";
std::string replacement_line = "TEMPLATE=" + template_name; std::string replacement_line = "TEMPLATE=" + template_name;
std::string service_env_path = new_template_path + "/example/.template_info.env"; std::string service_env_path = new_template_path + "/config/.template_info.env";
if (!replace_line_in_file(service_env_path, search_string, replacement_line)) { if (!replace_line_in_file(service_env_path, search_string, replacement_line)) {
std::cerr << "Error: Failed to replace TEMPLATE= line in the .template_info.env file" << std::endl; std::cerr << "Error: Failed to replace TEMPLATE= line in the .template_info.env file" << std::endl;
return; return;
@ -181,11 +181,12 @@
std::string template_name = std::filesystem::path(template_path).filename().string(); std::string template_name = std::filesystem::path(template_path).filename().string();
std::vector<std::string> required_files = { std::vector<std::string> required_files = {
"example/service.env", "config/service.env",
"example/.template_info.env", "config/.template_info.env",
"_default.env", "_default.env",
"install.sh", "install.sh",
"uninstall.sh" "uninstall.sh",
"nuke.sh"
}; };
for (const auto& file : required_files) { for (const auto& file : required_files) {
@ -197,8 +198,8 @@
// check TEMPLATE= line. // check TEMPLATE= line.
std::map<std::string, std::string> all_env_vars; std::map<std::string, std::string> all_env_vars;
std::vector<std::string> env_files = { std::vector<std::string> env_files = {
"example/service.env", "config/service.env",
"example/.template_info.env" "config/.template_info.env"
}; };
for (const auto& file : env_files) { for (const auto& file : env_files) {
{ // load service.env from the service on this machine. { // load service.env from the service on this machine.

View File

@ -32,7 +32,7 @@ namespace dropshell {
// | |-- <template_name> // | |-- <template_name>
// | |-- (...script files...) // | |-- (...script files...)
// | |-- _default.env // | |-- _default.env
// | |-- example // | |-- config
// | |-- service.env // | |-- service.env
// | |-- .template_info.env // | |-- .template_info.env
// | |-- (...other service config files...) // | |-- (...other service config files...)
@ -68,7 +68,7 @@ namespace dropshell {
// |-- service.env // |-- service.env
// |-- template // |-- template
// |-- (script files) // |-- (script files)
// |-- example // |-- config
// |-- service.env // |-- service.env
// |-- (other config files for specific server&service) // |-- (other config files for specific server&service)

View File

@ -1,36 +0,0 @@
#include "readmes.hpp"
#include <fstream>
#include <filesystem>
void dropshell::create_readme_local_config_dir(const std::string &readme_path)
{
if (std::filesystem::exists(readme_path))
return; // already exists
std::ofstream readme_file(readme_path);
// use heredoc to write the readme
readme_file << R"(
use this directory to store your local config files for your servers and services.
dropshell create-server <server_name>
dropshell create-template <template_name>
dropshell create-service <server_name> <template_name> <service_name>
config_path
|-- servers
| |-- server_name
| |-- server.env
| |-- services
| |-- service_name
| |-- service.env
| |-- (other config files for specific server&service)
|-- templates
| |-- template_name
| |-- (script files)
| |-- example
| |-- service.env
| |-- (other service config files)
)" << std::endl;
readme_file.close();
}

View File

@ -1,12 +0,0 @@
#ifndef READMES_HPP
#define READMES_HPP
#include <string>
namespace dropshell {
void create_readme_local_config_dir(const std::string &readme_path);
} // namespace dropshell
#endif

View File

@ -17,7 +17,7 @@ SCRIPT_DIR="$(dirname "$0")"
# // |-- service.env # // |-- service.env
# // |-- template # // |-- template
# // |-- (script files) # // |-- (script files)
# // |-- example # // |-- config
# // |-- service.env # // |-- service.env
# // |-- (other config files for specific server&service) # // |-- (other config files for specific server&service)

View File

@ -1,7 +1,7 @@
# Service settings specific to this server # Service settings specific to this server
# (can also override anything in the _default.env file in the template to make it specific to this server) # (can also override anything in the _default.env file in the template to make it specific to this server)
HOST_PORT=60123 HOST_PORT=60123
LOCAL_DATA_FOLDER="${HOME}/.example" LOCAL_DATA_FOLDER="${HOME}/.example-nginx"
CONTAINER_NAME=example-nginx CONTAINER_NAME=example-nginx
IMAGE_TAG="latest" IMAGE_TAG="latest"

View File

@ -13,8 +13,6 @@ if [ ! -d "${LOCAL_DATA_FOLDER}" ]; then
echo "Creating local data folder ${LOCAL_DATA_FOLDER}..." echo "Creating local data folder ${LOCAL_DATA_FOLDER}..."
mkdir -p "${LOCAL_DATA_FOLDER}" mkdir -p "${LOCAL_DATA_FOLDER}"
chmod 777 "${LOCAL_DATA_FOLDER}" chmod 777 "${LOCAL_DATA_FOLDER}"
# Optionally, copy default content if needed
# cp -r ./example/* "${LOCAL_DATA_FOLDER}/"
fi fi
echo "Checking Docker installation..." echo "Checking Docker installation..."