mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-07 11:56:08 +08:00
git_pull 重构,样式优化
This commit is contained in:
parent
4ca49edf01
commit
d5b9bca68b
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -19,6 +19,9 @@
|
||||||
/src/.umi-production
|
/src/.umi-production
|
||||||
/src/.umi-test
|
/src/.umi-test
|
||||||
/.env.local
|
/.env.local
|
||||||
|
.env
|
||||||
|
|
||||||
/config
|
/config
|
||||||
/log
|
/log
|
||||||
.env
|
/db
|
||||||
|
/manual_log
|
|
@ -36,7 +36,7 @@ export default (app: Router) => {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
res.send({ code: 200, content });
|
res.send({ code: 200, data: content });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('🔥 error: %o', e);
|
logger.error('🔥 error: %o', e);
|
||||||
return next(e);
|
return next(e);
|
||||||
|
|
|
@ -17,6 +17,9 @@ const logPath = path.join(rootPath, 'log/');
|
||||||
const authError = '错误的用户名密码,请重试';
|
const authError = '错误的用户名密码,请重试';
|
||||||
const loginFaild = '请先登录!';
|
const loginFaild = '请先登录!';
|
||||||
const configString = 'config sample crontab shareCode diy';
|
const configString = 'config sample crontab shareCode diy';
|
||||||
|
const dbPath = path.join(rootPath, 'db/');
|
||||||
|
const manualLogPath = path.join(rootPath, 'manual_log/');
|
||||||
|
const cronDbFile = path.join(rootPath, 'db/crontab.db');
|
||||||
|
|
||||||
if (envFound.error) {
|
if (envFound.error) {
|
||||||
throw new Error("⚠️ Couldn't find .env file ⚠️");
|
throw new Error("⚠️ Couldn't find .env file ⚠️");
|
||||||
|
@ -48,4 +51,7 @@ export default {
|
||||||
'crontab.list': crontabFile,
|
'crontab.list': crontabFile,
|
||||||
'diy.sh': diyFile,
|
'diy.sh': diyFile,
|
||||||
},
|
},
|
||||||
|
dbPath,
|
||||||
|
cronDbFile,
|
||||||
|
manualLogPath,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# 更新shell及面板代码
|
# 更新shell及面板代码
|
||||||
55 2,13 * * * git_pull >> ${QL_DIR}/log/git_pull.log 2>&1
|
55 2,13 * * * git_pull >> ${QL_DIR}/log/git_pull.log 2>&1
|
||||||
|
|
||||||
# 更新你需要的仓库的代码
|
# 更新你需要的仓库的代码
|
||||||
# diy test作者 test仓库 test路径1|test路径2 黑名单1文件名|黑名单2文件名
|
# diy test作者 test仓库 test路径1|test路径2 黑名单1文件名|黑名单2文件名
|
||||||
33 * * * * diy whyour hundun "quanx/jx|quanx/jd" tokens >> ${QL_DIR}/log/diy_pull.log 2>&1
|
33 * * * * diy whyour hundun "quanx/jx|quanx/jd" tokens >> ${QL_DIR}/log/diy_pull.log 2>&1
|
||||||
|
@ -14,49 +15,13 @@
|
||||||
# 导出所有互助码清单,日志在log/export_sharecodes下
|
# 导出所有互助码清单,日志在log/export_sharecodes下
|
||||||
48 5 * * * export_sharecodes
|
48 5 * * * export_sharecodes
|
||||||
|
|
||||||
# 重启挂机脚本,挂机脚本可以随容器启动而启动,建议需要重启挂机程序时直接重启容器,如实在不想通过重启容器而重启挂机程序,可以解除下一行注释
|
# 重启挂机脚本
|
||||||
# 33 13 * * * js hangup
|
# 33 3 * * * js hangup
|
||||||
|
|
||||||
# 运行lxk0301大佬的js脚本,仅列出长期任务作初始化用,AutoAddCron=true时,将自动添加短期任务。
|
# 重置密码
|
||||||
# 请保留任务名称中的前缀"jd_",去掉后缀".js",如果有些任务你不想运行,注释掉就好了,不要删除。
|
# 33 6 */7 * * js resetpwd
|
||||||
# 非lxk0301/jd_scripts仓库中的脚本不能以“jd_”、“jr_”、“jx_”开头。请在最后保留一个空行。
|
|
||||||
5 9 * * * js jd_bean_change
|
# 运行所有脚本(慎用)
|
||||||
28 5 * * * js jd_bean_home
|
# 33 9 */7 * * js runall
|
||||||
4 0,9 * * * js jd_bean_sign
|
|
||||||
0,30 0 * * * js jd_blueCoin
|
# 其他定时任务
|
||||||
12 8,12,18 * * * js jd_bookshop
|
|
||||||
37 7 * * * js jd_car
|
|
||||||
13 8,22 * * * js jd_cash
|
|
||||||
0 0 * * * js jd_car_exchange
|
|
||||||
2 0 * * * js jd_club_lottery
|
|
||||||
43 13 * * * js jd_crazy_joy
|
|
||||||
54 2-23/3 * * * js jd_daily_egg
|
|
||||||
20 * * * * js jd_dreamFactory
|
|
||||||
29 7,12,18 * * * js jd_fruit
|
|
||||||
49 6 * * * js jd_get_share_code
|
|
||||||
36 * * * * js jd_jdfactory
|
|
||||||
14 11 * * * js jd_jdzz
|
|
||||||
6 0,8,9,13,18,22 * * * js jd_joy
|
|
||||||
*/20 0-22 * * * js jd_joy_feedPets
|
|
||||||
0 0,8,12,16 * * * js jd_joy_reward
|
|
||||||
12 9-20/2 * * * js jd_joy_run
|
|
||||||
0 0,6 * * * js jd_joy_steal
|
|
||||||
0 9,12,18 * * * js jd_jxnc
|
|
||||||
32 7 * * * js jd_kd
|
|
||||||
13-33/5 13 * * * js jd_live
|
|
||||||
15 1 * * * js jd_lotteryMachine
|
|
||||||
40 */4 * * * js jd_moneyTree
|
|
||||||
20 0,20 * * * js jd_necklace
|
|
||||||
10 7,12,18 * * * js jd_pet
|
|
||||||
25 * * * * js jd_pigPet
|
|
||||||
35 7-22 * * * js jd_plantBean
|
|
||||||
11 0 * * * js jd_rankingList
|
|
||||||
1 1 * * * js jd_redPacket
|
|
||||||
0 0 * * * js jd_shop
|
|
||||||
16 0 * * * js jd_small_home
|
|
||||||
35 */3 * * * js jd_speed
|
|
||||||
9 1-23/5 * * * js jd_superMarket
|
|
||||||
25 9 * * * js jd_syj
|
|
||||||
44 5 * * 5 js jd_unbind
|
|
||||||
45 23 * * * js jd_unsubscribe
|
|
||||||
19 11 * * * js jx_sign
|
|
||||||
|
|
|
@ -1,163 +1,77 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
## 文件路径、脚本网址、文件版本以及各种环境的判断
|
## 常量
|
||||||
ShellDir=${QL_DIR:-$(cd $(dirname $0); pwd)}
|
ShellDir=${QL_DIR:-$(
|
||||||
[[ ${QL_DIR} ]] && ShellJs=js
|
cd $(dirname $0)
|
||||||
LogDir=${ShellDir}/log
|
pwd
|
||||||
[ ! -d ${LogDir} ] && mkdir -p ${LogDir}
|
)}
|
||||||
ScriptsDir=${ShellDir}/scripts
|
[[ $QL_DIR ]] && ShellJs=js
|
||||||
ConfigDir=${ShellDir}/config
|
LogDir=$ShellDir/log
|
||||||
FileConf=${ConfigDir}/config.sh
|
[ ! -d $LogDir ] && mkdir -p $LogDir
|
||||||
CookieConf=${ConfigDir}/cookie.sh
|
DbDir=$ShellDir/db
|
||||||
FileDiy=${ConfigDir}/diy.sh
|
[ ! -d $DbDir ] && mkdir -p $DbDir
|
||||||
FileConfSample=${ShellDir}/sample/config.sh.sample
|
ManualLogDir=$ShellDir/manual_log
|
||||||
ListCron=${ConfigDir}/crontab.list
|
[ ! -d $ManualLogDir ] && mkdir -p $ManualLogDir
|
||||||
ListCronLxk=${ScriptsDir}/docker/crontab_list.sh
|
ScriptsDir=$ShellDir/scripts
|
||||||
ListTask=${LogDir}/task.list
|
ConfigDir=$ShellDir/config
|
||||||
ListJs=${LogDir}/js.list
|
FileConf=$ConfigDir/config.sh
|
||||||
ListJsAdd=${LogDir}/js-add.list
|
CookieConf=$ConfigDir/cookie.sh
|
||||||
ListJsDrop=${LogDir}/js-drop.list
|
ExtraShell=$ConfigDir/extra.sh
|
||||||
ContentVersion=${ShellDir}/version
|
FileConfSample=$ShellDir/sample/config.sh.sample
|
||||||
ContentNewTask=${ShellDir}/new_task
|
ListCronSample=$ShellDir/sample/crontab.list.sample
|
||||||
ContentDropTask=${ShellDir}/drop_task
|
ListCronCurrent=$ConfigDir/crontab.list
|
||||||
SendCount=${ShellDir}/send_count
|
ListCronRemote=$ScriptsDir/docker/crontab_list.sh
|
||||||
isTermux=${ANDROID_RUNTIME_ROOT}${ANDROID_ROOT}
|
ListCurrentTask=$LogDir/task.list
|
||||||
|
ListRemoteTask=$LogDir/js.list
|
||||||
|
ListJsAdd=$LogDir/js-add.list
|
||||||
|
ListJsDrop=$LogDir/js-drop.list
|
||||||
|
ContentVersion=$ShellDir/version
|
||||||
|
ContentNewTask=$ShellDir/new_task
|
||||||
|
ContentDropTask=$ShellDir/drop_task
|
||||||
|
SendVersion=$ShellDir/send_version
|
||||||
|
isTermux=$ANDROID_RUNTIME_ROOT$ANDROID_ROOT
|
||||||
ShellURL=https://github.com.cnpmjs.org/whyour/qinglong
|
ShellURL=https://github.com.cnpmjs.org/whyour/qinglong
|
||||||
ScriptsURL=https://github.com.cnpmjs.org/gossh520/jd_scripts
|
ScriptsURL=https://github.com.cnpmjs.org/gossh520/jd_scripts
|
||||||
|
|
||||||
## 导入配置文件
|
Import_Conf() {
|
||||||
function Import_Conf {
|
if [ ! -s $FileConf ]; then
|
||||||
if [ -f ${FileConf} ]; then
|
echo -e "复制一份 $FileConfSample 示例配置文件\n\n"
|
||||||
. ${CookieConf}
|
cp -fv $FileConfSample $FileConf
|
||||||
. ${FileConf}
|
|
||||||
fi
|
fi
|
||||||
|
if [ ! -s $ListCronCurrent ]; then
|
||||||
|
echo -e "复制一份 $ListCronSample 基础定时任务\n\n"
|
||||||
|
cp -fv $ListCronSample $ListCronCurrent
|
||||||
|
fi
|
||||||
|
[ -f $CookieConf ] && . $CookieConf
|
||||||
|
[ -f $FileConf ] && . $FileConf
|
||||||
}
|
}
|
||||||
|
|
||||||
## 更新crontab,gitee服务器同一时间限制5个链接,因此每个人更新代码必须错开时间,每次执行git_pull随机生成。
|
# 更新shell
|
||||||
## 每天次数随机,更新时间随机,更新秒数随机,至少6次,至多12次,大部分为8-10次,符合正态分布。
|
Git_Pull_Shell() {
|
||||||
function Update_Cron {
|
|
||||||
if [[ $(date "+%-H") -le 2 ]] && [ -f ${ListCron} ]; then
|
|
||||||
RanMin=$((${RANDOM} % 60))
|
|
||||||
RanSleep=$((${RANDOM} % 56))
|
|
||||||
RanHourArray[0]=$((${RANDOM} % 3))
|
|
||||||
for ((i=1; i<14; i++)); do
|
|
||||||
j=$(($i - 1))
|
|
||||||
tmp=$((${RANDOM} % 3 + ${RanHourArray[j]} + 2))
|
|
||||||
[[ ${tmp} -lt 24 ]] && RanHourArray[i]=${tmp} || break
|
|
||||||
done
|
|
||||||
RanHour=${RanHourArray[0]}
|
|
||||||
for ((i=1; i<${#RanHourArray[*]}; i++)); do
|
|
||||||
RanHour="${RanHour},${RanHourArray[i]}"
|
|
||||||
done
|
|
||||||
perl -i -pe "s|.+(git_pull? .+git_pull\.log.*)|${RanMin} ${RanHour} \* \* \* sleep ${RanSleep} && \1|" ${ListCron}
|
|
||||||
crontab ${ListCron}
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
function Git_PullShell {
|
|
||||||
echo -e "更新shell...\n"
|
echo -e "更新shell...\n"
|
||||||
cd ${ShellDir}
|
cd $ShellDir
|
||||||
git remote set-url origin $ShellURL
|
git remote set-url origin $ShellURL
|
||||||
git fetch --all
|
git fetch --all
|
||||||
ExitStatusShell=$?
|
ExitStatusShell=$?
|
||||||
git reset --hard origin/master
|
git reset --hard origin/master
|
||||||
git pull
|
git pull
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## 更新shell成功后的操作
|
Git_Pull_Shell_Next() {
|
||||||
function Git_PullShellNext {
|
if [[ $ExitStatusShell -eq 0 ]]; then
|
||||||
if [[ ${ExitStatusShell} -eq 0 ]]; then
|
|
||||||
echo -e "更新shell成功...\n"
|
echo -e "更新shell成功...\n"
|
||||||
[[ "${PanelDependOld}" != "${PanelDependNew}" ]] && cd ${ShellDir}/panel && Npm_Install panel
|
[ ! -d $ShellDir/node_modules ] && Npm_Install panel
|
||||||
cp -f ${FileConfSample} ${ConfigDir}/config.sh.sample
|
[ -f $ShellDir/package.json ] && PanelDependNew=$(cat $ShellDir/package.json)
|
||||||
[ -d ${ScriptsDir}/node_modules ] && Notify_Version
|
[[ "$PanelDependOld" != "$PanelDependNew" ]] && cd $ShellDir && Npm_Install panel
|
||||||
|
cp -f $FileConfSample $ConfigDir/config.sh.sample
|
||||||
|
Notify_Version
|
||||||
else
|
else
|
||||||
echo -e "更新shell失败,请检查原因...\n"
|
echo -e "更新shell失败,请检查原因...\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## 克隆scripts
|
|
||||||
function Git_CloneScripts {
|
|
||||||
git clone -b master ${ScriptsURL} ${ScriptsDir}
|
|
||||||
ExitStatusScripts=$?
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
## 更新scripts
|
|
||||||
function Git_PullScripts {
|
|
||||||
echo -e "更新scripts...\n"
|
|
||||||
cd ${ScriptsDir}
|
|
||||||
git remote set-url origin $ScriptsURL
|
|
||||||
git fetch --all
|
|
||||||
ExitStatusScripts=$?
|
|
||||||
git reset --hard origin/master
|
|
||||||
git pull
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
## 检测文件:LXK9301/jd_scripts 仓库中的 docker/crontab_list.sh
|
|
||||||
## 检测定时任务是否有变化,此函数会在Log文件夹下生成四个文件,分别为:
|
|
||||||
## task.list crontab.list中的所有任务清单,仅保留脚本名
|
|
||||||
## js.list 上述检测文件中用来运行js脚本的清单(去掉后缀.js,非运行脚本的不会包括在内)
|
|
||||||
## js-add.list 如果上述检测文件增加了定时任务,这个文件内容将不为空
|
|
||||||
## js-drop.list 如果上述检测文件删除了定时任务,这个文件内容将不为空
|
|
||||||
function Diff_Cron {
|
|
||||||
if [ -f ${ListCron} ]; then
|
|
||||||
if [ -n "${QL_DIR}" ]
|
|
||||||
then
|
|
||||||
grep -E " j[drx]_\w+" ${ListCron} | perl -pe "s|.+ (j[drx]_\w+).*|\1|" | sort -u > ${ListTask}
|
|
||||||
else
|
|
||||||
grep "${ShellDir}/" ${ListCron} | grep -E " j[drx]_\w+" | perl -pe "s|.+ (j[drx]_\w+).*|\1|" | sort -u > ${ListTask}
|
|
||||||
fi
|
|
||||||
cat ${ListCronLxk} | grep -E "j[drx]_\w+\.js" | perl -pe "s|.+(j[drx]_\w+)\.js.+|\1|" | sort -u > ${ListJs}
|
|
||||||
grep -vwf ${ListTask} ${ListJs} > ${ListJsAdd}
|
|
||||||
grep -vwf ${ListJs} ${ListTask} > ${ListJsDrop}
|
|
||||||
else
|
|
||||||
echo -e "${ListCron} 文件不存在,请先定义你自己的crontab.list...\n"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
## 检测配置文件版本
|
|
||||||
function Notify_Version {
|
|
||||||
## 识别出两个文件的版本号
|
|
||||||
VerConfSample=$(grep " Version: " ${FileConfSample} | perl -pe "s|.+v((\d+\.?){3})|\1|")
|
|
||||||
[ -f ${FileConf} ] && VerConf=$(grep " Version: " ${FileConf} | perl -pe "s|.+v((\d+\.?){3})|\1|")
|
|
||||||
|
|
||||||
## 删除旧的发送记录文件
|
|
||||||
[ -f "${SendCount}" ] && [[ $(cat ${SendCount}) != ${VerConfSample} ]] && rm -f ${SendCount}
|
|
||||||
|
|
||||||
## 识别出更新日期和更新内容
|
|
||||||
UpdateDate=$(grep " Date: " ${FileConfSample} | awk -F ": " '{print $2}')
|
|
||||||
UpdateContent=$(grep " Update Content: " ${FileConfSample} | awk -F ": " '{print $2}')
|
|
||||||
|
|
||||||
## 如果是今天,并且版本号不一致,则发送通知
|
|
||||||
if [ -f ${FileConf} ] && [[ "${VerConf}" != "${VerConfSample}" ]] && [[ ${UpdateDate} == $(date "+%Y-%m-%d") ]]
|
|
||||||
then
|
|
||||||
if [ ! -f ${SendCount} ]; then
|
|
||||||
notify "检测到配置文件config.sh.sample有更新" "更新日期: ${UpdateDate}\n当前版本: ${VerConf}\n新的版本: ${VerConfSample}\n更新内容: ${UpdateContent}\n更新说明: 如需使用新功能请对照config.sh.sample,将相关新参数手动增加到你自己的config.sh中,否则请无视本消息。本消息只在该新版本配置文件更新当天发送一次。"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[ -f ${ContentVersion} ] && rm -f ${ContentVersion}
|
|
||||||
[ -f ${SendCount} ] && rm -f ${SendCount}
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
## npm install 子程序,判断是否为安卓,判断是否安装有yarn
|
|
||||||
function Npm_InstallSub {
|
|
||||||
if [ -n "${isTermux}" ]
|
|
||||||
then
|
|
||||||
npm install --no-bin-links --no-save || npm install --no-save --no-bin-links --registry=https://registry.npm.taobao.org
|
|
||||||
elif ! type yarn >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
npm install --no-save || npm install --no-save --registry=https://registry.npm.taobao.org
|
|
||||||
else
|
|
||||||
echo -e "检测到本机安装了 yarn,使用 yarn 替代 npm...\n"
|
|
||||||
yarn install || yarn install --registry=https://registry.npm.taobao.org
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
## npm install
|
## npm install
|
||||||
function Npm_Install {
|
Npm_Install() {
|
||||||
echo -e "检测到 $1 的依赖包有变化,运行 npm install...\n"
|
echo -e "检测到 $1 的依赖包有变化,运行 npm install...\n"
|
||||||
Npm_InstallSub
|
Npm_InstallSub
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
|
@ -183,131 +97,197 @@ function Npm_Install {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## 输出是否有新的定时任务
|
## npm install 子程序,判断是否为安卓,判断是否安装有yarn
|
||||||
function Output_ListJsAdd {
|
function Npm_InstallSub() {
|
||||||
if [ -s ${ListJsAdd} ]; then
|
if [ -n "$isTermux" ]; then
|
||||||
echo -e "检测到有新的定时任务:\n"
|
npm install --no-bin-links --no-save || npm install --no-save --no-bin-links --registry=https://registry.npm.taobao.org
|
||||||
cat ${ListJsAdd}
|
elif ! type yarn >/dev/null 2>&1; then
|
||||||
echo
|
npm install --no-save || npm install --no-save --registry=https://registry.npm.taobao.org
|
||||||
|
else
|
||||||
|
echo -e "检测到本机安装了 yarn,使用 yarn 替代 npm...\n"
|
||||||
|
yarn install || yarn install --registry=https://registry.npm.taobao.org
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## 输出是否有失效的定时任务
|
## 检测配置文件版本
|
||||||
function Output_ListJsDrop {
|
Notify_Version() {
|
||||||
if [ ${ExitStatusScripts} -eq 0 ] && [ -s ${ListJsDrop} ]; then
|
## 识别出两个文件的版本号
|
||||||
echo -e "检测到有失效的定时任务:\n"
|
VerConfSample=$(grep " Version: " $FileConfSample | perl -pe "s|.+v((\d+\.?){3})|\1|")
|
||||||
cat ${ListJsDrop}
|
[ -f $FileConf ] && VerConf=$(grep " Version: " $FileConf | perl -pe "s|.+v((\d+\.?){3})|\1|")
|
||||||
echo
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
## 自动删除失效的脚本与定时任务,需要5个条件:1.AutoDelCron 设置为 true;2.正常更新js脚本,没有报错;3.js-drop.list不为空;4.crontab.list存在并且不为空;5.已经正常运行过npm install
|
## 删除旧的发送记录文件
|
||||||
## 检测文件:LXK9301/jd_scripts 仓库中的 docker/crontab_list.sh
|
[ -f "$SendVersion" ] && [[ $(cat $SendVersion) != $VerConfSample ]] && rm -f $SendVersion
|
||||||
## 如果检测到某个定时任务在上述检测文件中已删除,那么在本地也删除对应定时任务
|
|
||||||
function Del_Cron {
|
## 识别出更新日期和更新内容
|
||||||
if [ "${AutoDelCron}" = "true" ] && [ -s ${ListJsDrop} ] && [ -s ${ListCron} ] && [ -d ${ScriptsDir}/node_modules ]; then
|
UpdateDate=$(grep " Date: " $FileConfSample | awk -F ": " '{print $2}')
|
||||||
echo -e "开始尝试自动删除定时任务如下:\n"
|
UpdateContent=$(grep " Update Content: " $FileConfSample | awk -F ": " '{print $2}')
|
||||||
cat ${ListJsDrop}
|
|
||||||
echo
|
## 如果是今天,并且版本号不一致,则发送通知
|
||||||
JsDrop=$(cat ${ListJsDrop})
|
if [ -f $FileConf ] && [[ "$VerConf" != "$VerConfSample" ]] && [[ $UpdateDate == $(date "+%Y-%m-%d") ]]; then
|
||||||
for Cron in ${JsDrop}
|
if [ ! -f $SendVersion ]; then
|
||||||
do
|
notify "检测到配置文件config.sh.sample有更新" "更新日期: $UpdateDate\n当前版本: $VerConf\n新的版本: $VerConfSample\n更新内容: $UpdateContent\n更新说明: 如需使用新功能请对照config.sh.sample,将相关新参数手动增加到你自己的config.sh中,否则请无视本消息。本消息只在该新版本配置文件更新当天发送一次。"
|
||||||
perl -i -ne "{print unless / ${Cron}( |$)/}" ${ListCron}
|
|
||||||
done
|
|
||||||
crontab ${ListCron}
|
|
||||||
echo -e "成功删除失效的脚本与定时任务,当前的定时任务清单如下:\n\n--------------------------------------------------------------\n"
|
|
||||||
crontab -l
|
|
||||||
echo -e "\n--------------------------------------------------------------\n"
|
|
||||||
if [ -d ${ScriptsDir}/node_modules ]; then
|
|
||||||
notify "删除 lxk0301 失效脚本" "${JsDrop}"
|
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
[ -f $ContentVersion ] && rm -f $ContentVersion
|
||||||
|
[ -f $SendVersion ] && rm -f $SendVersion
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## 自动增加新的定时任务,需要5个条件:1.AutoAddCron 设置为 true;2.正常更新js脚本,没有报错;3.js-add.list不为空;4.crontab.list存在并且不为空;5.已经正常运行过npm install
|
## 每天次数随机,更新时间随机,更新秒数随机,至少6次,至多12次,大部分为8-10次,符合正态分布。
|
||||||
## 检测文件:LXK9301/jd_scripts 仓库中的 docker/crontab_list.sh
|
Random_Pull_Cron() {
|
||||||
## 如果检测到检测文件中增加新的定时任务,那么在本地也增加
|
if [[ $(date "+%-H") -le 2 ]]; then
|
||||||
## 本功能生效时,会自动从检测文件新增加的任务中读取时间,该时间为北京时间
|
RanMin=$(($RANDOM % 60))
|
||||||
function Add_Cron {
|
RanSleep=$(($RANDOM % 56))
|
||||||
if [ "${AutoAddCron}" = "true" ] && [ -s ${ListJsAdd} ] && [ -s ${ListCron} ] && [ -d ${ScriptsDir}/node_modules ]; then
|
RanHourArray[0]=$(($RANDOM % 3))
|
||||||
echo -e "开始尝试自动添加定时任务如下:\n"
|
for ((i = 1; i < 14; i++)); do
|
||||||
cat ${ListJsAdd}
|
j=$(($i - 1))
|
||||||
echo
|
tmp=$(($RANDOM % 3 + ${RanHourArray[j]} + 2))
|
||||||
JsAdd=$(cat ${ListJsAdd})
|
[[ $tmp -lt 24 ]] && RanHourArray[i]=$tmp || break
|
||||||
|
done
|
||||||
|
|
||||||
|
for ((i = 1; i < ${#RanHourArray[*]}; i++)); do
|
||||||
|
RanHour="$RanHour,${RanHourArray[i]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
perl -i -pe "s|.+(git_pull? .+git_pull\.log.*)|$RanMin $RanHour \* \* \* sleep $RanSleep && \1|" $ListCronCurrent
|
||||||
|
crontab $ListCronCurrent
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
for Cron in ${JsAdd}
|
## 克隆scripts
|
||||||
do
|
Git_Clone_Scripts() {
|
||||||
if [[ ${Cron} == jd_bean_sign ]]
|
git clone -b master $ScriptsURL $ScriptsDir
|
||||||
then
|
ExitStatusScripts=$?
|
||||||
echo "4 0,9 * * * ${ShellJs} ${Cron}" >> ${ListCron}
|
}
|
||||||
|
|
||||||
|
## 更新scripts
|
||||||
|
Git_Pull_Scripts() {
|
||||||
|
if [ -d $ScriptsDir/.git ]; then
|
||||||
|
echo -e "更新scripts...\n"
|
||||||
|
cd $ScriptsDir
|
||||||
|
git remote set-url origin $ScriptsURL
|
||||||
|
git fetch --all
|
||||||
|
ExitStatusScripts=$?
|
||||||
|
git reset --hard origin/master
|
||||||
|
git pull
|
||||||
|
else
|
||||||
|
Git_Clone_Scripts
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
Git_Pull_Scripts_Next() {
|
||||||
|
if [[ $ExitStatusShell -eq 0 ]]; then
|
||||||
|
echo -e "更新scripts成功...\n"
|
||||||
|
[ ! -d $ScriptsDir/node_modules ] && Npm_Install scripts
|
||||||
|
[ -f $ScriptsDir/package.json ] && ScriptsDependNew=$(cat $ScriptsDir/package.json)
|
||||||
|
[[ "$ScriptsDependOld" != "$ScriptsDependNew" ]] && cd $ScriptsDir && Npm_Install scripts
|
||||||
|
Diff_Cron
|
||||||
|
if [ -s $ListJsDrop ]; then
|
||||||
|
Output_ListJs $ListJsDrop "失效"
|
||||||
|
Del_Cron
|
||||||
|
fi
|
||||||
|
if [ -s $ListJsAdd ]; then
|
||||||
|
Output_ListJs $ListJsAdd "新"
|
||||||
|
Add_Cron
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e "更新scripts失败,请检查原因...\n"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
Diff_Cron() {
|
||||||
|
cat $ListCronRemote | grep -E "node.+j[drx]_\w+\.js" | perl -pe "s|.+(j[drx]_\w+)\.js.+|\1|" | sort -u >$ListRemoteTask
|
||||||
|
cat $ListCronCurrent | grep -E "$ShellJs j[drx]_\w+" | perl -pe "s|.*$ShellJs (j[drx]_\w+)\.*|\1|" | sort -u >$ListCurrentTask
|
||||||
|
if [ -s $ListCurrentTask ]; then
|
||||||
|
grep -vwf $ListCurrentTask $ListRemoteTask >$ListJsAdd
|
||||||
|
else
|
||||||
|
cp -f $ListRemoteTask $ListJsAdd
|
||||||
|
fi
|
||||||
|
if [ -s $ListRemoteTask ]; then
|
||||||
|
grep -vwf $ListRemoteTask $ListCurrentTask >$ListJsDrop
|
||||||
|
else
|
||||||
|
cp -f $ListCurrentTask $ListJsDrop
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
Del_Cron() {
|
||||||
|
if [ $AutoDelCron == true ] && [ -s $ListJsDrop ]; then
|
||||||
|
echo -e "开始尝试自动删除定时任务如下:\n"
|
||||||
|
cat $ListJsDrop
|
||||||
|
echo
|
||||||
|
JsDrop=$(cat $ListJsDrop)
|
||||||
|
for Cron in $JsDrop; do
|
||||||
|
perl -i -ne "{print unless / $Cron( |$)/}" $ListCronCurrent
|
||||||
|
done
|
||||||
|
crontab $ListCronCurrent
|
||||||
|
echo -e "成功删除失效的脚本与定时任务\n"
|
||||||
|
notify "删除 lxk0301 失效脚本" "$JsDrop"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
Add_Cron() {
|
||||||
|
if [ $AutoAddCron == true ] && [ -s $ListJsAdd ]; then
|
||||||
|
echo -e "开始尝试自动添加定时任务\n"
|
||||||
|
JsAdd=$(cat $ListJsAdd)
|
||||||
|
for Cron in $JsAdd; do
|
||||||
|
if [[ $Cron == jd_bean_sign ]]; then
|
||||||
|
echo "4 0,9 * * * $ShellJs $Cron" >> $ListCronCurrent
|
||||||
else
|
else
|
||||||
cat ${ListCronLxk} | grep -E "\/${Cron}\." | perl -pe "s|(^.+)node */scripts/(j[drx]_\w+)\.js.+|\1${ShellJs} \2|" >> ${ListCron}
|
cat $ListCronRemote | grep -E "\/$Cron\." | perl -pe "s|(^.+)node */scripts/(j[drx]_\w+)\.js.+|\1$ShellJs \2|" >> $ListCronCurrent
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $? -eq 0 ]
|
if [ $? -eq 0 ]; then
|
||||||
then
|
crontab $ListCronCurrent
|
||||||
crontab ${ListCron}
|
echo -e "成功添加新的定时任务...\n"
|
||||||
echo -e "成功添加新的定时任务,当前的定时任务清单如下:\n\n--------------------------------------------------------------\n"
|
notify "新增lxk0301脚本" "$JsAdd"
|
||||||
crontab -l
|
|
||||||
echo -e "\n--------------------------------------------------------------\n"
|
|
||||||
if [ -d ${ScriptsDir}/node_modules ]; then
|
|
||||||
notify "新增 lxk0301 自定义脚本" "${JsAdd}"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo -e "添加新的定时任务出错,请手动添加...\n"
|
echo -e "添加新的定时任务出错,请手动添加...\n"
|
||||||
if [ -d ${ScriptsDir}/node_modules ]; then
|
notify "尝试自动添加lxk0301以下新的定时任务出错,请手动添加:" "$JsAdd"
|
||||||
notify "尝试自动添加 lxk0301 以下新的定时任务出错,请手动添加:" "${JsAdd}"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## 在日志中记录时间与路径
|
## 输出定时任务变化
|
||||||
|
Output_ListJs() {
|
||||||
|
local list=$1
|
||||||
|
local type=$2
|
||||||
|
if [ -s $list ]; then
|
||||||
|
echo -e "检测到有$type的定时任务:\n"
|
||||||
|
cat $list
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#################################################################################################################################
|
||||||
echo -e "\n--------------------------------------------------------------\n"
|
echo -e "\n--------------------------------------------------------------\n"
|
||||||
echo -n "系统时间:"
|
echo -n "系统时间:"
|
||||||
echo $(date "+%Y-%m-%d %H:%M:%S")
|
echo $(date "+%Y-%m-%d %H:%M:%S")
|
||||||
if [ "${TZ}" = "UTC" ]; then
|
if [ "${TZ}" = "UTC" ]; then
|
||||||
echo
|
|
||||||
echo -n "北京时间:"
|
echo -n "北京时间:"
|
||||||
echo $(date -d "8 hour" "+%Y-%m-%d %H:%M:%S")
|
echo $(date -d "8 hour" "+%Y-%m-%d %H:%M:%S")
|
||||||
fi
|
fi
|
||||||
echo -e "\nJS脚本目录:${ScriptsDir}\n"
|
echo -e "\nJS脚本目录:$ScriptsDir\n"
|
||||||
echo -e "--------------------------------------------------------------\n"
|
echo -e "--------------------------------------------------------------\n"
|
||||||
|
|
||||||
## 导入配置,更新cron,设置url,更新shell,复制sample,复制entrypoint,发送新配置通知
|
Import_Conf
|
||||||
Import_Conf "git_pull"
|
Random_Pull_Cron
|
||||||
Update_Cron
|
|
||||||
[ -f ${ShellDir}/panel/package.json ] && PanelDependOld=$(cat ${ShellDir}/panel/package.json)
|
|
||||||
Git_PullShell
|
|
||||||
[ -f ${ShellDir}/panel/package.json ] && PanelDependNew=$(cat ${ShellDir}/panel/package.json)
|
|
||||||
Git_PullShellNext
|
|
||||||
|
|
||||||
## 克隆或更新js脚本
|
# 更新shell
|
||||||
[ -f ${ScriptsDir}/package.json ] && ScriptsDependOld=$(cat ${ScriptsDir}/package.json)
|
[ -f $ShellDir/package.json ] && PanelDependOld=$(cat $ShellDir/package.json)
|
||||||
[ -d ${ScriptsDir}/.git ] && Git_PullScripts || Git_CloneScripts
|
Git_Pull_Shell
|
||||||
[ -f ${ScriptsDir}/package.json ] && ScriptsDependNew=$(cat ${ScriptsDir}/package.json)
|
Git_Pull_Shell_Next
|
||||||
|
|
||||||
## 执行各函数
|
## 更新scripts
|
||||||
if [[ ${ExitStatusScripts} -eq 0 ]]
|
[ -f $ScriptsDir/package.json ] && ScriptsDependOld=$(cat $ScriptsDir/package.json)
|
||||||
then
|
Git_Pull_Scripts
|
||||||
echo -e "更新scripts成功...\n"
|
Git_Pull_Scripts_Next
|
||||||
Diff_Cron
|
|
||||||
[[ "${ScriptsDependOld}" != "${ScriptsDependNew}" ]] && cd ${ScriptsDir} && Npm_Install scripts
|
|
||||||
Output_ListJsAdd
|
|
||||||
Output_ListJsDrop
|
|
||||||
Del_Cron
|
|
||||||
Add_Cron
|
|
||||||
else
|
|
||||||
echo -e "更新scripts失败,请检查原因...\n"
|
|
||||||
fi
|
|
||||||
|
|
||||||
## 调用用户自定义的diy.sh
|
## 调用用户自定义的extra.sh
|
||||||
if [[ ${EnableExtraShell} == true ]]; then
|
if [[ $EnableExtraShell == true ]]; then
|
||||||
if [ -f ${FileDiy} ]
|
if [ -f $ExtraShell ]; then
|
||||||
then
|
. $ExtraShell
|
||||||
. ${FileDiy}
|
|
||||||
else
|
else
|
||||||
echo -e "${FileDiy} 文件不存在,跳过执行DIY脚本...\n"
|
echo -e "$ExtraShell 文件不存在,跳过执行DIY脚本...\n"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -8,7 +8,7 @@ body {
|
||||||
|
|
||||||
.code-mirror-wrapper .CodeMirror {
|
.code-mirror-wrapper .CodeMirror {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
height: calc(100% - 24px);
|
height: calc(100% - 48px);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,5 +19,14 @@ body {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
height: calc(100vh - 96px);
|
height: calc(100vh - 96px);
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
|
padding: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.ant-pro-grid-content.wide {
|
||||||
|
.ant-pro-page-container-children-content {
|
||||||
|
height: calc(100vh - 144px);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,19 @@ export default function (props: any) {
|
||||||
const theme = localStorage.getItem('qinglong_dark_theme') || 'auto';
|
const theme = localStorage.getItem('qinglong_dark_theme') || 'auto';
|
||||||
setFetchMethod(window.fetch);
|
setFetchMethod(window.fetch);
|
||||||
if (theme === 'dark') {
|
if (theme === 'dark') {
|
||||||
enableDarkMode({ darkSchemeTextColor: '#fff' });
|
enableDarkMode({
|
||||||
|
brightness: 100,
|
||||||
|
contrast: 90,
|
||||||
|
sepia: 10,
|
||||||
|
});
|
||||||
} else if (theme === 'light') {
|
} else if (theme === 'light') {
|
||||||
disableDarkMode();
|
disableDarkMode();
|
||||||
} else {
|
} else {
|
||||||
followSystemColorScheme({ darkSchemeTextColor: '#fff' });
|
followSystemColorScheme({
|
||||||
|
brightness: 100,
|
||||||
|
contrast: 90,
|
||||||
|
sepia: 10,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ const Crontab = () => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}config/shareCode`)
|
.get(`${config.apiPrefix}config/shareCode`)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setValue(data.content);
|
setValue(data.data);
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,6 @@ import config from '@/utils/config';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
import { Controlled as CodeMirror } from 'react-codemirror2';
|
import { Controlled as CodeMirror } from 'react-codemirror2';
|
||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
import QRCode from 'qrcode.react';
|
|
||||||
|
|
||||||
const Config = () => {
|
const Config = () => {
|
||||||
const [width, setWdith] = useState('100%');
|
const [width, setWdith] = useState('100%');
|
||||||
|
@ -18,7 +17,7 @@ const Config = () => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}config/config`)
|
.get(`${config.apiPrefix}config/config`)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setValue(data.content);
|
setValue(data.data);
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
import React, { PureComponent, Fragment, useState, useEffect } from 'react';
|
import React, { PureComponent, Fragment, useState, useEffect } from 'react';
|
||||||
import { Button, notification, Modal, Table, Tag, Space } from 'antd';
|
import {
|
||||||
|
Button,
|
||||||
|
notification,
|
||||||
|
Modal,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Space,
|
||||||
|
Typography,
|
||||||
|
} from 'antd';
|
||||||
import { EditOutlined, DeleteOutlined } from '@ant-design/icons';
|
import { EditOutlined, DeleteOutlined } from '@ant-design/icons';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
|
@ -7,6 +15,8 @@ import { request } from '@/utils/http';
|
||||||
import QRCode from 'qrcode.react';
|
import QRCode from 'qrcode.react';
|
||||||
import CookieModal from './modal';
|
import CookieModal from './modal';
|
||||||
|
|
||||||
|
const { Text } = Typography;
|
||||||
|
|
||||||
enum Status {
|
enum Status {
|
||||||
'正常',
|
'正常',
|
||||||
'失效',
|
'失效',
|
||||||
|
@ -197,7 +207,11 @@ const Config = () => {
|
||||||
const deleteCookie = (record: any, index: number) => {
|
const deleteCookie = (record: any, index: number) => {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
title: '确认删除',
|
title: '确认删除',
|
||||||
content: `确认删除Cookie ${record.cookie} 吗`,
|
content: (
|
||||||
|
<>
|
||||||
|
确认删除Cookie <Text type="warning">{record.cookie}</Text> 吗
|
||||||
|
</>
|
||||||
|
),
|
||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.delete(`${config.apiPrefix}cookie`, {
|
.delete(`${config.apiPrefix}cookie`, {
|
||||||
|
@ -270,7 +284,11 @@ const Config = () => {
|
||||||
>
|
>
|
||||||
<Table
|
<Table
|
||||||
columns={columns}
|
columns={columns}
|
||||||
pagination={{ hideOnSinglePage: true }}
|
pagination={{
|
||||||
|
hideOnSinglePage: true,
|
||||||
|
showSizeChanger: true,
|
||||||
|
defaultPageSize: 20,
|
||||||
|
}}
|
||||||
dataSource={value}
|
dataSource={value}
|
||||||
rowKey="pin"
|
rowKey="pin"
|
||||||
size="middle"
|
size="middle"
|
||||||
|
|
|
@ -16,7 +16,7 @@ const Crontab = () => {
|
||||||
|
|
||||||
const getConfig = () => {
|
const getConfig = () => {
|
||||||
request.get(`${config.apiPrefix}config/config`).then((data) => {
|
request.get(`${config.apiPrefix}config/config`).then((data) => {
|
||||||
setValue(data.content);
|
setValue(data.data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ const Crontab = () => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}config/sample`)
|
.get(`${config.apiPrefix}config/sample`)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setSample(data.content);
|
setSample(data.data);
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,7 +17,7 @@ const Crontab = () => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}config/diy`)
|
.get(`${config.apiPrefix}config/diy`)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setValue(data.content);
|
setValue(data.data);
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user