#!/usr/bin/env bash # Sync install wizard static files into the running Nexus prod container. # Primary fix: Dockerfile.prod bakes these into the image on build. # This script is a safety net after upgrade if an old image is still running. set -euo pipefail NEXUS_ROOT="${NEXUS_ROOT:-/opt/nexus}" CONTAINER="${NEXUS_CONTAINER:-}" info() { echo -e "\033[0;32m[INFO]\033[0m $*"; } warn() { echo -e "\033[1;33m[WARN]\033[0m $*"; } error() { echo -e "\033[0;31m[ERROR]\033[0m $*" >&2; } resolve_container() { if [[ -n "$CONTAINER" ]]; then return 0 fi CONTAINER="$(docker ps --format '{{.Names}}' | grep -E 'nexus-prod-nexus|nexus-nexus-1' | head -1 || true)" if [[ -z "$CONTAINER" ]]; then error "未找到运行中的 Nexus 容器(可设 NEXUS_CONTAINER=名称)" exit 1 fi info "容器: $CONTAINER" } sync_file() { local src="$1" dest="$2" if [[ ! -f "$src" ]]; then error "缺少源文件: $src" exit 1 fi docker exec "$CONTAINER" mkdir -p "$(dirname "$dest")" docker cp "$src" "${CONTAINER}:${dest}" } main() { local app="$NEXUS_ROOT/web/app" if [[ ! -f "$app/install.html" ]]; then error "仓库中无 $app/install.html,请先 git pull" exit 1 fi resolve_container info "同步安装向导静态文件..." sync_file "$app/install.html" /app/web/app/install.html sync_file "$app/vendor/tailwindcss-browser.js" /app/web/app/vendor/tailwindcss-browser.js sync_file "$app/vendor/theme-init.js" /app/web/app/vendor/theme-init.js sync_file "$app/vendor/theme.css" /app/web/app/vendor/theme.css sync_file "$app/vendor/alpinejs.min.js" /app/web/app/vendor/alpinejs.min.js local install_py="$NEXUS_ROOT/server/api/install.py" if [[ -f "$install_py" ]]; then info "同步 install.py(Docker Redis env-check 修复)..." sync_file "$install_py" /app/server/api/install.py info "重启 Nexus 容器以加载 Python 变更..." docker restart "$CONTAINER" >/dev/null for _ in $(seq 1 30); do if curl -sf http://127.0.0.1:8600/health >/dev/null 2>&1; then break fi sleep 2 done else warn "未找到 $install_py,跳过 Python 热同步" fi local code code="$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8600/app/install.html 2>/dev/null || echo 000)" if [[ "$code" == "200" ]]; then info "/app/install.html → HTTP 200" else warn "/app/install.html → HTTP $code(请检查 Nexus 是否在 8600 监听)" exit 1 fi } main "$@"