feat: manage.sh reads .env for data paths — consistent with docker compose

- 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>
This commit is contained in:
Kpa-clawbot
2026-03-28 16:06:13 -07:00
parent 91fcbc5adc
commit a1a67e89fb
2 changed files with 48 additions and 21 deletions

View File

@@ -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

View File

@@ -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 ─────────────────────────────────────────────────────────────────