提交 495d70a4 authored 作者: Andy's avatar Andy

123

上级 0b7d6a2d
......@@ -5,40 +5,24 @@ install_dir="/home/deploy/wkgameplat"
GamePlat_ranch=1031_Game_JinSha
GameWeb_ranch=1031_Game_JinSha
Svr_Repo_Url="git@git.wkwork.xyz:LaunchDeploy/wk_gameplat_svr.git"
Svr_Base_Dir="./svr"
Svr_Branches=(
$GamePlat_ranch
)
Web_Repo_Url="git@git.wkwork.xyz:LaunchDeploy/wk_gameplat_web.git"
Web_Base_Dir="./web"
Web_Branches=(
$GamePlat_ranch
)
if [ ! -d "$install_dir" ]; then
mkdir -p "$install_dir"
fi
cd $install_dir
# 输出函数
# echo_content() {
# ECHO_TYPE="echo -e"
# case $1 in
# "red")
# ${ECHO_TYPE} "\033[31m$2\033[0m"
# ;;
# "green")
# ${ECHO_TYPE} "\033[32m$2\033[0m"
# ;;
# "yellow")
# ${ECHO_TYPE} "\033[33m$2\033[0m"
# ;;
# "blue")
# ${ECHO_TYPE} "\033[34m$2\033[0m"
# ;;
# "purple")
# ${ECHO_TYPE} "\033[35m$2\033[0m"
# ;;
# "skyBlue")
# ${ECHO_TYPE} "\033[36m$2\033[0m"
# ;;
# "white")
# ${ECHO_TYPE} "\033[37m$2\033[0m"
# ;;
# esac
# }
echo_content() {
local color="$1"
local text="$2"
......@@ -58,131 +42,25 @@ echo_content() {
esac
}
# 更新分支函数(带更新前恢复)
update_branch() {
local repo_url=$1
local branch=$2
local target_dir=$3
echo "Updating branch '$branch' in '$target_dir'..."
cd "$target_dir" || return 1
# 切换到目标分支
git checkout "$branch" >/dev/null 2>&1
# 更新前恢复到干净状态
echo "🔄 Resetting local changes on '$branch'..."
git reset --hard HEAD >/dev/null 2>&1
git clean -fd >/dev/null 2>&1
# 获取远程最新提交
git fetch origin "$branch"
local_commit=$(git rev-parse "$branch")
remote_commit=$(git rev-parse "origin/$branch")
if [ "$local_commit" = "$remote_commit" ]; then
echo "✅ Branch '$branch' is up-to-date."
else
echo "⬇️ Branch '$branch' has updates. Pulling changes..."
RETRY=0
until git pull origin "$branch"; do
RETRY=$((RETRY + 1))
if [ "$RETRY" -ge "$MAX_RETRY" ]; then
echo "❌ Failed to update '$branch' after $MAX_RETRY attempts."
break
fi
echo "Retrying pull for '$branch' ($RETRY/$MAX_RETRY)..."
sleep 2
done
fi
cd - >/dev/null
check_install_dependencies() {
bash <(curl -sSL http://oauth2:QFF_7BNyjHsq_Zvfsfut@git.wkwork.xyz/LaunchDeploy/install/raw/master/deps_gameplat.sh) check_install_dependencies
}
# 克隆分支函数
clone_branch() {
local repo_url=$1
local branch=$2
local target_dir=$3
echo "Cloning branch '$branch' into '$target_dir'..."
RETRY=0
until git clone --branch "$branch" --single-branch "$repo_url" "$target_dir"; do
RETRY=$((RETRY + 1))
if [ "$RETRY" -ge "$MAX_RETRY" ]; then
echo "❌ Failed to clone '$branch' after $MAX_RETRY attempts."
break
fi
echo "Retrying clone for '$branch' ($RETRY/$MAX_RETRY)..."
sleep 2
done
check_gitaccount() {
bash <(curl -sSL http://oauth2:QFF_7BNyjHsq_Zvfsfut@git.wkwork.xyz/LaunchDeploy/install/raw/master/gitaccount.sh) check_gitaccount
}
fetch_git_platsvr() {
REPO_URL="git@git.wkwork.xyz:LaunchDeploy/wk_gameplat_svr.git"
BASE_DIR="./svr"
MAX_RETRY=3 # 最大重试次数
BRANCHES=(
$GamePlat_ranch
)
# 主循环
for BRANCH in "${BRANCHES[@]}"; do
TARGET_DIR="$BASE_DIR/$BRANCH"
if [ -d "$TARGET_DIR/.git" ]; then
update_branch "$REPO_URL" "$BRANCH" "$TARGET_DIR"
else
clone_branch "$REPO_URL" "$BRANCH" "$TARGET_DIR"
fi
done
bash <(curl -sSL http://oauth2:QFF_7BNyjHsq_Zvfsfut@git.wkwork.xyz/LaunchDeploy/install/raw/master/gitaccount.sh) fetch_git_platsvr $Svr_Repo_Url $Svr_Base_Dir $Svr_Branches
}
# fetch_git_platweb() {
# REPO_URL="git@git.wkwork.xyz:LaunchDeploy/wk_gameplat_web.git"
# BASE_DIR="./web"
# MAX_RETRY=3 # 最大重试次数
# BRANCHES=(
# $GamePlat_ranch
# )
# # 主循环
# for BRANCH in "${BRANCHES[@]}"; do
# TARGET_DIR="$BASE_DIR/$BRANCH"
# if [ -d "$TARGET_DIR/.git" ]; then
# update_branch "$REPO_URL" "$BRANCH" "$TARGET_DIR"
# else
# clone_branch "$REPO_URL" "$BRANCH" "$TARGET_DIR"
# fi
# done
# }
Web_Repo_Url="git@git.wkwork.xyz:LaunchDeploy/wk_gameplat_web.git"
Web_Base_Dir="./web"
Web_Branches=(
$GamePlat_ranch
)
fetch_git_platweb() {
bash <(curl -sSL http://oauth2:QFF_7BNyjHsq_Zvfsfut@git.wkwork.xyz/LaunchDeploy/install/raw/master/gitaccount.sh) fetch_git_platweb $Web_Repo_Url $Web_Base_Dir $Web_Branches
local tmp_web_repo_url=$1
local tmp_base_dir=$2
local tmp_branches=$3
# 主循环
for branch in "${tmp_branches[@]}"; do
tmp_target_dir="$tmp_base_dir/$branch"
}
if [ -d "$tmp_target_dir/.git" ]; then
update_branch "$tmp_web_repo_url" "$branch" "$tmp_target_dir"
else
clone_branch "$tmp_web_repo_url" "$branch" "$tmp_target_dir"
fi
done
linux_docker() {
bash <(curl -sSL http://oauth2:QFF_7BNyjHsq_Zvfsfut@git.wkwork.xyz/LaunchDeploy/install/raw/master/docker.sh) linux_docker
}
run_docker() {
......@@ -208,10 +86,6 @@ run_service() {
cd ../..
}
check_install_dependencies() {
bash <(curl -sSL http://oauth2:QFF_7BNyjHsq_Zvfsfut@git.wkwork.xyz/LaunchDeploy/install/raw/master/deps_gameplat.sh) check_install_dependencies
}
# ------------------ 数组定义菜单项 ------------------
MENU_ITEMS=(
"测试 Git 账户"
......@@ -226,13 +100,13 @@ MENU_ITEMS=(
# 每个编号对应一个函数(index 对齐 MENU_ITEMS)
MENU_ACTIONS=(
"bash <(curl -sSL http://oauth2:QFF_7BNyjHsq_Zvfsfut@git.wkwork.xyz/LaunchDeploy/install/raw/master/gitaccount.sh) check_gitaccount"
"check_gitaccount"
"fetch_git_platsvr"
"fetch_git_platweb $Web_Repo_Url $Web_Base_Dir $Web_Branches"
"fetch_git_platweb"
"fetch_git_gameweb"
"run_docker"
"run_service"
"bash <(curl -sSL http://oauth2:QFF_7BNyjHsq_Zvfsfut@git.wkwork.xyz/LaunchDeploy/install/raw/master/docker.sh) linux_docker"
"linux_docker"
"exit 0"
)
......
......@@ -78,3 +78,100 @@ EOF
fi
}
# 更新分支函数(带更新前恢复)
update_branch() {
local repo_url=$1
local branch=$2
local target_dir=$3
echo "Updating branch '$branch' in '$target_dir'..."
cd "$target_dir" || return 1
# 切换到目标分支
git checkout "$branch" >/dev/null 2>&1
# 更新前恢复到干净状态
echo "🔄 Resetting local changes on '$branch'..."
git reset --hard HEAD >/dev/null 2>&1
git clean -fd >/dev/null 2>&1
# 获取远程最新提交
git fetch origin "$branch"
local_commit=$(git rev-parse "$branch")
remote_commit=$(git rev-parse "origin/$branch")
if [ "$local_commit" = "$remote_commit" ]; then
echo "✅ Branch '$branch' is up-to-date."
else
echo "⬇️ Branch '$branch' has updates. Pulling changes..."
RETRY=0
until git pull origin "$branch"; do
RETRY=$((RETRY + 1))
if [ "$RETRY" -ge "$MAX_RETRY" ]; then
echo "❌ Failed to update '$branch' after $MAX_RETRY attempts."
break
fi
echo "Retrying pull for '$branch' ($RETRY/$MAX_RETRY)..."
sleep 2
done
fi
cd - >/dev/null
}
# 克隆分支函数
clone_branch() {
local repo_url=$1
local branch=$2
local target_dir=$3
echo "Cloning branch '$branch' into '$target_dir'..."
RETRY=0
until git clone --branch "$branch" --single-branch "$repo_url" "$target_dir"; do
RETRY=$((RETRY + 1))
if [ "$RETRY" -ge "$MAX_RETRY" ]; then
echo "❌ Failed to clone '$branch' after $MAX_RETRY attempts."
break
fi
echo "Retrying clone for '$branch' ($RETRY/$MAX_RETRY)..."
sleep 2
done
}
fetch_git_platsvr() {
local tmp_svr_repo_url=$1
local tmp_svr_base_dir=$2
local tmp_svr_branches=$3
# 主循环
for branch in "${tmp_svr_branches[@]}"; do
tmp_target_dir="$tmp_svr_base_dir/$branch"
if [ -d "$tmp_target_dir/.git" ]; then
update_branch "$tmp_svr_repo_url" "$branch" "$tmp_target_dir"
else
clone_branch "$tmp_svr_repo_url" "$branch" "$tmp_target_dir"
fi
done
}
fetch_git_platweb() {
local tmp_web_repo_url=$1
local tmp_web_base_dir=$2
local tmp_web_branches=$3
# 主循环
for branch in "${tmp_web_branches[@]}"; do
tmp_target_dir="$tmp_web_base_dir/$branch"
if [ -d "$tmp_target_dir/.git" ]; then
update_branch "$tmp_web_repo_url" "$branch" "$tmp_target_dir"
else
clone_branch "$tmp_web_repo_url" "$branch" "$tmp_target_dir"
fi
done
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论