From c8493b92a003d42e5f9ada0c1771ceecca2d5f6b Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 20 Sep 2025 10:14:28 +1200 Subject: [PATCH] Fix inline comments in dropshell handling --- TEMPLATES.md | 15 +++++++++++---- source/src/utils/envmanager.cpp | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/TEMPLATES.md b/TEMPLATES.md index 83cb04a..a1c574f 100644 --- a/TEMPLATES.md +++ b/TEMPLATES.md @@ -122,17 +122,21 @@ CONFIG_VOLUME="${CONTAINER_NAME}_config" Default service configuration that **will be modified per installation**. When a user creates a service from this template, they edit this file to customize the deployment: ```bash -# Service-specific settings +# Service identification (REQUIRED) CONTAINER_NAME=service-name -IMAGE_TAG="latest" -# Server settings -SSH_USER="root" +# Server settings (REQUIRED by dropshell) +SSH_USER="root" # CRITICAL: This must always be defined! + +# Docker settings (optional) +IMAGE_TAG="latest" # Service-specific variables # (Add any configuration specific to your service) ``` +**CRITICAL REQUIREMENT**: The `SSH_USER` variable MUST be defined in every service.env file. Dropshell uses this internally for server management. Without it, the template will fail with "SSH_USER variable not defined" error. + **Important**: This is the file users edit to customize each service instance. Different deployments of the same template will have different `service.env` files. ### How Environment Variables Work @@ -332,6 +336,7 @@ Templates must pass these validation checks: 2. **Scripts are executable**: All `.sh` files must have execute permissions 3. **TEMPLATE variable matches**: The `TEMPLATE` variable in `.template_info.env` must match the directory name 4. **Valid environment files**: Both `.env` files must be parseable +5. **SSH_USER defined**: The `SSH_USER` variable MUST be present in `service.env` ## Best Practices @@ -377,6 +382,7 @@ CONTENT_VOLUME="${CONTAINER_NAME}_content" `service.env`: ```bash CONTAINER_NAME=nginx-server +SSH_USER="root" IMAGE_TAG="alpine" HTTP_PORT=8080 ``` @@ -434,6 +440,7 @@ CONFIG_VOLUME="${CONTAINER_NAME}_config" `service.env`: ```bash CONTAINER_NAME=postgres-db +SSH_USER="root" IMAGE_TAG="15-alpine" DB_PORT=5432 POSTGRES_PASSWORD="changeme" diff --git a/source/src/utils/envmanager.cpp b/source/src/utils/envmanager.cpp index 31bbee8..13ea373 100644 --- a/source/src/utils/envmanager.cpp +++ b/source/src/utils/envmanager.cpp @@ -35,6 +35,26 @@ bool envmanager::load() { std::string key = line.substr(0, pos); std::string value = line.substr(pos + 1); + // Remove inline comments (everything after unquoted #) + bool in_quotes = false; + char quote_char = '\0'; + for (size_t i = 0; i < value.length(); ++i) { + char c = value[i]; + + // Handle quote state changes + if (!in_quotes && (c == '\'' || c == '"')) { + in_quotes = true; + quote_char = c; + } else if (in_quotes && c == quote_char && (i == 0 || value[i-1] != '\\')) { + in_quotes = false; + quote_char = '\0'; + } else if (!in_quotes && c == '#') { + // Found unquoted # - truncate value here + value = value.substr(0, i); + break; + } + } + // trim whitespace from the key and value m_variables[dequote(trim(key))] = dequote(trim(value)); }