From a1a67e89fbe5f822f0016944fd5d5ff2bc33c780 Mon Sep 17 00:00:00 2001 From: Kpa-clawbot <259247574+Kpa-clawbot@users.noreply.github.com> Date: Sat, 28 Mar 2026 16:06:13 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20manage.sh=20reads=20.env=20for=20data?= =?UTF-8?q?=20paths=20=E2=80=94=20consistent=20with=20docker=20compose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace all hardcoded \C:\Users\KpaBap/meshcore-data with \ variable - \ resolves from \ in .env or defaults to ~/meshcore-data - Updated get_data_mount_args(), cmd_backup(), cmd_restore(), cmd_reset() - Enhanced .env.example with detailed comments for each variable - Both docker compose and manage.sh now read same .env file Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .env.example | 39 +++++++++++++++++++++++++++++++++------ manage.sh | 30 +++++++++++++++--------------- 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/.env.example b/.env.example index f530e57..e6372f4 100644 --- a/.env.example +++ b/.env.example @@ -1,17 +1,44 @@ # MeshCore Analyzer — Environment Configuration -# Copy to .env and customize. All values have sensible defaults in docker-compose.yml. +# Copy to .env and customize. All values have sensible defaults. # +# This file is read by BOTH docker compose AND manage.sh — one source of truth. # Each environment keeps config + data together in one directory: # ~/meshcore-data/config.json, meshcore.db, Caddyfile, theme.json # ~/meshcore-staging-data/config.json, meshcore.db, Caddyfile # --- Production --- -PROD_HTTP_PORT=80 -PROD_HTTPS_PORT=443 -PROD_MQTT_PORT=1883 +# Data directory (database, theme, etc.) +# Default: ~/meshcore-data +# Used by: docker compose, manage.sh PROD_DATA_DIR=~/meshcore-data +# HTTP port for web UI +# Default: 80 +# Used by: docker compose +PROD_HTTP_PORT=80 + +# HTTPS port for web UI (TLS via Caddy) +# Default: 443 +# Used by: docker compose +PROD_HTTPS_PORT=443 + +# MQTT port for observer connections +# Default: 1883 +# Used by: docker compose +PROD_MQTT_PORT=1883 + # --- Staging (HTTP only, no HTTPS) --- -STAGING_HTTP_PORT=81 -STAGING_MQTT_PORT=1884 +# Data directory +# Default: ~/meshcore-staging-data +# Used by: docker compose STAGING_DATA_DIR=~/meshcore-staging-data + +# HTTP port +# Default: 81 +# Used by: docker compose +STAGING_HTTP_PORT=81 + +# MQTT port +# Default: 1884 +# Used by: docker compose +STAGING_MQTT_PORT=1884 diff --git a/manage.sh b/manage.sh index 1a30bad..1432a8b 100755 --- a/manage.sh +++ b/manage.sh @@ -52,12 +52,12 @@ is_done() { [ -f "$STATE_FILE" ] && grep -qx "$1" "$STATE_FILE" 2>/dev/null; # ─── Helpers ────────────────────────────────────────────────────────────── # Determine the correct data volume/mount args for docker run. -# Always uses bind mounts to ~/meshcore-data so the DB is visible on the filesystem. +# Always uses bind mounts so the DB is visible on the filesystem. get_data_mount_args() { - # Always use bind mount to $HOME/meshcore-data + # Always use bind mount (from .env or default) # Create the directory if it doesn't exist - mkdir -p "$HOME/meshcore-data" - echo "-v $HOME/meshcore-data:/app/data" + mkdir -p "$PROD_DATA" + echo "-v $PROD_DATA:/app/data" } # Determine the required port mappings from Caddyfile @@ -378,8 +378,8 @@ cmd_setup() { step 5 "Starting container" # Detect existing data directories - if [ -d "$HOME/meshcore-data" ] && [ -f "$HOME/meshcore-data/meshcore.db" ]; then - info "Found existing data at \$HOME/meshcore-data/ — will use bind mount." + if [ -d "$PROD_DATA" ] && [ -f "$PROD_DATA/meshcore.db" ]; then + info "Found existing data at $PROD_DATA/ — will use bind mount." elif [ -d "$(pwd)/data" ] && [ -f "$(pwd)/data/meshcore.db" ]; then info "Found existing data at ./data/ — will use bind mount." fi @@ -917,8 +917,8 @@ cmd_backup() { info "Backing up to ${BACKUP_DIR}/" # Database - # Always use bind mount path - DB_PATH="$HOME/meshcore-data/meshcore.db" + # Always use bind mount path (from .env or default) + DB_PATH="$PROD_DATA/meshcore.db" if [ -f "$DB_PATH" ]; then cp "$DB_PATH" "$BACKUP_DIR/meshcore.db" log "Database ($(du -h "$BACKUP_DIR/meshcore.db" | cut -f1))" @@ -942,8 +942,8 @@ cmd_backup() { fi # Theme - # Always use bind mount path - THEME_PATH="$HOME/meshcore-data/theme.json" + # Always use bind mount path (from .env or default) + THEME_PATH="$PROD_DATA/theme.json" if [ -f "$THEME_PATH" ]; then cp "$THEME_PATH" "$BACKUP_DIR/theme.json" log "theme.json" @@ -1019,9 +1019,9 @@ cmd_restore() { docker stop "$CONTAINER_NAME" 2>/dev/null || true # Restore database - # Always use bind mount path - mkdir -p "$HOME/meshcore-data" - DEST_DB="$HOME/meshcore-data/meshcore.db" + # Always use bind mount path (from .env or default) + mkdir -p "$PROD_DATA" + DEST_DB="$PROD_DATA/meshcore.db" cp "$DB_FILE" "$DEST_DB" log "Database restored" @@ -1040,7 +1040,7 @@ cmd_restore() { # Restore theme if present if [ -n "$THEME_FILE" ] && [ -f "$THEME_FILE" ]; then - DEST_THEME="$HOME/meshcore-data/theme.json" + DEST_THEME="$PROD_DATA/theme.json" cp "$THEME_FILE" "$DEST_THEME" log "theme.json restored" fi @@ -1089,7 +1089,7 @@ cmd_reset() { rm -f "$STATE_FILE" log "Reset complete. Run './manage.sh setup' to start over." - echo " Data directory: ~/meshcore-data (not removed)" + echo " Data directory: $PROD_DATA (not removed)" } # ─── Help ─────────────────────────────────────────────────────────────────