Files
Nexus/deploy/upgrade.sh
T
Your Name a1276f38ad feat: 一键安装脚本 + PHP完全移除 + config.php→config.json
新增文件:
- deploy/install.sh: 7步一键安装(自动检测宝塔/标准模式)
- deploy/upgrade.sh: git pull + pip install + restart + 健康检查
- deploy/uninstall.sh: 停服务+删配置, 可选--purge删部署目录
- docs/install-guide.md: 完整中文安装教程(宝塔+手动)

核心改动:
- install.py: 宝塔Supervisor路径自适应, init-db返回bt_panel标记,
  config.php→config.json, 移除PHP锁文件, 生成Fernet加密密钥
- install.html: Step 5根据btPanel显示不同Supervisor/Nginx/SSL指引
- crypto.py: 移除PHP AES-CBC兼容层, 纯Fernet加密
- 删除 web/install.php (1192行PHP, 功能已完全迁移到Python)

PHP清理:
- Nginx配置: config\.php→config\.json deny规则
- config.py/main.py/migrations.py: install.php注释→install wizard
- CLAUDE.md/AGENTS.md: config.php→config.json, 移除PHP引用
- firefox_server.py: login.php→login.html默认URL

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-05-25 08:23:37 +08:00

131 lines
3.6 KiB
Bash

#!/bin/bash
# ================================================================
# Nexus 6.0 — Upgrade Script
#
# Usage:
# sudo bash upgrade.sh # auto-detect deploy dir
# sudo bash upgrade.sh --deploy-dir /opt/nexus # specify deploy dir
#
# Safe: git pull + pip install + restart. Database is NOT touched.
# ================================================================
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*"; }
DEPLOY_DIR=""
while [[ $# -gt 0 ]]; do
case $1 in
--deploy-dir) DEPLOY_DIR="$2"; shift 2 ;;
-h|--help)
echo "Usage: sudo bash upgrade.sh [--deploy-dir PATH]"
exit 0 ;;
*) shift ;;
esac
done
# Auto-detect deploy directory
if [ -z "$DEPLOY_DIR" ]; then
# Check common locations
for d in /opt/nexus /www/wwwroot/*/; do
if [ -d "$d/server" ] && [ -d "$d/web" ]; then
DEPLOY_DIR="$d"
break
fi
done
# Try from Supervisor config
if [ -z "$DEPLOY_DIR" ]; then
DEPLOY_DIR=$(supervisorctl status nexus 2>/dev/null | grep -oP 'cwd=\K[^ ,]+' || true)
fi
fi
if [ -z "$DEPLOY_DIR" ] || [ ! -d "$DEPLOY_DIR/server" ]; then
error "Cannot find Nexus installation. Use --deploy-dir to specify."
exit 1
fi
VENV_DIR="$DEPLOY_DIR/venv"
ENV_FILE="$DEPLOY_DIR/.env"
echo ""
echo "=========================================="
echo " Nexus 6.0 Upgrade"
echo "=========================================="
echo " Deploy: $DEPLOY_DIR"
echo ""
# 1. Pull latest code
info "Step 1/4: Updating source code..."
if [ -d "$DEPLOY_DIR/.git" ]; then
cd "$DEPLOY_DIR"
OLD_REV=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
git pull --ff-only 2>/dev/null || {
error "git pull failed. You may have local changes."
error "Resolve conflicts manually: cd $DEPLOY_DIR && git status"
exit 1
}
NEW_REV=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
if [ "$OLD_REV" = "$NEW_REV" ]; then
info " Already up to date (no new commits)"
else
info " Updated: ${OLD_REV:0:8}..${NEW_REV:0:8}"
fi
else
warn " Not a git repo. Skip git pull (update files manually)"
fi
# 2. Update Python dependencies
info "Step 2/4: Updating Python dependencies..."
if [ -d "$VENV_DIR/bin" ]; then
"$VENV_DIR/bin/pip" install -q --upgrade pip
"$VENV_DIR/bin/pip" install -q -r "$DEPLOY_DIR/requirements.txt" 2>/dev/null || {
warn " pip install had some warnings, but continuing..."
}
else
error " venv not found at $VENV_DIR. Run install.sh first."
exit 1
fi
# 3. Restart application
info "Step 3/4: Restarting Nexus..."
supervisorctl restart nexus >/dev/null 2>&1 || {
warn " supervisorctl restart failed. Try manually: supervisorctl restart nexus"
}
# 4. Health check
info "Step 4/4: Verifying health..."
# Read port from .env or default
PORT=8600
if [ -f "$ENV_FILE" ]; then
PORT_FROM_ENV=$(grep '^NEXUS_PORT=' "$ENV_FILE" 2>/dev/null | cut -d'=' -f2 || true)
[ -n "$PORT_FROM_ENV" ] && PORT="$PORT_FROM_ENV"
fi
HEALTH_OK=false
for i in $(seq 1 15); do
if curl -sf "http://127.0.0.1:$PORT/health" >/dev/null 2>&1; then
HEALTH_OK=true
break
fi
sleep 2
done
echo ""
if [ "$HEALTH_OK" = true ]; then
echo -e " ${GREEN}Upgrade complete! Nexus is healthy.${NC}"
else
echo -e " ${YELLOW}Health check pending. Verify manually:${NC}"
echo " curl http://127.0.0.1:$PORT/health"
echo " supervisorctl status nexus"
fi
echo ""