diff --git a/sample/config.sample.sh b/sample/config.sample.sh index 5c02cbe1..28aaa332 100644 --- a/sample/config.sample.sh +++ b/sample/config.sample.sh @@ -75,7 +75,7 @@ RepoBranch2="" RepoPath1="" RepoPath2="" -## 启用其他开发者的仓库方式二(选填):只下载想要的文件,针对同一个仓库,方式一和方式二只能选择一种。 +## 启用其他开发者的仓库方式二(选填):只下载想要的文件,针对同一个脚本,方式一和方式二建议只选择一种。 ## 请先确认你能正常下载该raw文件才列在下方,无论是github还是gitee,请只填入 raw 文件链接。 ## 一行一个文件下载链接,首尾一对半角括号,示例: ## RawUrl=( diff --git a/sample/crontab.sample.list b/sample/crontab.sample.list index 358429a3..c24ccfde 100644 --- a/sample/crontab.sample.list +++ b/sample/crontab.sample.list @@ -1,10 +1,11 @@ # 更新所有脚本 55 2,13 * * * CMD_UPDATE all -# 重新build面板 +# 重构面板 # 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 命令 +# 如果由本程序自动添加的任务你不想运行,注释即可,不要删除,请在最后保留一个空行 diff --git a/shell/git_diy.sh b/shell/git_diy.sh deleted file mode 100755 index 839c6fe8..00000000 --- a/shell/git_diy.sh +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env bash -#author:spark thanks to: https://github.com/sparkssssssss/scripts - -ShellDir=${QL_DIR:-$( - cd $(dirname $0) - pwd -)} -[[ $QL_DIR ]] && ShellJs=js -ConfigDir=$ShellDir/config -ListCronCurrent=$ConfigDir/crontab.list -AuthConf=$ConfigDir/auth.json - -declare -A BlackListDict -author=$1 -repo=$2 -path=$3 -blackword=$4 - -if [[ $# -lt 2 ]] || [[ $# -gt 4 ]]; then - echo 'Desc: 用户拉取指定用户的指定仓储' - echo 'Usage: diy ' - - echo 'auth 作者名' - echo 'repo 仓储名' - echo 'path 需要下载脚本的指定目录,多个目录 | 分割 path1 | path2' - echo 'blacklist 需要排除的脚本名,多个名称 | 分割 blacklist1 | blacklist2' - exit 0 -fi - -diyscriptsdir=/ql/diyscripts -mkdir -p ${diyscriptsdir} - -if [ ! -d "$diyscriptsdir/${author}_${repo}" ]; then - echo -e "${author}本地仓库不存在,从gayhub拉取ing..." - cd ${diyscriptsdir} && git clone https://ghproxy.com/https://github.com/${author}/${repo} ${author}_${repo} - gitpullstatus=$? - [ $gitpullstatus -eq 0 ] && echo -e "${author}本地仓库拉取完毕" - [ $gitpullstatus -ne 0 ] && echo -e "${author}本地仓库拉取失败,请检查!" && exit 0 -else - cd ${diyscriptsdir}/${author}_${repo} - branch=$(git symbolic-ref --short -q HEAD) - git fetch --all - git reset --hard origin/$branch - git pull - gitpullstatus=$? -fi - -rand() { - min=$1 - max=$(($2 - $min + 1)) - num=$(cat /proc/sys/kernel/random/uuid | cksum | awk -F ' ' '{print $1}') - echo $(($num % $max + $min)) -} - -addnewcron() { - addname="" - cd ${diyscriptsdir}/${author}_${repo} - express=$(find . -name "*.js") - if [ $path ]; then - express=$(find . -name "*.js" | egrep $path) - fi - 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) - [ -z "${script_date}" ] && cron_min=$(rand 1 59) && cron_hour=$(rand 7 9) && script_date="${cron_min} ${cron_hour} * * *" - local oldCron=$(grep -c -w "$croname" "$ListCronCurrent") - if [[ oldCron -eq 0 ]]; then - local name=$(cat "$js" | grep -E "new Env\(" | perl -pe "s|(^.+)new Env\(\'*\"*(.+?)'*\"*\).+|\2|") - add_cron_api "$script_date" "js $croname" "$name" - addname="${addname}\n${croname}" - echo -e "添加了新的脚本${croname}." - fi - if [ ! -f "/ql/scripts/${author}_$base" ]; then - \cp $js /ql/scripts/${author}_$base - else - change=$(diff $js /ql/scripts/${author}_$base) - [ -n "${change}" ] && \cp $js /ql/scripts/${author}_$base && echo -e "${author}_$base 脚本更新了." - fi - done - [ "$addname" != "" ] && notify "新增 ${author} 自定义脚本" "${addname}" - -} - -delcron() { - delname="" - 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}" -} - -. $ShellDir/shell/api.sh -get_token - -if [[ ${gitpullstatus} -eq 0 ]]; then - addnewcron - delcron -else - echo -e "$author 仓库更新失败了." - notify "自定义仓库更新失败" "$author" -fi - -exit 0 diff --git a/shell/git_pull.sh b/shell/git_pull.sh deleted file mode 100755 index 2d2629db..00000000 --- a/shell/git_pull.sh +++ /dev/null @@ -1,300 +0,0 @@ -#!/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://ghproxy.com/https://github.com/whyour/qinglong -ScriptsURL=https://ghproxy.com/https://github.com/gossh520/jd_scripts - -Import_Conf() { - if [ ! -s $FileConf ]; then - echo -e "复制一份 $FileConfSample 示例配置文件\n\n" - cp -fv $FileConfSample $FileConf - fi - if [ ! -s $ListCronCurrent ]; then - echo -e "复制一份 $ListCronSample 基础定时任务\n\n" - cp -fv $ListCronSample $ListCronCurrent - fi - [ -f $CookieConf ] && . $CookieConf - [ -f $FileConf ] && . $FileConf -} - -# 更新shell -Git_Pull_Shell() { - echo -e "更新shell...\n" - cd $ShellDir - git remote set-url origin $ShellURL - git fetch --all - ExitStatusShell=$? - git reset --hard origin/master - git pull -} - -Git_Pull_Shell_Next() { - if [[ $ExitStatusShell -eq 0 ]]; then - echo -e "更新shell成功...\n" - [ ! -d $ShellDir/node_modules ] && Npm_Install panel - [ -f $ShellDir/package.json ] && PanelDependNew=$(cat $ShellDir/package.json) - [[ "$PanelDependOld" != "$PanelDependNew" ]] && cd $ShellDir && Npm_Install panel - cp -f $FileConfSample $ConfigDir/config.sh.sample - Notify_Version - else - echo -e "更新shell失败,请检查原因...\n" - fi -} - -## npm install -Npm_Install() { - echo -e "检测到 $1 的依赖包有变化,运行 npm install...\n" - Npm_InstallSub - if [ $? -ne 0 ]; then - echo -e "\nnpm install 运行不成功,自动删除 $1/node_modules 后再次尝试一遍..." - rm -rf node_modules - fi - echo - - if [ ! -d node_modules ]; then - echo -e "运行 npm install...\n" - Npm_InstallSub - if [ $? -ne 0 ]; then - echo -e "\nnpm install 运行不成功,自动删除 $1/node_modules...\n" - echo -e "请进入 $1 目录后手动运行 npm install...\n" - echo -e "3...\n" - sleep 1 - echo -e "2...\n" - sleep 1 - echo -e "1...\n" - sleep 1 - rm -rf node_modules - fi - fi -} - -## npm install 子程序,判断是否为安卓,判断是否安装有yarn -function Npm_InstallSub() { - if [ -n "$isTermux" ]; then - npm install --no-save --no-bin-links --registry=https://registry.npm.taobao.org || npm install --no-bin-links --no-save - elif ! type yarn >/dev/null 2>&1; then - npm install --no-save --registry=https://registry.npm.taobao.org || npm install --no-save - else - echo -e "检测到本机安装了 yarn,使用 yarn 替代 npm...\n" - yarn install --registry=https://registry.npm.taobao.org || yarn install - fi -} - -## 检测配置文件版本 -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 "$SendVersion" ] && [[ $(cat $SendVersion) != $VerConfSample ]] && rm -f $SendVersion - - ## 识别出更新日期和更新内容 - 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 $SendVersion ]; 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 $SendVersion ] && rm -f $SendVersion - fi -} - -## 每天次数随机,更新时间随机,更新秒数随机,至少6次,至多12次,大部分为8-10次,符合正态分布。 -Random_Pull_Cron() { - if [[ $(date "+%-H") -le 2 ]]; 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|" $ListCronCurrent - crontab $ListCronCurrent - fi -} - -## 克隆scripts -Git_Clone_Scripts() { - git clone -b master $ScriptsURL $ScriptsDir - ExitStatusScripts=$? -} - -## 更新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|.*ID=(.*) $ShellJs (j[drx]_\w+)\.*|\2|" | 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 - local id=$(cat $ListCronCurrent | grep -E "js $Cron" | perl -pe "s|.*ID=(.*) js $Cron|\1|") - del_cron_api "$id" - 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 - local name=$(cat "$ScriptsDir/$Cron.js" | grep -E "new Env\(" | perl -pe "s|(^.+)new Env\(\'*\"*(.+?)'*\"*\).+|\2|") - add_cron_api "4 0,9 * * *" "$ShellJs $Cron" "$name" - else - local name=$(cat "$ScriptsDir/$Cron.js" | grep -E "new Env\(" | perl -pe "s|(^.+)new Env\(\'*\"*(.+?)'*\"*\).+|\2|") - local param=$(cat $ListCronRemote | grep -E "\/$Cron\." | perl -pe "s|(^.+) node */scripts/(j[drx]_\w+)\.js.+|\1\:$ShellJs \2|") - add_cron_api "$param:$name" - fi - done - - if [ $? -eq 0 ]; then - crontab $ListCronCurrent - echo -e "成功添加新的定时任务...\n" - notify "新增lxk0301脚本" "$JsAdd" - else - echo -e "添加新的定时任务出错,请手动添加...\n" - notify "尝试自动添加lxk0301以下新的定时任务出错,请手动添加:" "$JsAdd" - 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 -n "系统时间:" -echo $(date "+%Y-%m-%d %H:%M:%S") -if [ "${TZ}" = "UTC" ]; then - echo -n "北京时间:" - echo $(date -d "8 hour" "+%Y-%m-%d %H:%M:%S") -fi -echo -e "\nJS脚本目录:$ScriptsDir\n" -echo -e "--------------------------------------------------------------\n" - -. $ShellDir/shell/api.sh -get_token - -Import_Conf - -# 更新shell -[ -f $ShellDir/package.json ] && PanelDependOld=$(cat $ShellDir/package.json) -Git_Pull_Shell -Git_Pull_Shell_Next - -## 更新scripts -[ -f $ScriptsDir/package.json ] && ScriptsDependOld=$(cat $ScriptsDir/package.json) -Git_Pull_Scripts -Git_Pull_Scripts_Next - -## 调用用户自定义的extra.sh -if [[ $EnableExtraShell == true ]]; then - if [ -f $ExtraShell ]; then - . $ExtraShell - else - echo -e "$ExtraShell 文件不存在,跳过执行DIY脚本...\n" - fi -fi diff --git a/shell/js.sh b/shell/js.sh deleted file mode 100755 index e369810e..00000000 --- a/shell/js.sh +++ /dev/null @@ -1,283 +0,0 @@ -#!/usr/bin/env bash - -## 路径 -ShellDir=${QL_DIR:-$(cd $(dirname $0); pwd)} -[[ ${QL_DIR} ]] && ShellJS=js -ScriptsDir=${ShellDir}/scripts -ConfigDir=${ShellDir}/config -FileConf=${ConfigDir}/config.sh -CookieConf=${ConfigDir}/cookie.sh -FileConfSample=${ShellDir}/sample/config.sh.sample -LogDir=${ShellDir}/log -ListScripts=($(cd ${ScriptsDir}; ls *.js | grep -E "j[drx]_")) -ListCron=${ConfigDir}/crontab.list -ListCronLxk=${ScriptsDir}/docker/crontab_list.sh -ListJs=${LogDir}/js.list - -## 导入config.sh -function Import_Conf { - if [ -f ${FileConf} ] - then - . ${CookieConf} - . ${FileConf} - if [[ ! -s ${CookieConf} ]]; then - echo -e "请先在Cookie管理中添加一条Cookie...\n" - exit 1 - fi - else - echo -e "配置文件 ${FileConf} 不存在,请先按教程配置好该文件...\n" - exit 1 - fi -} - -## 更新crontab -function Detect_Cron { - if [[ $(cat ${ListCron}) != $(crontab -l) ]]; then - crontab ${ListCron} - fi -} - -## 用户数量UserSum -function Count_UserSum { - UserSum=0 - for line in `cat $CookieConf` - do - ((UserSum++)) - eval Cookie${UserSum}="\"${line}\"" - done -} - -## 组合Cookie和互助码子程序 -function Combin_Sub { - CombinAll="" - if [[ ${AutoHelpOther} == true ]] && [[ $1 == ForOther* ]]; then - - ForOtherAll="" - MyName=$(echo $1 | perl -pe "s|ForOther|My|") - - for ((m=1; m<=${UserSum}; m++)); do - TmpA=${MyName}$m - TmpB=${!TmpA} - ForOtherAll="${ForOtherAll}@${TmpB}" - done - - for ((n=1; n<=${UserSum}; n++)); do - for num in ${TempBlockCookie}; do - [[ $n -eq $num ]] && continue 2 - done - CombinAll="${CombinAll}&${ForOtherAll}" - done - - else - for ((i=1; i<=${UserSum}; i++)); do - for num in ${TempBlockCookie}; do - [[ $i -eq $num ]] && continue 2 - done - Tmp1=$1$i - Tmp2=${!Tmp1} - CombinAll="${CombinAll}&${Tmp2}" - done - fi - - echo ${CombinAll} | perl -pe "{s|^&||; s|^@+||; s|&@|&|g; s|@+&|&|g; s|@+|@|g; s|@+$||}" -} - -## 组合Cookie、Token与互助码 -function Combin_All { - export JD_COOKIE=$(Combin_Sub Cookie) - export FRUITSHARECODES=$(Combin_Sub ForOtherFruit) - export PETSHARECODES=$(Combin_Sub ForOtherPet) - export PLANT_BEAN_SHARECODES=$(Combin_Sub ForOtherBean) - export DREAM_FACTORY_SHARE_CODES=$(Combin_Sub ForOtherDreamFactory) - export DDFACTORY_SHARECODES=$(Combin_Sub ForOtherJdFactory) - export JDZZ_SHARECODES=$(Combin_Sub ForOtherJdzz) - export JDJOY_SHARECODES=$(Combin_Sub ForOtherJoy) - export JXNC_SHARECODES=$(Combin_Sub ForOtherJxnc) - export JXNCTOKENS=$(Combin_Sub TokenJxnc) - export BOOKSHOP_SHARECODES=$(Combin_Sub ForOtherBookShop) - export JD_CASH_SHARECODES=$(Combin_Sub ForOtherCash) - export JDSGMH_SHARECODES=$(Combin_Sub ForOtherSgmh) - export JDCFD_SHARECODES=$(Combin_Sub ForOtherCfd) - export JDGLOBAL_SHARECODES=$(Combin_Sub ForOtherGlobal) -} - -## 转换JD_BEAN_SIGN_STOP_NOTIFY或JD_BEAN_SIGN_NOTIFY_SIMPLE -function Trans_JD_BEAN_SIGN_NOTIFY { - case ${NotifyBeanSign} in - 0) - export JD_BEAN_SIGN_STOP_NOTIFY="true" - ;; - 1) - export JD_BEAN_SIGN_NOTIFY_SIMPLE="true" - ;; - esac -} - -## 转换UN_SUBSCRIBES -function Trans_UN_SUBSCRIBES { - export UN_SUBSCRIBES="${goodPageSize}\n${shopPageSize}\n${jdUnsubscribeStopGoods}\n${jdUnsubscribeStopShop}" -} - -## 申明全部变量 -function Set_Env { - Count_UserSum - Combin_All - Trans_JD_BEAN_SIGN_NOTIFY - Trans_UN_SUBSCRIBES -} - -## 随机延迟 -function Random_Delay { - if [[ -n ${RandomDelay} ]] && [[ ${RandomDelay} -gt 0 ]]; then - CurMin=$(date "+%-M") - if [[ ${CurMin} -gt 2 && ${CurMin} -lt 30 ]] || [[ ${CurMin} -gt 31 && ${CurMin} -lt 59 ]]; then - CurDelay=$((${RANDOM} % ${RandomDelay} + 1)) - echo -e "\n命令未添加 \"now\",随机延迟 ${CurDelay} 秒后再执行任务,如需立即终止,请按 CTRL+C...\n" - sleep ${CurDelay} - fi - fi -} - -## 使用说明 -function Help { - echo -e "本脚本的用法为:" - echo -e "1. ${ShellJS} xxx # 如果设置了随机延迟并且当时时间不在0-2、30-31、59分内,将随机延迟一定秒数" - echo -e "2. ${ShellJS} xxx now # 无论是否设置了随机延迟,均立即运行" - echo -e "3. ${ShellJS} runall # 运行所有非挂机脚本,非常耗时" - echo -e "4. ${ShellJS} hangup # 重启挂机程序" - echo -e "5. ${ShellJS} resetpwd # 重置控制面板用户名和密码" - echo -e "\n针对用法1、用法2中的\"xxx\",可以不输入后缀\".js\",另外,如果前缀是\"jd_\"的话前缀也可以省略。" - echo -e "当前有以下脚本可以运行(仅列出以jd_、jr_、jx_开头的脚本):" - cd ${ScriptsDir} - for ((i=0; i<${#ListScripts[*]}; i++)); do - Name=$(grep "new Env" ${ListScripts[i]} | awk -F "'|\"" '{print $2}') - echo -e "$(($i + 1)).${Name}:${ListScripts[i]}" - done -} - -## nohup -function Run_Nohup { - if [[ $(ps -ef | grep "${js}" | grep -v "grep") != "" ]]; then - ps -ef | grep "${js}" | grep -v "grep" | awk '{print $2}' | xargs kill -9 - fi - [ ! -d ${LogDir}/${js} ] && mkdir -p ${LogDir}/${js} - LogTime=$(date "+%Y-%m-%d-%H-%M-%S") - LogFile="${LogDir}/${js}/${LogTime}.log" - nohup node ${js}.js > ${LogFile} & -} - -## 运行挂机脚本 -function Run_HangUp { - HangUpJs="jd_crazy_joy_coin" - cd ${ScriptsDir} - for js in ${HangUpJs}; do - Import_Conf ${js} && Set_Env - if type pm2 >/dev/null 2>&1; then - pm2 stop ${js}.js 2>/dev/null - pm2 flush - pm2 start -a ${js}.js --watch "${ScriptsDir}/${js}.js" --name="${js}" - else - Run_Nohup >/dev/null 2>&1 - fi - done -} - -## 重置密码 -function Reset_Pwd { - cp -f ${ShellDir}/sample/auth.json ${ConfigDir}/auth.json - echo -e "控制面板重置成功,用户名:admin,密码:adminadmin\n" -} - -## 一次性运行所有脚本 -function Run_All { - if [ ! -f ${ListJs} ]; then - cat ${ListCronLxk} | grep -E "j[drx]_\w+\.js" | perl -pe "s|.+(j[drx]_\w+)\.js.+|\1|" | sort -u > ${ListJs} - fi - echo -e "\n==================== 开始运行所有非挂机脚本 ====================\n" - echo -e "请注意:本过程将非常非常耗时,一个账号可能长达几小时,账号越多耗时越长,如果是手动运行,退出终端也将终止运行。\n" - echo -e "倒计时5秒...\n" - for ((sec=5; sec>0; sec--)); do - echo -e "$sec...\n" - sleep 1 - done - for file in $(cat ${ListJs}); do - echo -e "==================== 运行 $file.js 脚本 ====================\n" - ${ShellJS} $file now - done -} - -## 正常运行单个脚本 -function Run_Normal { - Import_Conf $1 && Detect_Cron && Set_Env - - FileNameTmp1=$(echo $1 | perl -pe "s|\.js||") - FileNameTmp2=$(echo $1 | perl -pe "{s|jd_||; s|\.js||; s|^|jd_|}") - SeekDir="${ScriptsDir} ${ScriptsDir}/backUp ${ConfigDir}" - FileName="" - WhichDir="" - - for dir in ${SeekDir} - do - if [ -f ${dir}/${FileNameTmp1}.js ]; then - FileName=${FileNameTmp1} - WhichDir=${dir} - break - elif [ -f ${dir}/${FileNameTmp2}.js ]; then - FileName=${FileNameTmp2} - WhichDir=${dir} - break - fi - done - - if [ -n "${FileName}" ] && [ -n "${WhichDir}" ] - then - [ $# -eq 1 ] && Random_Delay - LogTime=$(date "+%Y-%m-%d-%H-%M-%S") - LogFile="${LogDir}/${FileName}/${LogTime}.log" - [ ! -d ${LogDir}/${FileName} ] && mkdir -p ${LogDir}/${FileName} - cd ${WhichDir} - node ${FileName}.js 2>&1 | tee ${LogFile} - else - echo -e "\n在${ScriptsDir}、${ScriptsDir}/backUp、${ConfigDir}三个目录下均未检测到 $1 脚本的存在,请确认...\n" - Help - fi -} - -## 命令检测 -case $# in - 0) - echo - Help - ;; - 1) - case $1 in - hangup) - Run_HangUp - ;; - resetpwd) - Reset_Pwd - ;; - runall) - Run_All - ;; - *) - Run_Normal $1 - ;; - esac - ;; - 2) - case $2 in - now) - Run_Normal $1 $2 - ;; - *) - echo -e "\n命令输入错误...\n" - Help - ;; - esac - ;; - *) - echo -e "\n命令过多...\n" - Help - ;; -esac \ No newline at end of file diff --git a/shell/task.sh b/shell/task.sh index fc84bc82..cf92080e 100644 --- a/shell/task.sh +++ b/shell/task.sh @@ -71,6 +71,7 @@ random_delay () { ## scripts目录下所有可运行脚本数组 gen_array_scripts () { + count_own_repo_sum gen_own_dir_and_path local dir_current=$(pwd) local i=0 @@ -91,14 +92,14 @@ gen_array_scripts () { ## 使用说明 usage () { define_cmd - echo -e "\ntask命令运行本程序自动添加进crontab的脚本,需要输入脚本的绝对路径或相对路径(定时任务中必须是从scripts目录出发的相对路径),用法为:" + echo -e "\ntask命令运行本程序自动添加进crontab的脚本,需要输入脚本的绝对路径或相对路径(定时任务中建议写作去掉 $dir_scripts 目录后的相对路径),用法为:" echo -e "1.$cmd_task # 依次执行,如果设置了随机延迟并且当时时间不在0-2、30-31、59分内,将随机延迟一定秒数" echo -e "2.$cmd_task now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中" echo -e "3.$cmd_task conc # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中" echo -e "\nmytask命令运行未识别出cron的脚本以及你自己添加的脚本,用法同task。mytask和task命令均为同一脚本的不同名字,二者仅用来在crontab.list中区分不同类型的任务,以方便自动增删任务,手动直接运行task即可。" echo -e "\n当前有以下脚本可以运行:" for ((i=0; i<${#array_scripts[*]}; i++)); do - echo -e "$(($i + 1)).${array_scripts_name[i]}:${array_scripts[i]}" + echo -e "$(($i + 1)). ${array_scripts_name[i]}:${array_scripts[i]}" done }