From 75a4e7502c6de7b94e4c960c88fad5baacc231c4 Mon Sep 17 00:00:00 2001 From: lhx Date: Thu, 30 Oct 2025 15:36:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index 2d47960..16c4565 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,13 +1,62 @@ #!/bin/bash # 服务部署脚本 -# 用于停止旧服务并启动新服务 +# 用于停止旧服务并重新启动服务 +# 使用方法: ./deploy.sh [0] (带0参数时不拉取代码) echo "=== 服务部署脚本 ===" echo "此脚本将停止当前服务并重新启动服务" echo "" +# 检查是否跳过git pull +SKIP_GIT_PULL=0 +if [ "$1" = "0" ]; then + SKIP_GIT_PULL=1 + echo "跳过代码拉取,直接部署" +else + echo "默认执行代码拉取" +fi + +# 如果不跳过git pull,则拉取最新代码 +if [ $SKIP_GIT_PULL -eq 0 ]; then + echo "" + echo "正在拉取最新代码..." + + # 读取gitea用户名和密码 + echo -n "请输入gitea用户名: " + read -r GIT_USERNAME + echo -n "请输入gitea密码: " + read -s GIT_PASSWORD + echo "" + + # 设置git凭据 + git config credential.helper store + echo "https://$GIT_USERNAME:$GIT_PASSWORD@gitea.com" > ~/.git-credentials + + # 拉取代码 + git pull origin main + + if [ $? -eq 0 ]; then + echo "✓ 代码拉取成功" + # 清除git凭据 + rm -f ~/.git-credentials + git config --unset credential.helper + else + echo "✗ 代码拉取失败" + # 清除git凭据 + rm -f ~/.git-credentials + git config --unset credential.helper + echo "是否继续部署? (y/n)" + read -r CONTINUE_DEPLOY + if [ "$CONTINUE_DEPLOY" != "y" ] && [ "$CONTINUE_DEPLOY" != "Y" ]; then + echo "部署已取消" + exit 1 + fi + fi +fi + # 读取sudo密码 +echo "" echo -n "请输入sudo密码: " read -s SUDO_PASSWORD echo "" From e6815176ae81410f199e44236a3b1398e13e6642 Mon Sep 17 00:00:00 2001 From: lhx Date: Thu, 30 Oct 2025 15:49:05 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy.sh | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/deploy.sh b/deploy.sh index 16c4565..788f120 100644 --- a/deploy.sh +++ b/deploy.sh @@ -29,23 +29,22 @@ if [ $SKIP_GIT_PULL -eq 0 ]; then read -s GIT_PASSWORD echo "" - # 设置git凭据 - git config credential.helper store - echo "https://$GIT_USERNAME:$GIT_PASSWORD@gitea.com" > ~/.git-credentials - - # 拉取代码 - git pull origin main + # 直接使用URL中的用户名密码进行拉取 + git_url=$(git remote get-url origin) + if [[ $git_url == http* ]]; then + # 如果是http/https URL,替换为包含用户名密码的URL + git_url_with_auth=$(echo $git_url | sed "s|https://|https://$GIT_USERNAME:$GIT_PASSWORD@|") + git pull $git_url_with_auth main + else + # 如果是ssh或其他格式,使用expect或者让git自动处理 + echo "使用凭据拉取代码..." + git pull origin main + fi if [ $? -eq 0 ]; then echo "✓ 代码拉取成功" - # 清除git凭据 - rm -f ~/.git-credentials - git config --unset credential.helper else echo "✗ 代码拉取失败" - # 清除git凭据 - rm -f ~/.git-credentials - git config --unset credential.helper echo "是否继续部署? (y/n)" read -r CONTINUE_DEPLOY if [ "$CONTINUE_DEPLOY" != "y" ] && [ "$CONTINUE_DEPLOY" != "Y" ]; then From 51137625deef77b70303bfbefb9e631f5c3bb99b Mon Sep 17 00:00:00 2001 From: lhx Date: Thu, 30 Oct 2025 15:52:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy.sh | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/deploy.sh b/deploy.sh index 788f120..fb764b6 100644 --- a/deploy.sh +++ b/deploy.sh @@ -21,25 +21,7 @@ fi if [ $SKIP_GIT_PULL -eq 0 ]; then echo "" echo "正在拉取最新代码..." - - # 读取gitea用户名和密码 - echo -n "请输入gitea用户名: " - read -r GIT_USERNAME - echo -n "请输入gitea密码: " - read -s GIT_PASSWORD - echo "" - - # 直接使用URL中的用户名密码进行拉取 - git_url=$(git remote get-url origin) - if [[ $git_url == http* ]]; then - # 如果是http/https URL,替换为包含用户名密码的URL - git_url_with_auth=$(echo $git_url | sed "s|https://|https://$GIT_USERNAME:$GIT_PASSWORD@|") - git pull $git_url_with_auth main - else - # 如果是ssh或其他格式,使用expect或者让git自动处理 - echo "使用凭据拉取代码..." - git pull origin main - fi + git pull origin main if [ $? -eq 0 ]; then echo "✓ 代码拉取成功"