This commit is contained in:
anonymous 2021-04-07 20:42:19 +08:00
parent 7412c70358
commit 77a3c5f905
4 changed files with 103 additions and 74 deletions

View File

@ -6,20 +6,20 @@
## 临时屏蔽某个Cookie
## 多个Cookie编号以半角的空格分隔两侧一对半角双引号使用此功能后在运行js脚本时账户编号将发生变化
## 多个Cookie编号以半角的空格分隔两侧一对半角双引号使用此功能后在运行脚本时账户编号将发生变化
## 举例1TempBlockCookie="2" 临时屏蔽掉Cookie2
## 举例2TempBlockCookie="2 4" 临时屏蔽掉Cookie2和Cookie4
TempBlockCookie=""
## 如果只是想要屏蔽某个账号不跑某一些脚本,可以参考下面 case 这个命令的例子来控制case的条件中请输入脚本的绝对路径也就是在crontab.list中的脚本路径是什么,这里就填入什么
## 如果只是想要屏蔽某个账号不跑某一些脚本,可以参考下面 case 这个命令的例子来控制case的条件中请输入脚本从scripts目录出发的相对路径也就是在crontab.list中的task命令后面的脚本路径是什么,这里就填入什么
## case $1 in
## /ql/scripts/lxk0301_jd_scripts/jd_fruit.js)
## lxk0301_jd_scripts/jd_fruit.js)
## TempBlockCookie="5" # 账号5不玩lxk0301_jd_scripts下的jd_fruit.js
## ;;
## /ql/scripts/lxk0301_jd_scripts/jd_dreamFactory.js | /ql/scripts/whyour_hundun/quanx/didi.js)
## lxk0301_jd_scripts/jd_dreamFactory.js | whyour_hundun/quanx/didi.js)
## TempBlockCookie="2" # 账号2不玩lxk0301_jd_scripts下的jd_dreamFactory.js和whyour_hundun下子文件夹quanx中的didi.js
## ;;
## /ql/scripts/lxk0301_jd_scripts/jd_jdzz.js | /ql/scripts/whyour_hundun/quanx/jx_factory.js)
## lxk0301_jd_scripts/jd_jdzz.js | whyour_hundun/quanx/jx_factory.js)
## TempBlockCookie="3 6" # 账号3、账号6不玩lxk0301_jd_scripts下的jd_jdzz.js和whyour_hundun下子文件夹quanx中的jx_factory.js
## ;;
## esac
@ -50,21 +50,21 @@ EnableExtraShell=""
## 启用其他开发者的仓库方式一(选填):完整更新整个仓库,针对同一个仓库,方式一和方式二只能选择一种
## OwnRepoUrl仓库地址清单必须从1开始依次编号
## OwnRepoBranch你想使用的分支清单不指定分支即使用默认分支时可以用一对不包含内容的空引号"",编号必须和 OwnRepoUrl 对应。
## OwnRepoPath要使用的脚本在仓库哪个路径下请输入仓库下的相对路径默认空值""代表仓库根目录,编号必须和 OwnRepoUrl 对应同一个仓库下不同文件夹之间使用空格分开。如果既包括根目录又包括子目录填写请见示例中OwnRepoPath3。
## RepoUrl仓库地址清单必须从1开始依次编号
## RepoBranch你想使用的分支清单不指定分支即使用默认分支时可以用一对不包含内容的空引号"",编号必须和 OwnRepoUrl 对应。
## RepoPath要使用的脚本在仓库哪个路径下请输入仓库下的相对路径默认空值""代表仓库根目录,编号必须和 OwnRepoUrl 对应同一个仓库下不同文件夹之间使用空格分开。如果既包括根目录又包括子目录填写请见示例中OwnRepoPath3。
## 所有脚本存放在 own 目录下,三个清单必须一一对应,示例如下:
## OwnRepoUrl1="https://gitee.com/abc/jdtsa.git"
## OwnRepoUrl2="https://github.com/nedcd/jxddfsa.git"
## OwnRepoUrl3="git@github.com:eject/poex.git"
## RepoUrl1="https://gitee.com/abc/jdtsa.git"
## RepoUrl2="https://github.com/nedcd/jxddfsa.git"
## RepoUrl3="git@github.com:eject/poex.git"
##
## OwnRepoBranch1="" # 代表第1个仓库 https://gitee.com/abc/jdtsa.git 使用 "默认" 分支
## OwnRepoBranch2="main" # 代表第2个仓库 https://github.com/nedcd/jxddfsa.git 使用 "main" 分支
## OwnRepoBranch3="master" # 代表第3个仓库 git@github.com:eject/poex.git 使用 "master" 分支
## RepoBranch1="" # 代表第1个仓库 https://gitee.com/abc/jdtsa.git 使用 "默认" 分支
## RepoBranch2="main" # 代表第2个仓库 https://github.com/nedcd/jxddfsa.git 使用 "main" 分支
## RepoBranch3="master" # 代表第3个仓库 git@github.com:eject/poex.git 使用 "master" 分支
##
## OwnRepoPath1="" # 代表第1个仓库https://gitee.com/abc/jdtsa.git你想使用的脚本就在仓库根目录下。
## OwnRepoPath2="scripts/jd normal" # 代表第2个仓库https://github.com/nedcd/jxddfsa.git你想使用的脚本在仓库的 scripts/jd 和 normal文件夹下必须输入相对路径
## OwnRepoPath3="'' cron" # 代表第3个仓库git@github.com:eject/poex.git你想使用的脚本在仓库的 根目录 和 cron 文件夹下,必须输入相对路径
## RepoPath1="" # 代表第1个仓库https://gitee.com/abc/jdtsa.git你想使用的脚本就在仓库根目录下。
## RepoPath2="scripts/jd normal" # 代表第2个仓库https://github.com/nedcd/jxddfsa.git你想使用的脚本在仓库的 scripts/jd 和 normal文件夹下必须输入相对路径
## RepoPath3="'' cron" # 代表第3个仓库git@github.com:eject/poex.git你想使用的脚本在仓库的 根目录 和 cron 文件夹下,必须输入相对路径
RepoUrl1=""
RepoUrl2=""
@ -78,11 +78,11 @@ RepoPath2=""
## 启用其他开发者的仓库方式二(选填):只下载想要的文件,针对同一个仓库,方式一和方式二只能选择一种。
## 请先确认你能正常下载该raw文件才列在下方无论是github还是gitee请只填入 raw 文件链接。
## 一行一个文件下载链接,首尾一对半角括号,示例:
## OwnRawFile=(
## RawUrl=(
## https://gitee.com/wabdwdd/scipts/raw/master/jd_abc.js
## https://github.com/lonfeg/loon/raw/main/jd_dudi.js
## https://github.com/sunsem/qx/raw/main/z_dida.js
## )
RawFile=(
RawUrl=(
)

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash
get_token() {
local authInfo=$(cat $AuthConf)
token=$(get_json_value "$authInfo" "token")
local auth_info=$(cat $file_auth_user)
token=$(get_json_value "$auth_info" "token")
}
get_json_value() {

View File

@ -91,7 +91,7 @@ gen_array_scripts () {
## 使用说明
usage () {
define_cmd
echo -e "\ntask命令运行本程序自动添加进crontab的脚本需要输入脚本的绝对路径或相对路径定时任务中必须是对路径),用法为:"
echo -e "\ntask命令运行本程序自动添加进crontab的脚本需要输入脚本的绝对路径或相对路径定时任务中必须是从scripts目录出发的相对路径),用法为:"
echo -e "1.$cmd_task <js_path> # 依次执行如果设置了随机延迟并且当时时间不在0-2、30-31、59分内将随机延迟一定秒数"
echo -e "2.$cmd_task <js_path> now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中"
echo -e "3.$cmd_task <js_path> conc # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中"
@ -111,6 +111,7 @@ run_nohup () {
## 正常运行单个脚本,$1传入参数
run_normal () {
local p1=$1
cd $dir_scripts
if [ -f $p1 ]; then
import_config_and_check "$p1"
update_crontab
@ -123,7 +124,7 @@ run_normal () {
make_dir "$dir_log/$p1"
$which_program $p1 2>&1 | tee $log_path
else
echo -e "\n $p1 脚本不存在,请确认...\n"
echo -e "\n $dir_scripts/$p1 脚本不存在,请确认...\n"
usage
fi
}
@ -132,6 +133,7 @@ run_normal () {
## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行
run_concurrent () {
local p1=$1
cd $dir_scripts
if [ -f $p1 ]; then
import_config_and_check "$p1"
update_crontab
@ -149,7 +151,7 @@ run_concurrent () {
$which_program $p1 &>$log_path &
done
else
echo -e "\n $p 脚本不存在,请确认...\n"
echo -e "\n $dir_scripts/$p1 脚本不存在,请确认...\n"
usage
fi
}

View File

@ -16,6 +16,7 @@ link_shell
define_cmd
fix_config
import_config_no_check "update"
get_token
## 克隆脚本,$1仓库地址$2仓库保存路径$3分支可省略
git_clone_scripts () {
@ -28,17 +29,15 @@ git_clone_scripts () {
exit_status=$?
}
## 更新脚本,$1仓库保存路径$2分支可省略
## 更新脚本,$1仓库保存路径
git_pull_scripts () {
local dir_current=$(pwd)
local dir_work=$1
local cmd_branch
[[ $2 ]] && cmd_branch="origin/$branch" || cmd_branch=""
cd $dir_work
echo -e "开始更新仓库:$dir_work\n"
git fetch --all
exit_status=$?
git reset --hard $cmd_branch
git reset --hard
git pull
cd $dir_current
}
@ -63,7 +62,7 @@ gen_list_own () {
done
fi
done
grep -E "$cmd_task " $list_crontab_user | perl -pe "s|.*$cmd_task ([^\s]+)( .+\|$)|\1|" | sort -u > $list_own_user
grep -E "$cmd_task " $list_crontab_user | perl -pe "s|.* $cmd_task ([^\s]+)( .+\|$)|\1|" | sort -u > $list_own_user
cd $dir_current
}
@ -153,20 +152,24 @@ npm_install_2 () {
cd $dir_current
}
## 比对两个文件,$1比$2新时将$1复制为$2
diff_and_copy () {
local copy_source=$1
local copy_to=$2
if [ ! -s $copy_to ] || [[ $(diff $copy_source $copy_to) ]]; then
cp $copy_source $copy_to
fi
}
## 更新依赖
update_depend () {
diff_and_copy "$dir_sample/package.json" "$dir_scripts/package.json"
if [ ! -s $dir_scripts/package.json ] || [[ $(diff $dir_sample/package.json $dir_scripts/package.json) ]]; then
cp -f $dir_sample/package.json $dir_scripts/package.json
npm_install_2 $dir_scripts
fi
if [ ! -s $dir_scripts/sendNotify.js ] || [[ $(diff $dir_sample/sendNotify.js $dir_scripts/sendNotify.js) ]]; then
cp -f $dir_sample/sendNotify.js $dir_scripts/sendNotify.js
fi
if [ ! -s $dir_scripts/jdCookie.js ] || [[ $(diff $dir_sample/jdCookie.js $dir_scripts/jdCookie.js) ]]; then
cp -f $dir_sample/jdCookie.js $dir_scripts/jdCookie.js
fi
diff_and_copy "$dir_sample/sendNotify.js" "$dir_scripts/sendNotify.js"
diff_and_copy "$dir_sample/jdCookie.js" "$dir_scripts/jdCookie.js"
}
## 输出是否有新的或失效的定时任务,$1新的或失效的任务清单文件路径$2新/失效
@ -209,19 +212,20 @@ add_cron () {
if [ -s $list_crontab_user ]; then
echo -e "开始尝试自动添加定时任务...\n"
local detail=$(cat $list_add)
for file_full_path in $detail; do
local file_name=$(echo $file_full_path | awk -F "/" '{print $NF}')
if [ -f $file_full_path ]; then
cd $dir_scripts
for file_relative_path in $detail; do
local file_name=$(echo $file_relative_path | awk -F "/" '{print $NF}')
if [ -f $file_relative_path ]; then
cron_line=$(
perl -ne "{
print if /.*([\d\*]*[\*-\/,\d]*[\d\*] ){4}[\d\*]*[\*-\/,\d]*[\d\*]( |,|\").*$file_name/
}" $file_full_path | \
}" $file_relative_path | \
perl -pe "{
s|[^\d\*]*(([\d\*]*[\*-\/,\d]*[\d\*] ){4}[\d\*]*[\*-\/,\d]*[\d\*])( \|,\|\").*/?$file_name.*|\1:$cmd_task $file_full_path|g;
s|[^\d\*]*(([\d\*]*[\*-\/,\d]*[\d\*] ){4}[\d\*]*[\*-\/,\d]*[\d\*])( \|,\|\").*/?$file_name.*|\1:$cmd_task $file_relative_path|g;
s| | |g
}" | sort -u | head -1
)
cron_name=$(grep "new Env" $file_full_path | awk -F "'|\"" '{print $2}' | head -1)
cron_name=$(grep "new Env" $file_relative_path | awk -F "'|\"" '{print $2}' | head -1)
[[ -z $cron_name ]] && cron_name="$file_name"
add_cron_api "$cron_line:$cron_name"
fi
@ -251,13 +255,22 @@ update_own_repo () {
else
git_clone_scripts ${array_own_repo_url[i]} ${array_own_repo_path[i]} ${array_own_repo_branch[i]}
fi
[[ $exit_status -eq 0 ]] && echo -e "\n更新${array_own_repo_path[i]}成功...\n" || echo -e "\n更新${array_own_repo_path[i]}失败,请检查原因...\n"
if [[ $exit_status -eq 0 ]]; then
echo -e "\n更新${array_own_repo_path[i]}成功...\n"
diff_and_copy "$dir_sample/sendNotify.js" "${array_own_repo_path[i]}/sendNotify.js"
diff_and_copy "$dir_sample/jdCookie.js" "${array_own_repo_path[i]}/jdCookie.js"
else
echo -e "\n更新${array_own_repo_path[i]}失败,请检查原因...\n"
fi
done
}
## 更新所有 raw 文件
update_own_raw () {
[[ ${#RawUrl[*]} -gt 0 ]] && echo -e "--------------------------------------------------------------\n"
if [[ ${#RawUrl[*]} -gt 0 ]]; then
echo -e "--------------------------------------------------------------\n"
make_dir $dir_raw
fi
for ((i=0; i<${#RawUrl[*]}; i++)); do
raw_file_name[$i]=$(echo ${RawUrl[i]} | awk -F "/" '{print $NF}')
echo -e "开始下载:${RawUrl[i]} \n\n保存路径$dir_raw/${raw_file_name[$i]}\n"
@ -288,13 +301,16 @@ run_extra_shell () {
## 脚本用法
usage () {
echo -e "本脚本用法:"
echo -e "1. $cmd_update # 更新qinglong、所有你设置的仓库和raw文件如果启用了EnableExtraShell还将在最后运行你自己编写的extra.sh"
echo -e "1. $cmd_update all # 更新qinglong、所有你设置的仓库和raw文件如果启用了EnableExtraShell还将在最后运行你自己编写的extra.sh"
echo -e "2. $cmd_update ql # 只更新qinglong和输入 $cmd_update qinglong 时功能一样不会运行extra.sh"
echo -e "3. $cmd_update <folder> # 指定scripts脚本目录下某个文件夹名称只更新这个文件夹中的脚本当该文件夹为git仓库才可使用此命令不会运行extra.sh"
echo -e "3. $cmd_update raw # 只更新raw文件不会运行extra.sh"
echo -e "4. $cmd_update repo # 更新所有设置的REPO不会运行extra.sh"
echo -e "5. $cmd_update <folder> # 指定scripts脚本目录下某个文件夹名称只更新这个文件夹中的脚本当该文件夹已经存在并且是git仓库才可使用此命令不会运行extra.sh"
}
## 更新qinglong
update_qinglong () {
echo -e "--------------------------------------------------------------\n"
git_pull_scripts $dir_root
if [[ $exit_status -eq 0 ]]; then
echo -e "\n更新$dir_root成功...\n"
@ -313,7 +329,6 @@ update_all_scripts () {
count_own_repo_sum
gen_own_dir_and_path
if [[ ${#array_own_scripts_path[*]} -gt 0 ]]; then
make_dir $dir_raw
update_own_repo
update_own_raw
gen_list_own
@ -336,40 +351,52 @@ update_all_scripts () {
update_specify_scripts_repo () {
local tmp_dir=$1
if [ -d $dir_scripts/$tmp_dir ]; then
git_pull_scripts $dir_scripts/$tmp_dir
if [ -d $dir_scripts/$tmp_dir/.git ]; then
git_pull_scripts $dir_scripts/$tmp_dir
else
echo -e "$dir_scripts/$tmp_dir 不是一个git仓库...\n"
fi
else
echo -e "$dir_scripts/$tmp_dir 不存在...\n"
echo -e "命令输入错误...\n"
usage
fi
}
main () {
local p1=$1
log_time=$(date "+%Y-%m-%d-%H-%M-%S")
log_path="$dir_log/update/${log_time}.log"
log_path="$dir_log/update/${log_time}_$p1.log"
make_dir "$dir_log/update"
case $# in
0)
update_qinglong | tee $log_path
update_all_scripts | tee -a $log_path
run_extra_shell | tee -a $log_path
exit 0
;;
1)
case $1 in
ql | qinglong)
update_qinglong | tee $log_path
;;
*)
update_specify_scripts_repo | tee $log_path
;;
esac
exit 0
;;
*)
usage
exit 0
;;
esac
if [[ $# -ne 1 ]]; then
echo -e "命令输入错误...\n"
usage
else
case $p1 in
all)
update_qinglong | tee $log_path
update_all_scripts | tee -a $log_path
run_extra_shell | tee -a $log_path
;;
ql | qinglong)
update_qinglong | tee $log_path
;;
repo)
count_own_repo_sum
gen_own_dir_and_path
update_own_repo | tee $log_path
;;
raw)
count_own_repo_sum
gen_own_dir_and_path
update_own_raw | tee $log_path
;;
*)
update_specify_scripts_repo "$p1" | tee $log_path
;;
esac
fi
}
main "$@"
exit 0