From 25369e1aa83a35e58076adf1d20edd802f443464 Mon Sep 17 00:00:00 2001 From: whyour Date: Mon, 10 May 2021 22:21:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0bot=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/bot.sh | 21 ++++++++++++++------- shell/share.sh | 24 ++++++++++++++++++++++++ shell/update.sh | 24 ------------------------ 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/shell/bot.sh b/shell/bot.sh index 55b9e595..ad83aaf6 100644 --- a/shell/bot.sh +++ b/shell/bot.sh @@ -4,29 +4,36 @@ dir_shell=/ql/shell . $dir_shell/share.sh repo_path="${dir_repo}/SuMaiKaDe_jddockerbot" +url="https://ghproxy.com/https://github.com/SuMaiKaDe/jddockerbot.git" -echo -e "1、安装bot依赖...\n" +echo -e "\n1、安装bot依赖...\n" apk --no-cache add -f zlib-dev gcc jpeg-dev python3-dev musl-dev freetype-dev -echo +echo -e "\nbot依赖安装成功...\n" echo -e "2、下载bot所需文件...\n" -git clone -b master https://ghproxy.com/https://github.com/SuMaiKaDe/jddockerbot.git $repo_path +if [ -d ${repo_path}/.git ]; then + reset_romote_url ${repo_path} ${url} + git_pull_scripts ${repo_path} +else + git_clone_scripts ${url} ${repo_path} "master" +fi + cp -rf "$repo_path/jbot" $dir_root if [[ ! -f "$dir_root/config/bot.json" ]]; then cp -f "$repo_path/config/bot.json" "$dir_root/config" fi -echo +echo -e "\nbot文件下载成功...\n" echo -e "3、安装python3依赖...\n" pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple cp -f "$repo_path/jbot/requirements.txt" "$dir_root" pip3 --default-timeout=100 install -r requirements.txt --no-cache-dir -echo +echo -e "\npython3依赖安装成功...\n" echo -e "4、启动bot程序...\n" cd $dir_root ps -ef | grep "python3 -m jbot" | grep -v grep | awk '{print $1}' | xargs kill -9 2>/dev/null -nohup python3 -m jbot & >/dev/null 2>&1 -echo +nohup python3 -m jbot >$dir_log/bot/nohup.log 2>&1 & +echo -e "bot启动成功...\n" exit 0 diff --git a/shell/share.sh b/shell/share.sh index ea310b9b..3f214a26 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -252,6 +252,30 @@ update_depend() { cd $dir_current } +## 克隆脚本,$1:仓库地址,$2:仓库保存路径,$3:分支(可省略) +git_clone_scripts() { + local url=$1 + local dir=$2 + local branch=$3 + [[ $branch ]] && local cmd="-b $branch " + echo -e "开始克隆仓库 $url 到 $dir\n" + git clone $cmd $url $dir + exit_status=$? +} + +## 更新脚本,$1:仓库保存路径 +git_pull_scripts() { + local dir_current=$(pwd) + local dir_work=$1 + cd $dir_work + echo -e "开始更新仓库:$dir_work\n" + git fetch --all + exit_status=$? + git reset --hard + git pull + cd $dir_current +} + ## 导入配置文件,检测平台,创建软连接,识别命令,修复配置文件 detect_termux detect_macos diff --git a/shell/update.sh b/shell/update.sh index 0cca5f39..0ceb353e 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -23,30 +23,6 @@ reset_romote_url() { fi } -## 克隆脚本,$1:仓库地址,$2:仓库保存路径,$3:分支(可省略) -git_clone_scripts() { - local url=$1 - local dir=$2 - local branch=$3 - [[ $branch ]] && local cmd="-b $branch " - echo -e "开始克隆仓库 $url 到 $dir\n" - git clone $cmd $url $dir - exit_status=$? -} - -## 更新脚本,$1:仓库保存路径 -git_pull_scripts() { - local dir_current=$(pwd) - local dir_work=$1 - cd $dir_work - echo -e "开始更新仓库:$dir_work\n" - git fetch --all - exit_status=$? - git reset --hard - git pull - cd $dir_current -} - ## 检测cron的差异,$1:脚本清单文件路径,$2:cron任务清单文件路径,$3:增加任务清单文件路径,$4:删除任务清单文件路径 diff_cron() { local list_scripts="$1"