diff --git a/shell/update.sh b/shell/update.sh index fd0462a9..e7a85ae7 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -34,7 +34,6 @@ output_list_add_drop() { if [[ -s $list ]]; then echo -e "检测到有${type}的定时任务:" cat $list - echo fi } @@ -45,7 +44,7 @@ del_cron() { local path=$2 local detail="" local ids="" - echo -e "开始尝试自动删除失效的定时任务..." + echo -e "\n开始尝试自动删除失效的定时任务..." for cron in $(cat $list_drop); do local id=$(cat $list_crontab_user | grep -E "$cmd_task.* $cron" | perl -pe "s|.*ID=(.*) $cmd_task.* $cron\.*|\1|" | head -1 | awk -F " " '{print $1}') if [[ $ids ]]; then @@ -76,7 +75,7 @@ del_cron() { add_cron() { local list_add=$1 local path=$2 - echo -e "开始尝试自动添加定时任务..." + echo -e "\n开始尝试自动添加定时任务..." local detail="" cd $dir_scripts for file in $(cat $list_add); do @@ -86,19 +85,20 @@ add_cron() { cron_line=$( perl -ne "{ print if /.*([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*]( |,|\").*$file_name/ - }" $file | + }" $file 2>/dev/null | perl -pe "{ s|[^\d\*]*(([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*])( \|,\|\").*/?$file_name.*|\1|g; s|\*([\d\*])(.*)|\1\2|g; s| | |g; - }" | sort -u | head -1 + }" 2>/dev/null | sort -u | head -1 ) - cron_name=$(grep "new Env" $file | awk -F "\(" '{print $2}' | awk -F "\)" '{print $1}' | sed 's:.*\('\''\|"\)\([^"'\'']*\)\('\''\|"\).*:\2:' | sed 's:"::g' | sed "s:'::g" | head -1) - [[ -z $cron_name ]] && cron_name="$file_name" [[ -z $cron_line ]] && cron_line=$(grep "cron:" $file | awk -F ":" '{print $2}' | head -1 | xargs) [[ -z $cron_line ]] && cron_line=$(grep "cron " $file | awk -F "cron \"" '{print $2}' | awk -F "\" " '{print $1}' | head -1 | xargs) [[ -z $cron_line ]] && cron_line="$default_cron" - result=$(add_cron_api "$cron_line:$cmd_task $file:$cron_name:$SUB_ID") + cron_name=$(grep "new Env" $file | awk -F "\(" '{print $2}' | awk -F "\)" '{print $1}' | sed 's:.*\('\''\|"\)\([^"'\'']*\)\('\''\|"\).*:\2:' | sed 's:"::g' | sed "s:'::g" | head -1) + [[ -z $cron_name ]] && cron_name=$(grep "name:" $file | awk -F ":" '{print $2}' | head -1 | xargs) + [[ -z $cron_name ]] && cron_name=$(basename "$file_name") + result=$(add_cron_api "${cron_line}:${cmd_task} ${file}:${cron_name}:${SUB_ID}") echo -e "$result" if [[ $detail ]]; then detail="${detail}${result}\n" @@ -135,10 +135,10 @@ update_repo() { git_clone_scripts "${formatUrl}" ${repo_path} "${branch}" "${proxy}" if [[ $exit_status -eq 0 ]]; then - echo -e "\n拉取 ${uniq_path} 成功...\n" + echo -e "拉取 ${uniq_path} 成功...\n" diff_scripts "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions" "$autoAddCron" "$autoDelCron" else - echo -e "\n拉取 ${uniq_path} 失败,请检查日志...\n" + echo -e "拉取 ${uniq_path} 失败,请检查日志...\n" fi } @@ -195,7 +195,7 @@ update_raw() { [[ -z $cron_line ]] && cron_line=$(grep "cron:" $raw_file_name | awk -F ":" '{print $2}' | head -1 | xargs) [[ -z $cron_line ]] && cron_line=$(grep "cron " $raw_file_name | awk -F "cron \"" '{print $2}' | awk -F "\" " '{print $1}' | head -1 | xargs) [[ -z $cron_line ]] && cron_line="$default_cron" - result=$(add_cron_api "$cron_line:$cmd_task $filename:$cron_name:$SUB_ID") + result=$(add_cron_api "${cron_line}:${cmd_task} ${filename}:${cron_name}:${SUB_ID}") echo -e "$result\n" notify_api "新增任务通知" "\n$result" # update_cron_api "$cron_line:$cmd_task $filename:$cron_name:$cron_id" @@ -423,9 +423,15 @@ gen_list_repo() { fi for file in ${files}; do + dirPath=$(dirname "$file") filename=$(basename "$file") - cp -f $file "$dir_scripts/${uniq_path}/${filename}" - echo "${uniq_path}/${filename}" >>"$dir_list_tmp/${uniq_path}_scripts.list" + filePath="${uniq_path}/${filename}" + if [[ $dirPath ]] && [[ $dirPath != '.' ]]; then + mkdir -p "${dir_scripts}/${uniq_path}/${dirPath}" + filePath="${uniq_path}/${dirPath}/${filename}" + fi + cp -f $file "${dir_scripts}/$filePath" + echo "$filePath" >>"$dir_list_tmp/${uniq_path}_scripts.list" # cron_id=$(cat $list_crontab_user | grep -E "$cmd_task.* ${uniq_path}_${filename}" | perl -pe "s|.*ID=(.*) $cmd_task.* ${uniq_path}_${filename}\.*|\1|" | head -1 | awk -F " " '{print $1}') # if [[ $cron_id ]]; then # result=$(update_cron_command_api "$cmd_task ${uniq_path}/${filename}:$cron_id")