fundplatform/scripts/deploy/deploy-config.sh
zhangjf 852af7ee26 fix: 远程执行命令时加载环境变量
- 使用 bash -l 加载登录 shell 环境变量
- 解决 SSH 非交互式 shell 不加载 .bash_profile 导致 java 命令找不到的问题
2026-02-23 15:51:41 +08:00

76 lines
1.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ============================================
# 部署配置文件
# ============================================
# 生产环境SSH配置
PROD_HOST="82.156.159.46"
PROD_USER="fundsp"
PROD_PASSWORD="fdsp@Ywj\$107P#KM"
# 部署路径配置
MOBILE_DEPLOY_PATH="/home/fundsp/portal/fmobile"
ADMIN_DEPLOY_PATH="/home/fundsp/portal/fadmin"
SERVICE_DEPLOY_BASE="/home/fundsp/app"
# 本地打包路径
# 获取项目根目录(脚本目录的上两级)
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
LOCAL_DEPLOY_DIR="$PROJECT_ROOT/deploy"
LOCAL_MOBILE_ZIP="fund-mobile.zip"
LOCAL_ADMIN_ZIP="fund-admin.zip"
# 服务列表
SERVICES=(
"fund-gateway"
"fund-sys"
"fund-cust"
"fund-proj"
"fund-exp"
"fund-receipt"
"fund-report"
"fund-req"
"fund-file"
)
# 颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# 日志函数
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# 检查sshpass是否安装
check_sshpass() {
if ! command -v sshpass &> /dev/null; then
log_error "sshpass 未安装,请先安装: sudo apt install sshpass"
exit 1
fi
}
# 执行远程命令(加载环境变量)
remote_exec() {
local cmd="$1"
# 使用 bash -l 加载登录 shell 环境变量(包括 .bash_profile
sshpass -p "$PROD_PASSWORD" ssh -o StrictHostKeyChecking=no "$PROD_USER@$PROD_HOST" "bash -l -c '$cmd'"
}
# 上传文件
upload_file() {
local local_path="$1"
local remote_path="$2"
sshpass -p "$PROD_PASSWORD" scp -o StrictHostKeyChecking=no "$local_path" "$PROD_USER@$PROD_HOST:$remote_path"
}