mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-27 14:46:06 +08:00
测试shell
This commit is contained in:
parent
e5e8c45e8b
commit
7c15a074e0
|
@ -31,7 +31,6 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
|||
&& cd ${QL_DIR} \
|
||||
&& cp -f .env.example .env \
|
||||
&& ln -sf ${QL_DIR}/shell/task.sh /usr/local/bin/task \
|
||||
&& ln -sf ${QL_DIR}/shell/task.sh /usr/local/bin/mytask \
|
||||
&& ln -sf ${QL_DIR}/shell/update.sh /usr/local/bin/update \
|
||||
&& ln -sf ${QL_DIR}/shell/rmlog.sh /usr/local/bin/rmlog \
|
||||
&& ln -sf ${QL_DIR}/shell/notify.sh /usr/local/bin/notify \
|
||||
|
|
|
@ -11,15 +11,6 @@ echo -e "======================2. 检测配置文件========================\n"
|
|||
[ ! -d ${QL_DIR}/db ] && mkdir -p ${QL_DIR}/db
|
||||
[ ! -d ${QL_DIR}/manual_log ] && mkdir -p ${QL_DIR}/manual_log
|
||||
|
||||
if [ ! -s ${QL_DIR}/config/crontab.list ]
|
||||
then
|
||||
echo -e "检测到config配置目录下不存在crontab.list或存在但文件为空,从示例文件复制一份用于初始化...\n"
|
||||
cp -fv ${QL_DIR}/sample/crontab.sample.list ${QL_DIR}/config/crontab.list
|
||||
perl -i -pe "{s|CMD_UPDATE|update|g; s|CMD_REBUILD|rebuild|g; s|CMD_RMLOG|rmlog|g; s|CMD_TASK|task|g; s|CMD_MYTASK|mytask|g}" ${QL_DIR}/config/crontab.list
|
||||
fi
|
||||
crontab ${QL_DIR}/config/crontab.list
|
||||
echo -e "成功添加定时任务...\n"
|
||||
|
||||
if [ ! -s ${QL_DIR}/config/cookie.sh ]; then
|
||||
echo -e "检测到config配置目录下不存在cookie.sh,从示例文件复制一份用于初始化...\n"
|
||||
touch ${QL_DIR}/config/cookie.sh
|
||||
|
|
1
gossh520_jd_scripts
Submodule
1
gossh520_jd_scripts
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 85da52dc3fb5ede1c7cd70a2d3af62e37c18e341
|
|
@ -37,7 +37,7 @@ AutoAddCron="true"
|
|||
RmLogDaysAgo="7"
|
||||
|
||||
|
||||
## 在运行 task 或 mytask 命令时,随机延迟启动任务的最大延迟时间
|
||||
## 在运行 task 命令时,随机延迟启动任务的最大延迟时间
|
||||
## 如果任务不是必须准点运行的任务,那么给它增加一个随机延迟,由你定义最大延迟时间,单位为秒,如 RandomDelay="300" ,表示任务将在 1-300 秒内随机延迟一个秒数,然后再运行
|
||||
## 在crontab.list中,在每小时第0-2分、第30-31分、第59分这几个时间内启动的任务,均算作必须准点运行的任务,在启动这些任务时,即使你定义了RandomDelay,也将准点运行,不启用随机延迟
|
||||
## 在crontab.list中,除掉每小时上述时间启动的任务外,其他任务在你定义了 RandomDelay 的情况下,一律启用随机延迟,但如果你给某些任务添加了 "now" 或者 "conc",那么这些任务也将无视随机延迟直接启动
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
# 更新所有脚本
|
||||
55 2,13 * * * CMD_UPDATE all
|
||||
|
||||
# 重构面板
|
||||
# 30 7 */7 * * CMD_REBUILD >> ${QL_DIR}/log/rebuild.log 2>&1
|
||||
|
||||
# 删除 RmLogDaysAgo 指定天数以前的旧日志,不记录日志
|
||||
57 13 * * * CMD_RMLOG >/dev/null 2>&1
|
||||
|
||||
# 其他定时任务,由本程序自动添加的任务使用 CMD_TASK 命令,由你自行添加的任务请使用 CMD_MYTASK 命令
|
||||
# 如果由本程序自动添加的任务你不想运行,注释即可,不要删除,请在最后保留一个空行
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
此文件为Node.js专用。其他用户请忽略
|
||||
*/
|
||||
//此处填写京东账号cookie。
|
||||
let CookieJDs = [
|
||||
'',//账号一ck,例:pt_key=XXX;pt_pin=XXX;
|
||||
'',//账号二ck,例:pt_key=XXX;pt_pin=XXX;如有更多,依次类推
|
||||
]
|
||||
// 判断环境变量里面是否有京东ck
|
||||
if (process.env.JD_COOKIE) {
|
||||
if (process.env.JD_COOKIE.indexOf('&') > -1) {
|
||||
CookieJDs = process.env.JD_COOKIE.split('&');
|
||||
} else if (process.env.JD_COOKIE.indexOf('\n') > -1) {
|
||||
CookieJDs = process.env.JD_COOKIE.split('\n');
|
||||
} else {
|
||||
CookieJDs = [process.env.JD_COOKIE];
|
||||
}
|
||||
}
|
||||
if (JSON.stringify(process.env).indexOf('GITHUB')>-1) {
|
||||
console.log(`请勿使用github action运行此脚本,无论你是从你自己的私库还是其他哪里拉取的源代码,都会导致我被封号\n`);
|
||||
!(async () => {
|
||||
await require('./sendNotify').sendNotify('提醒', `请勿使用github action、滥用github资源会封我仓库以及账号`)
|
||||
await process.exit(0);
|
||||
})()
|
||||
}
|
||||
CookieJDs = [...new Set(CookieJDs.filter(item => !!item))]
|
||||
console.log(`\n====================共${CookieJDs.length}个京东账号Cookie=========\n`);
|
||||
console.log(`==================脚本执行- 北京时间(UTC+8):${new Date(new Date().getTime() + new Date().getTimezoneOffset()*60*1000 + 8*60*60*1000).toLocaleString()}=====================\n`)
|
||||
if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => {};
|
||||
for (let i = 0; i < CookieJDs.length; i++) {
|
||||
if (!CookieJDs[i].match(/pt_pin=(.+?);/) || !CookieJDs[i].match(/pt_key=(.+?);/)) console.log(`\n提示:京东cookie 【${CookieJDs[i]}】填写不规范,可能会影响部分脚本正常使用。正确格式为: pt_key=xxx;pt_pin=xxx;(分号;不可少)\n`);
|
||||
const index = (i + 1 === 1) ? '' : (i + 1);
|
||||
exports['CookieJD' + index] = CookieJDs[i].trim();
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
{
|
||||
"name": "lxk0301",
|
||||
"version": "1.0.0",
|
||||
"description": "{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}",
|
||||
"main": "AlipayManor.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/lxk0301/jd_scripts.git"
|
||||
},
|
||||
"keywords": [
|
||||
""
|
||||
],
|
||||
"author": "LXK9301",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"crypto-js": "^4.0.0",
|
||||
"download": "^8.0.0",
|
||||
"got": "^11.5.1",
|
||||
"http-server": "^0.12.3",
|
||||
"qrcode-terminal": "^0.12.0",
|
||||
"request": "^2.88.2",
|
||||
"tough-cookie": "^4.0.0",
|
||||
"tunnel": "0.0.6",
|
||||
"ws": "^7.4.3"
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
0
shell/api.sh
Normal file → Executable file
0
shell/api.sh
Normal file → Executable file
|
@ -1 +0,0 @@
|
|||
task.sh
|
|
@ -1,4 +1,4 @@
|
|||
const notify = require('../scripts/sendNotify.js');
|
||||
const notify = require('/ql/scripts/sendNotify.js');
|
||||
const title = process.argv[2];
|
||||
const content = process.argv[3];
|
||||
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
dir_shell=$(dirname $(readlink -f "$0"))
|
||||
dir_root=$(cd $dir_shell; cd ..; pwd)
|
||||
|
||||
echo -e "更新qinglong...\n"
|
||||
cd $dir_root
|
||||
git fetch --all
|
||||
git pull
|
||||
echo -e "更新更新qinglong完成...\n"
|
||||
|
||||
echo -e "重新build...\n"
|
||||
yarn install --network-timeout 1000000000 || yarn install --registry=https://registry.npm.taobao.org --network-timeout 1000000000
|
||||
yarn build
|
||||
yarn build-back
|
||||
yarn cache clean
|
||||
echo -e "重新build完成...\n"
|
||||
|
||||
echo -e "重启服务...\n"
|
||||
pm2 restart panel 2>/dev/null || pm2 start $dir_root/build/app.js -n panel
|
||||
nginx -s reload
|
||||
|
||||
echo -e "重启服务完成...\n"
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
## 判断环境
|
||||
dir_shell=$(dirname $(readlink -f "$0"))
|
||||
dir_root=$(cd $dir_shell; cd ..; pwd)
|
||||
dir_root=$(cd $dir_shell; pwd)
|
||||
|
||||
## 导入通用变量与函数
|
||||
. $dir_shell/share.sh
|
||||
|
|
67
shell/share.sh
Normal file → Executable file
67
shell/share.sh
Normal file → Executable file
|
@ -2,6 +2,7 @@
|
|||
dir_sample=$dir_root/sample
|
||||
dir_config=$dir_root/config
|
||||
dir_scripts=$dir_root/scripts
|
||||
dir_repo=$dir_root/repo
|
||||
dir_raw=$dir_scripts/raw
|
||||
dir_log=$dir_root/log
|
||||
dir_list_tmp=$dir_log/.tmp
|
||||
|
@ -34,13 +35,11 @@ var_name=(
|
|||
## 软连接及其原始文件对应关系
|
||||
link_name=(
|
||||
task
|
||||
mytask
|
||||
rmlog
|
||||
update
|
||||
rebuild
|
||||
)
|
||||
original_name=(
|
||||
task.sh
|
||||
task.sh
|
||||
rmlog.sh
|
||||
update.sh
|
||||
|
@ -69,15 +68,6 @@ import_config_and_check () {
|
|||
fi
|
||||
}
|
||||
|
||||
## 发送通知,依赖于import_config_and_check或import_config_no_check,$1:标题,$2:内容
|
||||
notify () {
|
||||
local title=$(echo $1 | perl -pe 's|-|_|g')
|
||||
local msg="$(echo -e $2)"
|
||||
if [ -d $dir_scripts_node_modules ]; then
|
||||
node $dir_shell/notify.js "$title" "$msg"
|
||||
fi
|
||||
}
|
||||
|
||||
## 创建目录,$1:目录的绝对路径
|
||||
make_dir () {
|
||||
local dir=$1
|
||||
|
@ -154,52 +144,6 @@ define_cmd () {
|
|||
done
|
||||
}
|
||||
|
||||
## 统计 own 仓库数量
|
||||
count_own_repo_sum () {
|
||||
own_repo_sum=0
|
||||
for ((i=1; i<=1000; i++)); do
|
||||
local tmp1=RepoUrl$i
|
||||
local tmp2=${!tmp1}
|
||||
[[ $tmp2 ]] && own_repo_sum=$i || break
|
||||
done
|
||||
}
|
||||
|
||||
## 形成 own 仓库的文件夹名清单,依赖于import_config_and_check或import_config_no_check
|
||||
## array_own_repo_path:repo存放的绝对路径组成的数组;array_own_scripts_path:所有要使用的脚本所在的绝对路径组成的数组
|
||||
gen_own_dir_and_path () {
|
||||
local scripts_path_num="-1"
|
||||
local repo_num tmp1 tmp2 tmp3 tmp4 tmp5 dir
|
||||
|
||||
if [[ $own_repo_sum -ge 1 ]]; then
|
||||
for ((i=1; i<=$own_repo_sum; i++)); do
|
||||
repo_num=$((i - 1))
|
||||
tmp1=RepoUrl$i
|
||||
array_own_repo_url[$repo_num]=${!tmp1}
|
||||
tmp2=RepoBranch$i
|
||||
array_own_repo_branch[$repo_num]=${!tmp2}
|
||||
array_own_repo_dir[$repo_num]=$(echo ${array_own_repo_url[$repo_num]} | perl -pe "s|\.git||" | awk -F "/|:" '{print $((NF - 1)) "_" $NF}')
|
||||
array_own_repo_path[$repo_num]=$dir_scripts/${array_own_repo_dir[$repo_num]}
|
||||
tmp3=RepoPath$i
|
||||
if [[ ${!tmp3} ]]; then
|
||||
for dir in ${!tmp3}; do
|
||||
let scripts_path_num++
|
||||
tmp4="${array_own_repo_dir[repo_num]}/$dir"
|
||||
tmp5=$(echo $tmp4 | perl -pe "{s|//|/|g; s|/$||}") # 去掉多余的/
|
||||
array_own_scripts_path[$scripts_path_num]="$dir_scripts/$tmp5"
|
||||
done
|
||||
else
|
||||
let scripts_path_num++
|
||||
array_own_scripts_path[$scripts_path_num]="${array_own_repo_path[$repo_num]}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ ${#RawUrl[*]} -ge 1 ]]; then
|
||||
let scripts_path_num++
|
||||
array_own_scripts_path[$scripts_path_num]=$dir_raw # 只有own脚本所在绝对路径附加了raw文件夹,其他数组均不附加
|
||||
fi
|
||||
}
|
||||
|
||||
## 修复配置文件
|
||||
fix_config () {
|
||||
make_dir $dir_config
|
||||
|
@ -208,16 +152,9 @@ fix_config () {
|
|||
cp -fv $file_config_sample $file_config_user
|
||||
echo
|
||||
fi
|
||||
if [ ! -s $list_crontab_user ]; then
|
||||
echo -e "复制一份 $list_crontab_sample 为 $list_crontab_user,这是你自己的 crontab.list\n"
|
||||
cp -fv $list_crontab_sample $list_crontab_user
|
||||
echo
|
||||
fi
|
||||
perl -i -pe "{
|
||||
s|CMD_UPDATE|$cmd_update|g;
|
||||
s|CMD_REBUILD|$cmd_rebuild|g;
|
||||
s|CMD_RMLOG|$cmd_rmlog|g;
|
||||
s|CMD_TASK|$cmd_task|g;
|
||||
s|CMD_MYTASK|$cmd_mytask|g
|
||||
s|CMD_TASK|$cmd_task|g
|
||||
}" $list_crontab_user
|
||||
}
|
||||
|
|
23
shell/task.sh
Normal file → Executable file
23
shell/task.sh
Normal file → Executable file
|
@ -2,18 +2,11 @@
|
|||
|
||||
## 路径
|
||||
dir_shell=$(dirname $(readlink -f "$0"))
|
||||
dir_root=$(cd $dir_shell; cd ..; pwd)
|
||||
dir_root=$(cd $dir_shell; pwd)
|
||||
|
||||
## 导入通用变量与函数
|
||||
. $dir_shell/share.sh
|
||||
|
||||
## 更新crontab
|
||||
update_crontab () {
|
||||
if [[ $(cat $list_crontab_user) != $(crontab -l) ]]; then
|
||||
crontab $list_crontab_user
|
||||
fi
|
||||
}
|
||||
|
||||
## 组合Cookie和互助码子程序,$1:要组合的内容
|
||||
combine_sub () {
|
||||
local what_combine=$1
|
||||
|
@ -68,21 +61,17 @@ random_delay () {
|
|||
## scripts目录下所有可运行脚本数组
|
||||
gen_array_scripts () {
|
||||
import_config_no_check
|
||||
count_own_repo_sum
|
||||
gen_own_dir_and_path
|
||||
local dir_current=$(pwd)
|
||||
local i="-1"
|
||||
for ((scripts_path_num=0; scripts_path_num<${#array_own_scripts_path[*]}; scripts_path_num++)); do
|
||||
cd ${array_own_scripts_path[$scripts_path_num]}
|
||||
cd $dir_scripts
|
||||
for file in $(ls); do
|
||||
if [ -f $file ] && [[ $(grep "new Env" $file) ]] && [[ $file == *.js && $file != sendNotify.js && $file != JD_extra_cookie.js ]]; then
|
||||
if [ -f $file ] && [[ $file == *.js && $file != sendNotify.js && $file != JD_extra_cookie.js ]]; then
|
||||
let i++
|
||||
array_scripts[i]=$(echo "${array_own_scripts_path[$scripts_path_num]}/$file" | perl -pe "s|$dir_scripts/||g")
|
||||
array_scripts[i]=$(echo "$file" | perl -pe "s|$dir_scripts/||g")
|
||||
array_scripts_name[i]=$(grep "new Env" $file | awk -F "'|\"" '{print $2}' | head -1)
|
||||
[[ -z ${array_scripts_name[i]} ]] && array_scripts_name[i]="<未识别出活动名称>"
|
||||
fi
|
||||
done
|
||||
done
|
||||
cd $dir_current
|
||||
}
|
||||
|
||||
|
@ -113,7 +102,6 @@ run_normal () {
|
|||
cd $dir_scripts
|
||||
if [ -f $p1 ]; then
|
||||
import_config_and_check "$p1"
|
||||
update_crontab
|
||||
define_program "$p1"
|
||||
combine_all
|
||||
[[ $# -eq 1 ]] && random_delay
|
||||
|
@ -122,7 +110,6 @@ run_normal () {
|
|||
make_dir "$dir_log/$p1"
|
||||
$which_program $p1 2>&1 | tee $log_path
|
||||
else
|
||||
update_crontab
|
||||
echo -e "\n $p1 脚本不存在,请确认...\n"
|
||||
usage
|
||||
fi
|
||||
|
@ -135,7 +122,6 @@ run_concurrent () {
|
|||
cd $dir_scripts
|
||||
if [ -f $p1 ]; then
|
||||
import_config_and_check "$p1"
|
||||
update_crontab
|
||||
define_program
|
||||
make_dir $dir_log/$p1
|
||||
log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")
|
||||
|
@ -149,7 +135,6 @@ run_concurrent () {
|
|||
$which_program $p1 &>$log_path &
|
||||
done
|
||||
else
|
||||
update_crontab
|
||||
echo -e "\n $p1 脚本不存在,请确认...\n"
|
||||
usage
|
||||
fi
|
||||
|
|
203
shell/update.sh
Normal file → Executable file
203
shell/update.sh
Normal file → Executable file
|
@ -1,13 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
## 文件路径、脚本网址
|
||||
dir_shell=$(dirname $(readlink -f "$0"))
|
||||
dir_root=$(cd $dir_shell; cd ..; pwd)
|
||||
# dir_shell=$(dirname $(readlink -f "$0"))
|
||||
# dir_root=$(
|
||||
# cd $dir_shell
|
||||
# cd ..
|
||||
# pwd
|
||||
# )
|
||||
dir_shell=$(pwd)
|
||||
dir_root=$(
|
||||
cd $dir_shell
|
||||
pwd
|
||||
)
|
||||
send_mark=$dir_shell/send_mark
|
||||
|
||||
## 导入通用变量与函数
|
||||
. $dir_shell/share.sh
|
||||
. $dir_shell/api.sh
|
||||
# 导入通用变量与函数
|
||||
# . $dir_shell/share.sh
|
||||
# . $dir_shell/api.sh
|
||||
. ./shell/share.sh
|
||||
. ./shell/api.sh
|
||||
|
||||
## 导入配置文件,检测平台,创建软连接,识别命令,修复配置文件
|
||||
detect_termux
|
||||
|
@ -56,30 +67,6 @@ git_pull_scripts () {
|
|||
cd $dir_current
|
||||
}
|
||||
|
||||
## 生成脚本的路径清单文件
|
||||
gen_list_own () {
|
||||
local dir_current=$(pwd)
|
||||
rm -f $dir_list_tmp/own*.list >/dev/null 2>&1
|
||||
for ((i=0; i<${#array_own_scripts_path[*]}; i++)); do
|
||||
cd ${array_own_scripts_path[i]}
|
||||
if [[ $(ls *.js 2>/dev/null) ]]; then
|
||||
for file in $(ls *.js); do
|
||||
if [ -f $file ]; then
|
||||
perl -ne "{
|
||||
print if /.*([\d\*]*[\*-\/,\d]*[\d\*] ){4}[\d\*]*[\*-\/,\d]*[\d\*]( |,|\").*\/?$file/
|
||||
}" $file | \
|
||||
perl -pe "{
|
||||
s|.*(([\d\*]*[\*-\/,\d]*[\d\*] ){4}[\d\*]*[\*-\/,\d]*[\d\*])( \|,\|\").*/?$file.*|${array_own_scripts_path[i]}/$file|g;
|
||||
s|$dir_scripts/||
|
||||
}" | head -1 >> $list_own_scripts
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
grep -E "$cmd_task " $list_crontab_user | perl -pe "s|.* $cmd_task ([^\s]+)( .+\|$)|\1|" | sort -u > $list_own_user
|
||||
cd $dir_current
|
||||
}
|
||||
|
||||
## 检测cron的差异,$1:脚本清单文件路径,$2:cron任务清单文件路径,$3:增加任务清单文件路径,$4:删除任务清单文件路径
|
||||
diff_cron() {
|
||||
make_dir $dir_list_tmp
|
||||
|
@ -187,9 +174,6 @@ update_depend () {
|
|||
fi
|
||||
|
||||
[ ! -d $dir_scripts/node_modules ] && npm_install_2 $dir_scripts
|
||||
|
||||
diff_and_copy "$dir_sample/sendNotify.js" "$dir_scripts/sendNotify.js"
|
||||
diff_and_copy "$dir_sample/jdCookie.js" "$dir_scripts/jdCookie.js"
|
||||
}
|
||||
|
||||
## 输出是否有新的或失效的定时任务,$1:新的或失效的任务清单文件路径,$2:新/失效
|
||||
|
@ -212,7 +196,7 @@ del_cron () {
|
|||
detail=$(cat $list_drop)
|
||||
echo -e "开始尝试自动删除失效的定时任务...\n"
|
||||
for cron in $detail; do
|
||||
local id=$(cat $list_crontab_user | grep -E "$cmd_task $cron" | perl -pe "s|.*ID=(.*) $cmd_task $cron|\1|")
|
||||
local id=$(cat $list_crontab_user | grep -E "$cmd_task $cron$" | perl -pe "s|.*ID=(.*) $cmd_task $cron$|\1|")
|
||||
del_cron_api "$id"
|
||||
done
|
||||
detail2=$(echo $detail | perl -pe "s| |\\\n|g")
|
||||
|
@ -225,7 +209,6 @@ del_cron () {
|
|||
## $1:新任务清单文件路径
|
||||
add_cron() {
|
||||
local list_add=$1
|
||||
if [ -s $list_crontab_user ]; then
|
||||
echo -e "开始尝试自动添加定时任务...\n"
|
||||
local detail=$(cat $list_add)
|
||||
cd $dir_scripts
|
||||
|
@ -235,7 +218,7 @@ add_cron () {
|
|||
cron_line=$(
|
||||
perl -ne "{
|
||||
print if /.*([\d\*]*[\*-\/,\d]*[\d\*] ){4}[\d\*]*[\*-\/,\d]*[\d\*]( |,|\").*$file_name/
|
||||
}" $file_relative_path | \
|
||||
}" $file_relative_path |
|
||||
perl -pe "{
|
||||
s|[^\d\*]*(([\d\*]*[\*-\/,\d]*[\d\*] ){4}[\d\*]*[\*-\/,\d]*[\d\*])( \|,\|\").*/?$file_name.*|\1:$cmd_task $file_relative_path|g;
|
||||
s| | |g
|
||||
|
@ -249,47 +232,49 @@ add_cron () {
|
|||
exit_status=$?
|
||||
local detail2=$(echo $detail | perl -pe "s| |\\\n|g")
|
||||
if [[ $exit_status -eq 0 ]]; then
|
||||
crontab $list_crontab_user
|
||||
echo -e "成功添加新的定时任务...\n"
|
||||
notify "新增任务通知" "成功添加新的定时任务:\n$detail2"
|
||||
else
|
||||
echo -e "添加新的定时任务出错,请手动添加...\n"
|
||||
notify "新任务添加失败通知" "尝试自动添加以下新的定时任务出错,请手动添加:\n$detail2"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
## 更新所有仓库
|
||||
update_own_repo () {
|
||||
[[ ${#array_own_repo_url[*]} -gt 0 ]] && echo -e "--------------------------------------------------------------\n"
|
||||
for ((i=0; i<${#array_own_repo_url[*]}; i++)); do
|
||||
if [ -d ${array_own_repo_path[i]}/.git ]; then
|
||||
reset_romote_url ${array_own_repo_path[i]} ${array_own_repo_url[i]}
|
||||
git_pull_scripts ${array_own_repo_path[i]}
|
||||
## 更新仓库
|
||||
update_repo() {
|
||||
echo -e "--------------------------------------------------------------\n"
|
||||
local url="$1"
|
||||
local path="$2"
|
||||
local blackword="$3"
|
||||
local urlTmp="${url%*/}"
|
||||
local repoTmp="${urlTmp##*/}"
|
||||
local repo="${repoTmp%.*}"
|
||||
local tmp="${url%/*}"
|
||||
local authorTmp1="${tmp##*/}"
|
||||
local authorTmp2="${authorTmp1##*:}"
|
||||
local author="${authorTmp2##*.}"
|
||||
|
||||
local repo_path="${author}_${repo}"
|
||||
if [ -d ${repo_path}/.git ]; then
|
||||
reset_romote_url ${repo_path} ${url}
|
||||
git_pull_scripts ${repo_path}
|
||||
else
|
||||
git_clone_scripts ${array_own_repo_url[i]} ${array_own_repo_path[i]} ${array_own_repo_branch[i]}
|
||||
git_clone_scripts ${url} ${repo_path}
|
||||
fi
|
||||
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"
|
||||
echo -e "\n更新${repo_path}成功...\n"
|
||||
else
|
||||
echo -e "\n更新${array_own_repo_path[i]}失败,请检查原因...\n"
|
||||
echo -e "\n更新${repo_path}失败,请检查原因...\n"
|
||||
fi
|
||||
done
|
||||
for ((i=0; i<${#array_own_scripts_path[*]}; i++)); do
|
||||
diff_and_copy "$dir_sample/sendNotify.js" "${array_own_scripts_path[i]}/sendNotify.js"
|
||||
diff_and_copy "$dir_sample/jdCookie.js" "${array_own_scripts_path[i]}/jdCookie.js"
|
||||
done
|
||||
|
||||
diff_scripts $repo_path $author $path $blackword
|
||||
}
|
||||
|
||||
## 更新所有 raw 文件
|
||||
update_own_raw () {
|
||||
update_raw() {
|
||||
if [[ ${#RawUrl[*]} -gt 0 ]]; then
|
||||
echo -e "--------------------------------------------------------------\n"
|
||||
make_dir $dir_raw
|
||||
diff_and_copy "$dir_sample/sendNotify.js" "$dir_raw/sendNotify.js"
|
||||
diff_and_copy "$dir_sample/jdCookie.js" "$dir_raw/jdCookie.js"
|
||||
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"
|
||||
|
@ -309,8 +294,7 @@ update_own_raw () {
|
|||
## 调用用户自定义的extra.sh
|
||||
run_extra_shell() {
|
||||
if [[ ${EnableExtraShell} == true ]]; then
|
||||
if [ -f $file_extra_shell ]
|
||||
then
|
||||
if [ -f $file_extra_shell ]; then
|
||||
echo -e "--------------------------------------------------------------\n"
|
||||
. $file_extra_shell
|
||||
else
|
||||
|
@ -322,8 +306,8 @@ run_extra_shell () {
|
|||
## 脚本用法
|
||||
usage() {
|
||||
echo -e "本脚本用法:"
|
||||
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 "2. $cmd_update update # 只更新qinglong,不会运行extra.sh"
|
||||
echo -e "2. $cmd_update rebuild # 重新编译qinglong,不会运行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"
|
||||
|
@ -345,14 +329,28 @@ update_qinglong () {
|
|||
fi
|
||||
}
|
||||
|
||||
## 更新所有脚本
|
||||
update_all_scripts () {
|
||||
count_own_repo_sum
|
||||
gen_own_dir_and_path
|
||||
if [[ ${#array_own_scripts_path[*]} -gt 0 ]]; then
|
||||
update_own_repo
|
||||
update_own_raw
|
||||
gen_list_own
|
||||
## 重新编译qinglong
|
||||
rebuild_qinglong() {
|
||||
echo -e "--------------------------------------------------------------\n"
|
||||
update_qinglong
|
||||
if [[ $exit_status -eq 0 ]]; then
|
||||
echo -e "重新编译青龙...\n"
|
||||
yarn install --network-timeout 1000000000 || yarn install --registry=https://registry.npm.taobao.org --network-timeout 1000000000
|
||||
yarn build
|
||||
yarn build-back
|
||||
yarn cache clean
|
||||
echo -e "重新编译青龙完成...\n"
|
||||
|
||||
echo -e "重启青龙...\n"
|
||||
pm2 restart panel 2>/dev/null || pm2 start $dir_root/build/app.js -n panel
|
||||
nginx -s reload
|
||||
echo -e "重启青龙完成...\n"
|
||||
fi
|
||||
}
|
||||
|
||||
## 对比脚本
|
||||
diff_scripts() {
|
||||
gen_list_repo $1 $2 $3 $4
|
||||
diff_cron $list_own_scripts $list_own_user $list_own_add $list_own_drop
|
||||
|
||||
if [ -s $list_own_drop ]; then
|
||||
|
@ -365,57 +363,68 @@ update_all_scripts () {
|
|||
add_cron $list_own_add
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
## 更新指定仓库
|
||||
update_specify_scripts_repo () {
|
||||
local tmp_dir=$1
|
||||
if [ -d $dir_scripts/$tmp_dir ]; then
|
||||
if [ -d $dir_scripts/$tmp_dir/.git ]; then
|
||||
git_pull_scripts $dir_scripts/$tmp_dir
|
||||
else
|
||||
echo -e "$dir_scripts/$tmp_dir 不是一个git仓库...\n"
|
||||
## 生成脚本的路径清单文件
|
||||
gen_list_repo() {
|
||||
local dir_current=$(pwd)
|
||||
local repo_path="$1"
|
||||
local author="$2"
|
||||
local path="$3"
|
||||
local blackword="$4"
|
||||
# rm -f $dir_list_tmp/own*.list >/dev/null 2>&1
|
||||
|
||||
cd ${repo_path}
|
||||
files=$(find . -name "*.js")
|
||||
if [ $path ]; then
|
||||
files=$(find . -name "*.js" | egrep $path)
|
||||
fi
|
||||
else
|
||||
echo -e "$dir_scripts/$tmp_dir 还不存在,可能是还没有clone?\n"
|
||||
usage
|
||||
if [ $blackword ]; then
|
||||
files=$(find . -name "*.js" | egrep -v $blackword | egrep $path)
|
||||
fi
|
||||
for file in ${files}; do
|
||||
if [ -f $file ]; then
|
||||
# base=$(basename $file)
|
||||
# echo $base | head -1 >>$list_own_scripts
|
||||
perl -ne "{
|
||||
print if /.*([\d\*]*[\*-\/,\d]*[\d\*] ){4}[\d\*]*[\*-\/,\d]*[\d\*]( |,|\").*\/?$file/
|
||||
}" $file | perl -pe "{
|
||||
s|.*(([\d\*]*[\*-\/,\d]*[\d\*] ){4}[\d\*]*[\*-\/,\d]*[\d\*])( \|,\|\").*/?$file.*|${repo_path}/$file|g;
|
||||
s|$dir_scripts/||
|
||||
}" | head -1 >> $list_own_scripts
|
||||
fi
|
||||
done
|
||||
grep -E "$cmd_task $author" $list_crontab_user | perl -pe "s|.*ID=(.*) $cmd_task ($author_.*)\.*|\2|" | sort -u >$list_own_user
|
||||
cd $dir_current
|
||||
}
|
||||
|
||||
main() {
|
||||
local p1=$1
|
||||
local p2=$2
|
||||
local p3=$3
|
||||
local p4=$4
|
||||
log_time=$(date "+%Y-%m-%d-%H-%M-%S")
|
||||
log_path="$dir_log/update/${log_time}_$p1.log"
|
||||
make_dir "$dir_log/update"
|
||||
if [[ $# -ne 1 ]]; then
|
||||
echo -e "命令输入错误...\n"
|
||||
usage
|
||||
else
|
||||
case $p1 in
|
||||
all)
|
||||
update)
|
||||
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
|
||||
rebuild)
|
||||
rebuild_qinglong | tee $log_path
|
||||
;;
|
||||
repo)
|
||||
count_own_repo_sum
|
||||
gen_own_dir_and_path
|
||||
update_own_repo | tee $log_path
|
||||
update_repo "$p2" "$p3" "$p4" | tee $log_path
|
||||
;;
|
||||
raw)
|
||||
count_own_repo_sum
|
||||
gen_own_dir_and_path
|
||||
update_own_raw | tee $log_path
|
||||
update_raw | tee $log_path
|
||||
;;
|
||||
*)
|
||||
update_specify_scripts_repo "$p1" | tee $log_path
|
||||
echo -e "命令输入错误...\n"
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
Loading…
Reference in New Issue
Block a user