From 2923f6be1ce1e892ade58e49b62b9aa1598508c4 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Thu, 5 Aug 2021 14:42:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drepo=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6=E5=94=AF=E4=B8=80=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/api.sh | 6 ++---- shell/task.sh | 18 +++++++++--------- shell/update.sh | 29 ++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/shell/api.sh b/shell/api.sh index 1cf19aca..d241a3a8 100755 --- a/shell/api.sh +++ b/shell/api.sh @@ -169,10 +169,8 @@ update_cron() { ) code=$(echo $api | jq -r .code) message=$(echo $api | jq -r .message) - if [[ $code == 200 ]]; then - echo -e "## 更新任务状态成功\n" >> $log_path - else - echo -e "\n## 更新任务状态失败(${message})" >> $log_path + if [[ $code != 200 ]]; then + echo -e "\n## 更新任务状态失败(${message})\n" >> $log_path fi } diff --git a/shell/task.sh b/shell/task.sh index 56b102b2..4671e846 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -93,11 +93,11 @@ run_normal() { local begin_time=$(date '+%Y-%m-%d %H:%M:%S') echo -e "## 开始执行... $begin_time\n" >> $log_path [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" - . $file_task_before + . $file_task_before >> $log_path 2>&1 - timeout -k 10s $command_timeout_time $which_program $p1 2>&1 >> $log_path + timeout -k 10s $command_timeout_time $which_program $p1 >> $log_path 2>&1 - . $file_task_after + . $file_task_after >> $log_path 2>&1 [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" local end_time=$(date '+%Y-%m-%d %H:%M:%S') local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time"))) @@ -127,17 +127,17 @@ run_concurrent() { local begin_time=$(date '+%Y-%m-%d %H:%M:%S') echo -e "## 开始执行... $begin_time\n" >> $log_path [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" - . $file_task_before + . $file_task_before >> $log_path 2>&1 echo -e "\n各账号间已经在后台开始并发执行,前台不输入日志,日志直接写入文件中。\n" >> $log_path single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N") for i in "${!array[@]}"; do export ${p3}=${array[i]} single_log_path="$log_dir/${single_log_time}_$((i + 1)).log" - timeout -k 10s $command_timeout_time $which_program $p1 &>$single_log_path & + timeout -k 10s $command_timeout_time $which_program $p1 &>$single_log_path 2>&1 & done - . $file_task_after + . $file_task_after >> $log_path 2>&1 [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" local end_time=$(date '+%Y-%m-%d %H:%M:%S') local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time"))) @@ -156,11 +156,11 @@ run_else() { local begin_time=$(date '+%Y-%m-%d %H:%M:%S') echo -e "## 开始执行... $begin_time\n" >> $log_path [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" - . $file_task_before + . $file_task_before >> $log_path 2>&1 - timeout -k 10s $command_timeout_time "$@" 2>&1 >> $log_path + timeout -k 10s $command_timeout_time "$@" >> $log_path 2>&1 - . $file_task_after + . $file_task_after >> $log_path 2>&1 [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" local end_time=$(date '+%Y-%m-%d %H:%M:%S') local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time"))) diff --git a/shell/update.sh b/shell/update.sh index 01e0ce6a..02473a55 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -141,16 +141,12 @@ update_repo() { local blackword="$3" local dependence="$4" local branch="$5" - local urlTmp="${url%*/}" - local repoTmp="${urlTmp##*/}" - local repo="${repoTmp%.*}" local tmp="${url%/*}" local authorTmp1="${tmp##*/}" local authorTmp2="${authorTmp1##*:}" local author="${authorTmp2##*.}" - local repo_path="${dir_repo}/${author}_${repo}" - [[ $branch ]] && repo_path="${repo_path}_${branch}" + local repo_path="${dir_repo}/${uniq_path}" local formatUrl="${github_proxy_url}${url/https:\/\/ghproxy.com\//}" if [ -d ${repo_path}/.git ]; then @@ -392,6 +388,21 @@ gen_list_repo() { cd $dir_current } +get_uniq_path() { + local url="$1" + local branch="$2" + local urlTmp="${url%*/}" + local repoTmp="${urlTmp##*/}" + local repo="${repoTmp%.*}" + local tmp="${url%/*}" + local authorTmp1="${tmp##*/}" + local authorTmp2="${authorTmp1##*:}" + local author="${authorTmp2##*.}" + + uniq_path="${author}_${repo}" + [[ $branch ]] && uniq_path="${uniq_path}_${branch}" +} + main() { local p1=$1 local p2=$2 @@ -413,8 +424,8 @@ main() { ;; repo) get_user_info - local name=$(echo "${p2##*/}" | awk -F "." '{print $1}') - log_path="$dir_log/update/${log_time}_$name.log" + get_uniq_path "$p2" "$p6" + log_path="$dir_log/update/${log_time}_${uniq_path}.log" echo -e "## 开始执行... $begin_time\n" >> $log_path if [[ -n $p2 ]]; then update_repo "$p2" "$p3" "$p4" "$p5" "$p6" | tee -p -a $log_path @@ -425,8 +436,8 @@ main() { ;; raw) get_user_info - local name=$(echo "${p2##*/}" | awk -F "." '{print $1}') - log_path="$dir_log/update/${log_time}_$name.log" + get_uniq_path "$p2" + log_path="$dir_log/update/${log_time}_${uniq_path}.log" echo -e "## 开始执行... $begin_time\n" >> $log_path if [[ -n $p2 ]]; then update_raw "$p2" | tee -p -a $log_path