mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 23:06:06 +08:00
更新diy和git_pull
This commit is contained in:
parent
8a45599919
commit
a519997da7
|
@ -22,7 +22,7 @@ get_json_value() {
|
|||
}
|
||||
|
||||
add_cron_api() {
|
||||
local currentTimeStamp=$(date +%s%3)
|
||||
local currentTimeStamp=$(date +%s)
|
||||
if [ $# -eq 1 ]; then
|
||||
local schedule=$(echo "$1" | awk -F ":" '{print $1}')
|
||||
local command=$(echo "$1" | awk -F ":" '{print $2}')
|
||||
|
@ -54,7 +54,7 @@ add_cron_api() {
|
|||
|
||||
del_cron_api() {
|
||||
local id=$1
|
||||
local currentTimeStamp=$(date +%s%3)
|
||||
local currentTimeStamp=$(date +%s)
|
||||
local api=$(curl "http://localhost:5678/api/crons/$id?t=$currentTimeStamp" \
|
||||
-X 'DELETE' \
|
||||
-H "Accept: application/json" \
|
||||
|
|
|
@ -15,7 +15,7 @@ if [[ $# -lt 2 ]] || [[ $# -gt 4 ]] ; then
|
|||
echo 'repo 仓储名'
|
||||
echo 'path 需要下载脚本的指定目录,多个目录 | 分割 path1 | path2'
|
||||
echo 'blacklist 需要排除的脚本名,多个名称 | 分割 blacklist1 | blacklist2'
|
||||
exit 0;
|
||||
exit 0
|
||||
fi
|
||||
|
||||
diyscriptsdir=/ql/diyscripts
|
||||
|
@ -29,7 +29,7 @@ if [ ! -d "$diyscriptsdir/${author}_${repo}" ]; then
|
|||
[ $gitpullstatus -ne 0 ] && echo -e "${author}本地仓库拉取失败,请检查!" && exit 0
|
||||
else
|
||||
cd ${diyscriptsdir}/${author}_${repo}
|
||||
branch=`git symbolic-ref --short -q HEAD`
|
||||
branch=$(git symbolic-ref --short -q HEAD)
|
||||
git fetch --all
|
||||
git reset --hard origin/$branch
|
||||
git pull
|
||||
|
@ -43,7 +43,7 @@ rand(){
|
|||
echo $(($num % $max + $min))
|
||||
}
|
||||
|
||||
function addnewcron {
|
||||
addnewcron() {
|
||||
addname=""
|
||||
cd ${diyscriptsdir}/${author}_${repo}
|
||||
express=$(find . -name "*.js")
|
||||
|
@ -53,14 +53,18 @@ function addnewcron {
|
|||
if [ $blackword ]; then
|
||||
express=$(find . -name "*.js" | egrep -v $blackword | egrep $path)
|
||||
fi
|
||||
for js in $express;
|
||||
do
|
||||
base=`basename $js`
|
||||
croname=`echo "${author}_$base"|awk -F\. '{print $1}'`
|
||||
script_date=`cat $js|grep ^[0-9]|awk '{print $1,$2,$3,$4,$5}'|egrep -v "[a-zA-Z]|:|\."|sort |uniq|head -n 1`
|
||||
[ -z "${script_date}" ] && script_date=`cat $js|grep -Eo "([0-9]+|\*|[0-9]+[,-].*) ([0-9]+|\*|[0-9]+[,-].*) ([0-9]+|\*|[0-9]+[,-].*) ([0-9]+|\*|[0-9]+[,-].*) ([0-9]+|\*|[0-9][,-].*)"|sort |uniq|head -n 1`
|
||||
for js in $express; do
|
||||
base=$(basename $js)
|
||||
croname=$(echo "${author}_$base" | awk -F\. '{print $1}')
|
||||
script_date=$(cat $js | grep ^[0-9] | awk '{print $1,$2,$3,$4,$5}' | egrep -v "[a-zA-Z]|:|\." | sort | uniq | head -n 1)
|
||||
[ -z "${script_date}" ] && script_date=$(cat $js | grep -Eo "([0-9]+|\*|[0-9]+[,-].*) ([0-9]+|\*|[0-9]+[,-].*) ([0-9]+|\*|[0-9]+[,-].*) ([0-9]+|\*|[0-9]+[,-].*) ([0-9]+|\*|[0-9][,-].*)" | sort | uniq | head -n 1)
|
||||
[ -z "${script_date}" ] && cron_min=$(rand 1 59) && cron_hour=$(rand 7 9) && script_date="${cron_min} ${cron_hour} * * *"
|
||||
[ $(grep -c -w "$croname" /ql/config/crontab.list) -eq 0 ] && sed -i "/hangup/a${script_date} js $croname" /ql/config/crontab.list && addname="${addname}\n${croname}" && echo -e "添加了新的脚本${croname}."
|
||||
local oldCron=$(grep -c -w "$croname" "$ListCronCurrent")
|
||||
if [[ oldCron -eq 0 ]]; then
|
||||
add_cron_api "$script_date" "js $croname" "$croname"
|
||||
addname="${addname}\n${croname}"
|
||||
echo -e "添加了新的脚本${croname}."
|
||||
fi
|
||||
if [ ! -f "/ql/scripts/${author}_$base" ]; then
|
||||
\cp $js /ql/scripts/${author}_$base
|
||||
else
|
||||
|
@ -72,21 +76,27 @@ function addnewcron {
|
|||
|
||||
}
|
||||
|
||||
function delcron {
|
||||
delcron() {
|
||||
delname=""
|
||||
cronfiles=$(grep "$author" /ql/config/crontab.list|grep -v "^#"|awk '{print $8}'|awk -F"${author}_" '{print $2}')
|
||||
for filename in $cronfiles;
|
||||
do
|
||||
if [ ! -f "${diyscriptsdir}/${author}_${repo}/${filename}.js" ]; then
|
||||
sed -i "/\<js ${author}_${filename}\>/d" /ql/config/crontab.list && echo -e "删除失效脚本${filename}."
|
||||
cronfiles=$(grep "$author" /ql/config/crontab.list | grep -v "^#" | perl -pe "s|.*ID=(.*) js (${author}_.*)\.*|\1:\2|")
|
||||
for filename in $cronfiles; do
|
||||
local id=$(echo "$1" | awk -F ":" '{print $1}')
|
||||
local name=$(echo "$1" | awk -F ":" '{print $2}')
|
||||
hasFile=$(cd ${diyscriptsdir}/${author}_${repo} && find . -name "$filename.js" | wc -l)
|
||||
if [[ $hasFile != 0 ]]; then
|
||||
del_cron_api "$id"
|
||||
echo -e "删除失效脚本${name}."
|
||||
delname="${delname}\n${author}_${filename}"
|
||||
fi
|
||||
done
|
||||
[ "$delname" != "" ] && notify "删除 ${author} 失效脚本" "${delname}"
|
||||
}
|
||||
|
||||
if [[ ${gitpullstatus} -eq 0 ]]
|
||||
then
|
||||
. $ShellDir/shell/variables.sh
|
||||
. $ShellDir/shell/api.sh
|
||||
get_token
|
||||
|
||||
if [[ ${gitpullstatus} -eq 0 ]]; then
|
||||
addnewcron
|
||||
delcron
|
||||
else
|
||||
|
|
|
@ -1,39 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
## 常量
|
||||
ShellDir=${QL_DIR:-$(
|
||||
cd $(dirname $0)
|
||||
pwd
|
||||
)}
|
||||
[[ $QL_DIR ]] && ShellJs=js
|
||||
LogDir=$ShellDir/log
|
||||
[ ! -d $LogDir ] && mkdir -p $LogDir
|
||||
DbDir=$ShellDir/db
|
||||
[ ! -d $DbDir ] && mkdir -p $DbDir
|
||||
ManualLogDir=$ShellDir/manual_log
|
||||
[ ! -d $ManualLogDir ] && mkdir -p $ManualLogDir
|
||||
ScriptsDir=$ShellDir/scripts
|
||||
ConfigDir=$ShellDir/config
|
||||
FileConf=$ConfigDir/config.sh
|
||||
CookieConf=$ConfigDir/cookie.sh
|
||||
AuthConf=$ConfigDir/auth.json
|
||||
ExtraShell=$ConfigDir/extra.sh
|
||||
FileConfSample=$ShellDir/sample/config.sh.sample
|
||||
ListCronSample=$ShellDir/sample/crontab.list.sample
|
||||
ListCronCurrent=$ConfigDir/crontab.list
|
||||
ListCronRemote=$ScriptsDir/docker/crontab_list.sh
|
||||
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
|
||||
ScriptsURL=https://github.com.cnpmjs.org/gossh520/jd_scripts
|
||||
|
||||
Import_Conf() {
|
||||
if [ ! -s $FileConf ]; then
|
||||
echo -e "复制一份 $FileConfSample 示例配置文件\n\n"
|
||||
|
@ -45,8 +11,6 @@ Import_Conf() {
|
|||
fi
|
||||
[ -f $CookieConf ] && . $CookieConf
|
||||
[ -f $FileConf ] && . $FileConf
|
||||
|
||||
. $ShellDir/shell/api.sh
|
||||
}
|
||||
|
||||
# 更新shell
|
||||
|
@ -201,7 +165,7 @@ Git_Pull_Scripts_Next() {
|
|||
|
||||
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|.*ID=(.*)$ShellJs (j[drx]_\w+)\.*|\1|" | sort -u >$ListCurrentTask
|
||||
cat $ListCronCurrent | grep -E "$ShellJs j[drx]_\w+" | perl -pe "s|.*ID=(.*)$ShellJs (j[drx]_\w+)\.*|\1:\2|" | sort -u >$ListCurrentTask
|
||||
if [ -s $ListCurrentTask ]; then
|
||||
grep -vwf $ListCurrentTask $ListRemoteTask >$ListJsAdd
|
||||
else
|
||||
|
@ -221,7 +185,9 @@ Del_Cron() {
|
|||
echo
|
||||
JsDrop=$(cat $ListJsDrop)
|
||||
for Cron in $JsDrop; do
|
||||
del_cron_api "$Cron"
|
||||
local id=$(echo "$1" | awk -F ":" '{print $1}')
|
||||
local name=$(echo "$1" | awk -F ":" '{print $2}')
|
||||
del_cron_api "$id"
|
||||
done
|
||||
crontab $ListCronCurrent
|
||||
echo -e "成功删除失效的脚本与定时任务\n"
|
||||
|
@ -234,10 +200,12 @@ Add_Cron() {
|
|||
echo -e "开始尝试自动添加定时任务\n"
|
||||
JsAdd=$(cat $ListJsAdd)
|
||||
for Cron in $JsAdd; do
|
||||
if [[ $Cron == jd_bean_sign ]]; then
|
||||
echo "4 0,9 * * * $ShellJs $Cron" >> $ListCronCurrent
|
||||
local id=$(echo "$1" | awk -F ":" '{print $1}')
|
||||
local name=$(echo "$1" | awk -F ":" '{print $2}')
|
||||
if [[ $name == jd_bean_sign ]]; then
|
||||
echo "4 0,9 * * * $ShellJs $name" >>$ListCronCurrent
|
||||
else
|
||||
param=$(cat $ListCronRemote | grep -E "\/$Cron\." | perl -pe "s|(^.+)node */scripts/(j[drx]_\w+)\.js.+|\1\: $ShellJs \2: \2|")
|
||||
param=$(cat $ListCronRemote | grep -E "\/$name\." | perl -pe "s|(^.+)node */scripts/(j[drx]_\w+)\.js.+|\1\:$ShellJs \2:\2|")
|
||||
add_cron_api "$param"
|
||||
fi
|
||||
done
|
||||
|
@ -275,11 +243,13 @@ fi
|
|||
echo -e "\nJS脚本目录:$ScriptsDir\n"
|
||||
echo -e "--------------------------------------------------------------\n"
|
||||
|
||||
. $ShellDir/shell/variables.sh
|
||||
. $ShellDir/shell/api.sh
|
||||
get_token
|
||||
|
||||
Import_Conf
|
||||
Random_Pull_Cron
|
||||
|
||||
get_token
|
||||
|
||||
# 更新shell
|
||||
[ -f $ShellDir/package.json ] && PanelDependOld=$(cat $ShellDir/package.json)
|
||||
Git_Pull_Shell
|
||||
|
|
34
shell/variables.sh
Executable file
34
shell/variables.sh
Executable file
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
ShellDir=${QL_DIR:-$(
|
||||
cd $(dirname $0)
|
||||
pwd
|
||||
)}
|
||||
[[ $QL_DIR ]] && ShellJs=js
|
||||
LogDir=$ShellDir/log
|
||||
[ ! -d $LogDir ] && mkdir -p $LogDir
|
||||
DbDir=$ShellDir/db
|
||||
[ ! -d $DbDir ] && mkdir -p $DbDir
|
||||
ManualLogDir=$ShellDir/manual_log
|
||||
[ ! -d $ManualLogDir ] && mkdir -p $ManualLogDir
|
||||
ScriptsDir=$ShellDir/scripts
|
||||
ConfigDir=$ShellDir/config
|
||||
FileConf=$ConfigDir/config.sh
|
||||
CookieConf=$ConfigDir/cookie.sh
|
||||
AuthConf=$ConfigDir/auth.json
|
||||
ExtraShell=$ConfigDir/extra.sh
|
||||
FileConfSample=$ShellDir/sample/config.sh.sample
|
||||
ListCronSample=$ShellDir/sample/crontab.list.sample
|
||||
ListCronCurrent=$ConfigDir/crontab.list
|
||||
ListCronRemote=$ScriptsDir/docker/crontab_list.sh
|
||||
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
|
||||
ScriptsURL=https://github.com.cnpmjs.org/gossh520/jd_scripts
|
Loading…
Reference in New Issue
Block a user