diff --git a/deploy.sh b/deploy.sh index 637f9cd..9af8eeb 100755 --- a/deploy.sh +++ b/deploy.sh @@ -78,48 +78,27 @@ setup_go_proxy() { } # ---------------------------------------------------------- -# 4. 生成 .env 配置文件 +# 4. 读取 .env 配置文件 # ---------------------------------------------------------- -setup_env() { +load_env() { local port="${1:-9050}" - if [ -f ".env" ]; then - warn ".env 文件已存在,跳过生成" - # 确保端口是最新的 - if grep -q "^PORT=" .env; then - sed -i "s/^PORT=.*/PORT=${port}/" .env - else - echo "PORT=${port}" >> .env - fi - return + if [ ! -f ".env" ]; then + error ".env 文件不存在,请先执行: cp .env.example .env 并填写 MySQL 连接信息" fi - info "生成 .env 配置文件..." + info "读取 .env 配置..." + set -a + # shellcheck disable=SC1091 + source .env + set +a - # 生成随机 MySQL 密码 - local mysql_password - mysql_password=$(openssl rand -base64 16 | tr -dc 'a-zA-Z0-9' | head -c 20) + # 命令行参数覆盖 .env 中的 PORT + if [ -n "$port" ]; then + export PORT="$port" + fi - cat > .env <