#!/bin/bash # Phase 4: Sync configuration to secondary set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" if [ -f "$PROJECT_ROOT/.env" ]; then set +euo pipefail source "$PROJECT_ROOT/.env" 2>/dev/null || true set -euo pipefail fi log_info() { echo -e "\033[0;34m[INFO]\033[0m $1"; } log_success() { echo -e "\033[0;32m[✓]\033[0m $1"; } log_warn() { echo -e "\033[1;33m[⚠]\033[0m $1"; } log_info "Syncing configuration to secondary..." # Export from primary log_info "Exporting primary configuration..." EXPORT_DIR=$(bash "$SCRIPT_DIR/export-primary-config.sh" 2>&1 | grep "exported to" | awk '{print $NF}' || echo "") if [ -z "$EXPORT_DIR" ] || [ ! -d "$EXPORT_DIR" ]; then log_warn "Could not determine export directory, trying default location..." EXPORT_DIR=$(ls -td /tmp/npmplus-config-backup-* 2>/dev/null | head -1 || echo "") fi if [ -n "$EXPORT_DIR" ] && [ -d "$EXPORT_DIR" ]; then log_info "Importing to secondary..." bash "$SCRIPT_DIR/import-secondary-config.sh" "$EXPORT_DIR" || { log_warn "Import failed, but continuing..." } log_success "Configuration sync attempted" else log_warn "Export directory not found, skipping import" fi # Sync certificates log_info "Syncing certificates..." bash "$SCRIPT_DIR/sync-certificates.sh" || { log_warn "Certificate sync failed" } log_success "Phase 4 complete: Configuration sync attempted"