From 1bdc2b9ae0780f63cade83c610832c9bd31e1a64 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 6 Nov 2025 23:26:42 -0700 Subject: [PATCH] some updates --- config.sh | 228 ++++++++++++++++++++++++--------------------- docker-compose.yml | 92 +++++++++--------- reset-site.sh | 0 3 files changed, 168 insertions(+), 152 deletions(-) mode change 100644 => 100755 reset-site.sh diff --git a/config.sh b/config.sh index 2b88c1a..47dc42b 100755 --- a/config.sh +++ b/config.sh @@ -593,99 +593,6 @@ load_env_vars() { fi } -# Function to update or create the map's .env file with domain settings -update_map_env() { - local new_domain=$1 - - # Check if the map directory exists - if [ ! -d "$SCRIPT_DIR/map" ]; then - echo "Map directory not found at $SCRIPT_DIR/map" - return - fi - - echo "Creating/updating map .env file at: $MAP_ENV_FILE" - - cat > "$MAP_ENV_FILE" << EOL -NOCODB_API_URL=https://db.$new_domain/api/v1 -NOCODB_API_TOKEN=changeme - -# NocoDB View URL is the URL to your NocoDB view where the map data is stored. -NOCODB_VIEW_URL= - -# NOCODB_LOGIN_SHEET is the URL to your NocoDB login sheet. -NOCODB_LOGIN_SHEET= - -# NOCODB_SETTINGS_SHEET is the URL to your NocoDB settings sheet. -NOCODB_SETTINGS_SHEET= - -# NOCODB_SHIFTS_SHEET is the urls to your shifts sheets. -NOCODB_SHIFTS_SHEET= - -# NOCODB_SHIFT_SIGNUPS_SHEET is the URL to your NocoDB shift signups sheet where users can add their own shifts. -NOCODB_SHIFT_SIGNUPS_SHEET= - -# NOCODB_CUTS_SHEET is the URL to your Nocodb Cuts sheet. -NOCODB_CUTS_SHEET= - -DOMAIN=$new_domain - -# MkDocs Integration -MKDOCS_URL=https://$new_domain -MKDOCS_SEARCH_URL=https://$new_domain -MKDOCS_SITE_SERVER_PORT=4002 - -# Server Configuration -PORT=3000 -NODE_ENV=production - -# Session Secret (IMPORTANT: Generate a secure random string for production) -# You can generate one with: openssl rand -hex 32 -SESSION_SECRET=$(openssl rand -hex 32 2>/dev/null || echo "changeme") - -# Map Defaults (Edmonton, Alberta, Canada) -DEFAULT_LAT=53.5461 -DEFAULT_LNG=-113.4938 -DEFAULT_ZOOM=11 - -# Optional: Map Boundaries (prevents users from adding points outside area) -# BOUND_NORTH=53.7 -# BOUND_SOUTH=53.4 -# BOUND_EAST=-113.3 -# BOUND_WEST=-113.7 - -# Cloudflare Settings -TRUST_PROXY=true -COOKIE_DOMAIN=.$new_domain - -# Update NODE_ENV to production for HTTPS -NODE_ENV=production - -# Add allowed origin -ALLOWED_ORIGINS=https://map.$new_domain,http://localhost:3000 - -# SMTP Configuration -SMTP_HOST=smtp.protonmail.ch -SMTP_PORT=587 -SMTP_SECURE=false -SMTP_USER=changeme@$new_domain -SMTP_PASS=changeme -EMAIL_FROM_NAME="$new_domain Map" -EMAIL_FROM_ADDRESS=changeme@$new_domain - -# App Configuration -APP_NAME="$new_domain Map" - -# Listmonk Configuration -LISTMONK_API_URL=http://listmonk_app:9000/api -LISTMONK_USERNAME=changeme -LISTMONK_PASSWORD=changeme -LISTMONK_SYNC_ENABLED=true -LISTMONK_INITIAL_SYNC=true # Set to true only for first run to sync existing data -EOL - - echo "Map .env file updated with domain: $new_domain" -} - # Function to sync ports from root .env to map .env sync_map_ports() { echo "Syncing ports from root .env to map configuration..." @@ -923,6 +830,66 @@ EOL return 0 } +# Function to check for port conflicts in existing .env file +check_port_conflicts() { + echo "Checking for port conflicts in existing configuration..." + + # Get list of all used ports on system + local used_ports_list + used_ports_list=$(get_used_ports) + + if [ $? -ne 0 ] || [ -z "$used_ports_list" ]; then + echo "Warning: Could not scan system ports. Skipping conflict check." + return 1 + fi + + # Check each configured port + local -a conflicts=() + local -a port_vars=( + "CODE_SERVER_PORT" + "LISTMONK_PORT" + "LISTMONK_DB_PORT" + "MKDOCS_PORT" + "MKDOCS_SITE_SERVER_PORT" + "N8N_PORT" + "NOCODB_PORT" + "HOMEPAGE_PORT" + "GITEA_WEB_PORT" + "GITEA_SSH_PORT" + "MAP_PORT" + "INFLUENCE_PORT" + "MINI_QR_PORT" + "REDIS_PORT" + "PROMETHEUS_PORT" + "GRAFANA_PORT" + ) + + for var in "${port_vars[@]}"; do + local port_value="${!var}" + if [ -n "$port_value" ] && ! is_port_available "$port_value" "$used_ports_list"; then + conflicts+=("$var=$port_value") + fi + done + + if [ ${#conflicts[@]} -gt 0 ]; then + echo "" + echo "⚠️ WARNING: Port conflicts detected!" + echo "The following ports are already in use on your system:" + for conflict in "${conflicts[@]}"; do + echo " - $conflict" + done + echo "" + echo "You may need to:" + echo "1. Stop services using these ports, or" + echo "2. Edit .env file to use different ports" + echo "" + else + echo "✅ No port conflicts detected!" + fi + + return 0 +} + # Function to get instance identifier get_instance_identifier() { # Try to get from directory name first @@ -936,14 +903,15 @@ get_instance_identifier() { default_instance="$dir_name" fi - echo "" - echo "=== Instance Configuration ===" - echo "To run multiple Changemaker instances on the same machine," - echo "each instance needs a unique identifier for containers and networks." - echo "" + # Send informational messages to stderr so they don't get captured + echo "" >&2 + echo "=== Instance Configuration ===" >&2 + echo "To run multiple Changemaker instances on the same machine," >&2 + echo "each instance needs a unique identifier for containers and networks." >&2 + echo "" >&2 if [ -n "$default_instance" ]; then - echo "Detected potential instance name from directory: $default_instance" + echo "Detected potential instance name from directory: $default_instance" >&2 read -p "Use this instance identifier? [Y/n]: " use_detected if [[ ! "$use_detected" =~ ^[Nn]$ ]]; then echo "$default_instance" @@ -965,6 +933,7 @@ get_instance_identifier() { instance_id="main" fi + # Only output the final instance_id to stdout (this gets captured) echo "$instance_id" } @@ -977,6 +946,13 @@ update_docker_compose_names() { return 0 fi + # Check if docker-compose.yml exists and is not empty + if [ ! -f "$DOCKER_COMPOSE_FILE" ] || [ ! -s "$DOCKER_COMPOSE_FILE" ]; then + echo "Error: docker-compose.yml does not exist or is empty at: $DOCKER_COMPOSE_FILE" + echo "Please ensure docker-compose.yml exists before running this script." + return 1 + fi + echo "Updating docker-compose.yml with instance identifier: $instance_id" # Create a backup of the docker-compose.yml file @@ -988,25 +964,51 @@ update_docker_compose_names() { # Create temporary file for modifications local temp_file=$(mktemp) + # Verify temp file was created + if [ ! -f "$temp_file" ]; then + echo "Error: Could not create temporary file" + return 1 + fi + # Update container names, network names, and volume names - sed -e "s/container_name: \([^-]*\)$/container_name: \1-${instance_id}/g" \ + # Process the file and save to temp file + sed \ -e "s/container_name: \([^-]*\)-changemaker$/container_name: \1-changemaker-${instance_id}/g" \ - -e "s/container_name: \([^-]*\)_\([^-]*\)$/container_name: \1_\2_${instance_id}/g" \ -e "s/container_name: \([^-]*\)_\([^-]*\)_changemaker$/container_name: \1_\2_changemaker_${instance_id}/g" \ - -e "s/networks:/networks:/g" \ + -e "s/container_name: \([^-]*\)_\([^-]*\)$/container_name: \1_\2_${instance_id}/g" \ + -e "s/container_name: \([^-]*\)$/container_name: \1-${instance_id}/g" \ -e "s/changemaker-lite:/changemaker-lite-${instance_id}:/g" \ -e "s/- changemaker-lite$/- changemaker-lite-${instance_id}/g" \ - -e "s/driver: bridge$/driver: bridge/g" \ - -e "s/volumes:/volumes:/g" \ -e "s/listmonk-data:/listmonk-data-${instance_id}:/g" \ + -e "s/source: listmonk-data$/source: listmonk-data-${instance_id}/g" \ -e "s/n8n_data:/n8n_data_${instance_id}:/g" \ + -e "s/source: n8n_data$/source: n8n_data_${instance_id}/g" \ -e "s/nc_data:/nc_data_${instance_id}:/g" \ + -e "s/source: nc_data$/source: nc_data_${instance_id}/g" \ -e "s/db_data:/db_data_${instance_id}:/g" \ + -e "s/source: db_data$/source: db_data_${instance_id}/g" \ -e "s/gitea_data:/gitea_data_${instance_id}:/g" \ + -e "s/source: gitea_data$/source: gitea_data_${instance_id}/g" \ -e "s/mysql_data:/mysql_data_${instance_id}:/g" \ + -e "s/source: mysql_data$/source: mysql_data_${instance_id}/g" \ + -e "s/redis-data:/redis-data-${instance_id}:/g" \ + -e "s/source: redis-data$/source: redis-data-${instance_id}/g" \ + -e "s/prometheus-data:/prometheus-data-${instance_id}:/g" \ + -e "s/source: prometheus-data$/source: prometheus-data-${instance_id}/g" \ + -e "s/grafana-data:/grafana-data-${instance_id}:/g" \ + -e "s/source: grafana-data$/source: grafana-data-${instance_id}/g" \ "$DOCKER_COMPOSE_FILE" > "$temp_file" - # Replace the original file + # Check if temp file has content + if [ ! -s "$temp_file" ]; then + echo "Error: sed operation produced empty file" + echo "Restoring from backup..." + cp "$backup_file" "$DOCKER_COMPOSE_FILE" + rm -f "$temp_file" + return 1 + fi + + # Replace the original file only if temp file has content mv "$temp_file" "$DOCKER_COMPOSE_FILE" echo "✅ Updated docker-compose.yml with instance-specific names:" @@ -1054,7 +1056,21 @@ echo "Please provide the following information:" # Get instance identifier and update docker-compose.yml echo -e "\n---- Instance Configuration ----" instance_identifier=$(get_instance_identifier) -update_docker_compose_names "$instance_identifier" +# Strip any whitespace/newlines from the captured value +instance_identifier=$(echo "$instance_identifier" | tr -d '\n\r' | xargs) + +# Only update docker-compose.yml if we have a non-default instance ID +if [ -n "$instance_identifier" ] && [ "$instance_identifier" != "main" ]; then + if update_docker_compose_names "$instance_identifier"; then + echo "✅ Docker Compose configuration updated successfully" + else + echo "⚠️ Warning: Failed to update docker-compose.yml" + echo " Continuing with default configuration..." + fi +else + echo "Using default instance configuration (no modifications to docker-compose.yml)" +fi + update_env_instance_config "$instance_identifier" # Domain configuration diff --git a/docker-compose.yml b/docker-compose.yml index e8ae12b..835fdc5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,16 +21,16 @@ services: - "${CODE_SERVER_PORT:-8888}:8080" restart: unless-stopped networks: - - changemaker-lite + - changemaker-lite-test4 listmonk-app: image: listmonk/listmonk:latest - container_name: listmonk_app + container_name: listmonk_app_test4-test4 restart: unless-stopped ports: - "${LISTMONK_PORT:-9001}:9000" networks: - - changemaker-lite + - changemaker-lite-test4 hostname: ${LISTMONK_HOSTNAME} depends_on: - listmonk-db @@ -54,12 +54,12 @@ services: listmonk-db: image: postgres:17-alpine - container_name: listmonk_db + container_name: listmonk_db_test4-test4 restart: unless-stopped ports: - "127.0.0.1:${LISTMONK_DB_PORT:-5432}:5432" networks: - - changemaker-lite + - changemaker-lite-test4 environment: <<: *db-credentials healthcheck: @@ -69,12 +69,12 @@ services: retries: 6 volumes: - type: volume - source: listmonk-data + source: listmonk-data-test4 target: /var/lib/postgresql/data mkdocs: image: squidfunk/mkdocs-material - container_name: mkdocs-changemaker + container_name: mkdocs-changemaker-test4 volumes: - ./mkdocs:/docs:rw - ./assets/images:/docs/assets/images:rw @@ -85,7 +85,7 @@ services: - SITE_URL=${BASE_DOMAIN:-https://changeme.org} command: serve --dev-addr=0.0.0.0:8000 --watch-theme --livereload networks: - - changemaker-lite + - changemaker-lite-test4 restart: unless-stopped mkdocs-site-server: @@ -102,11 +102,11 @@ services: - "${MKDOCS_SITE_SERVER_PORT:-4001}:80" restart: unless-stopped networks: - - changemaker-lite + - changemaker-lite-test4 n8n: image: docker.n8n.io/n8nio/n8n - container_name: n8n-changemaker + container_name: n8n-changemaker-test4 restart: unless-stopped ports: - "${N8N_PORT:-5678}:5678" @@ -122,10 +122,10 @@ services: - N8N_DEFAULT_USER_EMAIL=${N8N_USER_EMAIL:-admin@example.com} - N8N_DEFAULT_USER_PASSWORD=${N8N_USER_PASSWORD:-changeMe} volumes: - - n8n_data:/home/node/.n8n + - n8n_data_test4:/home/node/.n8n - ./local-files:/files networks: - - changemaker-lite + - changemaker-lite-test4 nocodb: depends_on: @@ -138,9 +138,9 @@ services: - "${NOCODB_PORT:-8090}:8080" restart: always volumes: - - "nc_data:/usr/app/data" + - "nc_data_test4:/usr/app/data" networks: - - changemaker-lite + - changemaker-lite-test4 root_db: environment: POSTGRES_DB: root_db @@ -154,14 +154,14 @@ services: image: postgres:16.6 restart: always volumes: - - "db_data:/var/lib/postgresql/data" + - "db_data_test4:/var/lib/postgresql/data" networks: - - changemaker-lite + - changemaker-lite-test4 # Homepage App homepage-changemaker: image: ghcr.io/gethomepage/homepage:latest - container_name: homepage-changemaker + container_name: homepage-changemaker-test4 ports: - "${HOMEPAGE_PORT:-3010}:3000" volumes: @@ -177,12 +177,12 @@ services: - HOMEPAGE_VAR_BASE_URL=${HOMEPAGE_VAR_BASE_URL:-http://localhost} restart: unless-stopped networks: - - changemaker-lite + - changemaker-lite-test4 # Gitea - Git service gitea-app: image: gitea/gitea:1.23.7 - container_name: gitea_changemaker + container_name: gitea_changemaker_test4-test4 environment: - USER_UID=${USER_ID:-1000} - USER_GID=${GROUP_ID:-1000} @@ -201,9 +201,9 @@ services: - GITEA__server__PROXY_ALLOW_SUBNET=0.0.0.0/0 restart: unless-stopped networks: - - changemaker-lite + - changemaker-lite-test4 volumes: - - gitea_data:/data + - gitea_data_test4:/data - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro ports: @@ -214,7 +214,7 @@ services: gitea-db: image: mysql:8 - container_name: gitea_mysql_changemaker + container_name: gitea_mysql_changemaker_test4_test4-test4 restart: unless-stopped environment: - MYSQL_ROOT_PASSWORD=${GITEA_DB_ROOT_PASSWORD} @@ -222,9 +222,9 @@ services: - MYSQL_PASSWORD=${GITEA_DB_PASSWD} - MYSQL_DATABASE=${GITEA_DB_NAME:-gitea} networks: - - changemaker-lite + - changemaker-lite-test4 volumes: - - mysql_data:/var/lib/mysql + - mysql_data_test4:/var/lib/mysql healthcheck: test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "${GITEA_DB_USER:-gitea}", "-p${GITEA_DB_PASSWD}"] interval: 10s @@ -238,17 +238,17 @@ services: - "${MINI_QR_PORT:-8089}:8080" restart: unless-stopped networks: - - changemaker-lite + - changemaker-lite-test4 # Shared Redis - Used by all services for caching, queues, sessions redis: image: redis:7-alpine - container_name: redis-changemaker + container_name: redis-changemaker-test4 command: redis-server --appendonly yes --maxmemory 512mb --maxmemory-policy allkeys-lru ports: - "6379:6379" volumes: - - redis-data:/data + - redis-data-test4:/data restart: always healthcheck: test: ["CMD", "redis-cli", "ping"] @@ -264,7 +264,7 @@ services: cpus: '0.25' memory: 256M networks: - - changemaker-lite + - changemaker-lite-test4 logging: driver: "json-file" options: @@ -274,7 +274,7 @@ services: # Prometheus - Metrics collection for all services prometheus: image: prom/prometheus:latest - container_name: prometheus-changemaker + container_name: prometheus-changemaker-test4 command: - '--config.file=/etc/prometheus/prometheus.yml' - '--storage.tsdb.path=/prometheus' @@ -283,17 +283,17 @@ services: - "${PROMETHEUS_PORT:-9090}:9090" volumes: - ./configs/prometheus:/etc/prometheus - - prometheus-data:/prometheus + - prometheus-data-test4:/prometheus restart: always networks: - - changemaker-lite + - changemaker-lite-test4 profiles: - monitoring # Grafana - Metrics visualization for all services grafana: image: grafana/grafana:latest - container_name: grafana-changemaker + container_name: grafana-changemaker-test4 ports: - "${GRAFANA_PORT:-3001}:3000" environment: @@ -301,13 +301,13 @@ services: - GF_USERS_ALLOW_SIGN_UP=false - GF_SERVER_ROOT_URL=${GRAFANA_ROOT_URL:-http://localhost:3001} volumes: - - grafana-data:/var/lib/grafana + - grafana-data-test4:/var/lib/grafana - ./configs/grafana:/etc/grafana/provisioning restart: always depends_on: - prometheus networks: - - changemaker-lite + - changemaker-lite-test4 profiles: - monitoring @@ -317,13 +317,13 @@ services: # SMTP: mailhog-changemaker:1025 mailhog: image: mailhog/mailhog:latest - container_name: mailhog-changemaker + container_name: mailhog-changemaker-test4 ports: - "1025:1025" # SMTP server - "8025:8025" # Web UI restart: unless-stopped networks: - - changemaker-lite + - changemaker-lite-test4 logging: driver: "json-file" options: @@ -331,16 +331,16 @@ services: max-file: "2" networks: - changemaker-lite: + changemaker-lite-test4: driver: bridge volumes: - listmonk-data: - n8n_data: - nc_data: - db_data: - gitea_data: - mysql_data: - redis-data: - prometheus-data: - grafana-data: \ No newline at end of file + listmonk-data-test4: + n8n_data_test4: + nc_data_test4: + db_data_test4: + gitea_data_test4: + mysql_data_test4: + redis-data-test4: + prometheus-data-test4: + grafana-data-test4: \ No newline at end of file diff --git a/reset-site.sh b/reset-site.sh old mode 100644 new mode 100755