重构shell (#17)

* dev

Co-authored-by: anonymous <anonymous@gmail.com>
This commit is contained in:
nevinee 2021-04-11 20:28:53 +08:00 committed by GitHub
parent 17c50d0c9e
commit d3cd3256ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 1813 additions and 1605 deletions

View File

@ -1,7 +1,7 @@
FROM node:lts-alpine FROM node:lts-alpine
LABEL maintainer="whyour" LABEL maintainer="whyour"
ARG QL_BASE_URL=https://github.com.cnpmjs.org/whyour/qinglong ARG QL_URL=https://github.com.cnpmjs.org/whyour/qinglong
ARG QL_BASE_BRANCH=master ARG QL_BRANCH=master
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
LANG=zh_CN.UTF-8 \ LANG=zh_CN.UTF-8 \
SHELL=/bin/bash \ SHELL=/bin/bash \
@ -23,21 +23,19 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
openssl \ openssl \
nginx \ nginx \
python3 \ python3 \
yarn \
jq \ jq \
&& rm -rf /var/cache/apk/* \ && rm -rf /var/cache/apk/* \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \ && echo "Asia/Shanghai" > /etc/timezone \
&& touch ~/.bashrc \ && touch ~/.bashrc \
&& mkdir /run/nginx \ && mkdir /run/nginx \
&& git clone -b ${QL_BASE_BRANCH} ${QL_BASE_URL} ${QL_DIR} \ && git clone -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
&& cd ${QL_DIR} \ && cd ${QL_DIR} \
&& cp -f .env.example .env \ && cp -f .env.example .env \
&& ln -sf ${QL_DIR}/shell/js.sh /usr/local/bin/js \ && ln -sf ${QL_DIR}/shell/task.sh /usr/local/bin/task \
&& ln -sf ${QL_DIR}/shell/git_pull.sh /usr/local/bin/git_pull \ && ln -sf ${QL_DIR}/shell/task.sh /usr/local/bin/mytask \
&& ln -sf ${QL_DIR}/shell/rm_log.sh /usr/local/bin/rm_log \ && ln -sf ${QL_DIR}/shell/update.sh /usr/local/bin/update \
&& ln -sf ${QL_DIR}/shell/export_sharecodes.sh /usr/local/bin/export_sharecodes \ && ln -sf ${QL_DIR}/shell/rmlog.sh /usr/local/bin/rmlog \
&& ln -sf ${QL_DIR}/shell/git_diy.sh /usr/local/bin/diy \
&& ln -sf ${QL_DIR}/shell/notify.sh /usr/local/bin/notify \ && ln -sf ${QL_DIR}/shell/notify.sh /usr/local/bin/notify \
&& ln -sf ${QL_DIR}/shell/rebuild.sh /usr/local/bin/rebuild \ && ln -sf ${QL_DIR}/shell/rebuild.sh /usr/local/bin/rebuild \
&& ln -sf ${QL_DIR}/docker/docker-entrypoint.sh /usr/local/bin/entrypoint \ && ln -sf ${QL_DIR}/docker/docker-entrypoint.sh /usr/local/bin/entrypoint \

63
docker/docker-entrypoint.sh Executable file → Normal file
View File

@ -1,73 +1,58 @@
#!/bin/bash #!/bin/bash
set -e set -e
echo -e "======================1. 检测配置文件========================\n" echo -e "======================1. 更新源代码========================\n"
update ql
echo
echo -e "======================2. 检测配置文件========================\n"
[ ! -d ${QL_DIR}/config ] && mkdir -p ${QL_DIR}/config [ ! -d ${QL_DIR}/config ] && mkdir -p ${QL_DIR}/config
if [ ! -s ${QL_DIR}/config/crontab.list ] if [ ! -s ${QL_DIR}/config/crontab.list ]
then then
echo -e "检测到config配置目录下不存在crontab.list或存在但文件为空从示例文件复制一份用于初始化...\n" echo -e "检测到config配置目录下不存在crontab.list或存在但文件为空从示例文件复制一份用于初始化...\n"
cp -fv ${QL_DIR}/sample/crontab.list.sample ${QL_DIR}/config/crontab.list cp -fv ${QL_DIR}/sample/crontab.sample.list ${QL_DIR}/config/crontab.list
sed -i "s,MY_PATH,${QL_DIR},g" ${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
sed -i "s,ENV_PATH=,PATH=$PATH,g" ${QL_DIR}/config/crontab.list
fi fi
crond
crontab ${QL_DIR}/config/crontab.list crontab ${QL_DIR}/config/crontab.list
echo -e "成功添加定时任务...\n" echo -e "成功添加定时任务...\n"
if [ ! -s ${QL_DIR}/config/cookie.sh ]; then if [ ! -s ${QL_DIR}/config/cookie.sh ]; then
echo -e "检测到config配置目录下不存在cookie.sh从示例文件复制一份用于初始化...\n" echo -e "检测到config配置目录下不存在cookie.sh从示例文件复制一份用于初始化...\n"
touch ${QL_DIR}/config/cookie.sh touch ${QL_DIR}/config/cookie.sh
echo echo
fi fi
if [ ! -s ${QL_DIR}/config/config.sh ]; then if [ ! -s ${QL_DIR}/config/config.sh ]; then
echo -e "检测到config配置目录下不存在config.sh从示例文件复制一份用于初始化...\n" echo -e "检测到config配置目录下不存在config.sh从示例文件复制一份用于初始化...\n"
cp -fv ${QL_DIR}/sample/config.sh.sample ${QL_DIR}/config/config.sh cp -fv ${QL_DIR}/sample/config.sample.sh ${QL_DIR}/config/config.sh
echo echo
fi fi
if [ ! -s ${QL_DIR}/config/auth.json ]; then if [ ! -s ${QL_DIR}/config/auth.sample.json ]; then
echo -e "检测到config配置目录下不存在auth.json从示例文件复制一份用于初始化...\n" echo -e "检测到config配置目录下不存在auth.json从示例文件复制一份用于初始化...\n"
cp -fv ${QL_DIR}/sample/auth.json ${QL_DIR}/config/auth.json cp -fv ${QL_DIR}/sample/auth.sample.json ${QL_DIR}/config/auth.json
echo echo
fi fi
if [ -s /etc/nginx/conf.d/default.conf ]; then if [ -s /etc/nginx/conf.d/default.conf ]; then
echo -e "检测到默认nginx配置文件删除...\n" echo -e "检测到默认nginx配置文件删除...\n"
rm -f /etc/nginx/conf.d/default.conf rm -f /etc/nginx/conf.d/default.conf
echo echo
fi fi
cp -fv ${QL_DIR}/docker/front.conf /etc/nginx/conf.d/front.conf cp -fv ${QL_DIR}/docker/front.conf /etc/nginx/conf.d/front.conf
echo -e "======================2. 启动nginx========================\n" echo -e "======================3. 启动nginx========================\n"
nginx -c /etc/nginx/nginx.conf nginx -c /etc/nginx/nginx.conf
echo echo
echo -e "======================3. 启动控制面板========================\n" echo -e "======================4. 启动控制面板========================\n"
pm2 start ${QL_DIR}/build/app.js -n panel pm2 start ${QL_DIR}/build/app.js -n panel
echo -e "控制面板启动成功...\n" echo -e "控制面板启动成功...\n"
echo -e "======================4. 更新源代码========================\n"
git_pull
echo
echo -e "======================5. 启动挂机程序========================\n"
CookieConf=${QL_DIR}/config/cookie.sh
. ${QL_DIR}/config/config.sh
. ${CookieConf}
if [ -s ${CookieConf} ]; then
js hangup 2>/dev/null
echo -e "挂机程序启动成功...\n"
else
echo -e "尚未在Cookie管理中添加一条Cookie可能是首次部署容器因此不启动挂机程序...\n"
fi
echo -e "\n容器启动成功...\n" echo -e "\n容器启动成功...\n"
if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ]; then crond -f
set -- node "$@"
fi
exec "$@" exec "$@"

88
sample/config.sample.sh Normal file
View File

@ -0,0 +1,88 @@
## Version: v2.0.0
## Date: 2021-04-07
## Update Content: 新一版qinglong。
## 上面版本号中如果第2位数字有变化那么代表增加了新的参数如果只有第3位数字有变化仅代表更新了注释没有增加新的参数可更新可不更新
## 临时屏蔽某个Cookie
## 多个Cookie编号以半角的空格分隔两侧一对半角双引号使用此功能后在运行脚本时账户编号将发生变化
## 举例1TempBlockCookie="2" 临时屏蔽掉Cookie2
## 举例2TempBlockCookie="2 4" 临时屏蔽掉Cookie2和Cookie4
TempBlockCookie=""
## 如果只是想要屏蔽某个账号不跑某一些脚本,可以参考下面 case 这个命令的例子来控制case的条件中请输入脚本从scripts目录出发的相对路径也就是在crontab.list中的task命令后面的脚本路径是什么这里就填入什么
## case $1 in
## lxk0301_jd_scripts/jd_fruit.js)
## TempBlockCookie="5" # 账号5不玩lxk0301_jd_scripts下的jd_fruit.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
## ;;
## 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
## 在运行 update 命令时,是否自动删除失效的脚本与定时任务
AutoDelCron="true"
## 在运行 update 命令时,是否自动增加新的本地定时任务
AutoAddCron="true"
## 运行 rmlog 命令时删除多久以前的日志,仅能输入正整数
RmLogDaysAgo="7"
## 在运行 task 或 mytask 命令时,随机延迟启动任务的最大延迟时间
## 如果任务不是必须准点运行的任务,那么给它增加一个随机延迟,由你定义最大延迟时间,单位为秒,如 RandomDelay="300" ,表示任务将在 1-300 秒内随机延迟一个秒数,然后再运行
## 在crontab.list中在每小时第0-2分、第30-31分、第59分这几个时间内启动的任务均算作必须准点运行的任务在启动这些任务时即使你定义了RandomDelay也将准点运行不启用随机延迟
## 在crontab.list中除掉每小时上述时间启动的任务外其他任务在你定义了 RandomDelay 的情况下,一律启用随机延迟,但如果你给某些任务添加了 "now" 或者 "conc",那么这些任务也将无视随机延迟直接启动
RandomDelay="300"
## 如果你自己会写shell脚本并且希望在每次运行 update 命令时,额外运行你的 shell 脚本,请赋值为 "true"
## 同时,请务必将你的脚本命名为 extra.sh (只能叫这个文件名),放在 config 目录下
EnableExtraShell=""
## 启用其他开发者的仓库方式一(选填):完整更新整个仓库,针对同一个仓库,方式一和方式二只能选择一种
## RepoUrl仓库地址清单必须从1开始依次编号
## RepoBranch你想使用的分支清单不指定分支即使用默认分支时可以用一对不包含内容的空引号"",编号必须和 OwnRepoUrl 对应。
## RepoPath要使用的脚本在仓库哪个路径下请输入仓库下的相对路径默认空值""代表仓库根目录,编号必须和 OwnRepoUrl 对应同一个仓库下不同文件夹之间使用空格分开。如果既包括根目录又包括子目录填写请见示例中OwnRepoPath3。
## 所有脚本存放在 own 目录下,三个清单必须一一对应,示例如下:
## RepoUrl1="https://gitee.com/abc/jdtsa.git"
## RepoUrl2="https://github.com/nedcd/jxddfsa.git"
## RepoUrl3="git@github.com:eject/poex.git"
##
## 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" 分支
##
## 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=""
RepoBranch1=""
RepoBranch2=""
RepoPath1=""
RepoPath2=""
## 启用其他开发者的仓库方式二(选填):只下载想要的文件,针对同一个脚本,方式一和方式二建议只选择一种。
## 请先确认你能正常下载该raw文件才列在下方无论是github还是gitee请只填入 raw 文件链接。
## 一行一个文件下载链接,首尾一对半角括号,示例:
## 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
## )
RawUrl=(
)

View File

@ -1,599 +0,0 @@
## Version: v3.30.6
## Date: 2021-3-8
## Update Content: 京小兑控制变量,宠汪汪自己内部账户互助变量,环球挑战赛互助变量。
## 上面版本号中如果第2位数字有变化那么代表增加了新的参数如果只有第3位数字有变化仅代表更新了注释没有增加新的参数可更新可不更新
################################## 说明 ##################################
## 以下配置中,带有 export 申明的均由LXK9301大佬定义详见https://gitee.com/lxk0301/jd_scripts/blob/master/githubAction.md
## 其他互助码考虑到直接按LXK9301大佬定义的变量去填的话一是不方便记忆二是容易搞混所以最终的变量将由脚本去组合你只要按注释去填即可
## 除此之外还额外增加了是否自动删除失效任务AutoDelCron、是否自动增加新任务AutoAddCron、删除旧日志时间RmLogDaysAgo、随机延迟启动任务RandomDelay、是否添加自定义脚本EnableExtraShell五个人性化的设置供选择
## 所有赋值等号两边不能有空格,所有的值请一律在两侧添加半角的双引号,如果变量值中含有双引号,则外侧改为一对半角的单引号。
## 所有的赋值都可以参考 “定义东东萌宠是否静默运行” 部分,在不同时间设置不同的值,以达到你想要的效果,具体判断条件如下:
## $(date "+%d") 当前的日期13
## $(date "+%w") 当前是星期几3
## $(date "+%H") 当前的小时数23
## $(date "+%M") 当前的分钟数49
## 其他date命令的更多用法可以在命令行中输入 date --help 查看
## 判断条件 -eq -ne -gt -ge -lt -le ,具体含义可百度一下
################################## 临时屏蔽某个Cookie选填 ##################################
## 如果某些Cookie已经失效了但暂时还没法更新可以使用此功能在不删除该Cookie和重新修改Cookie编号的前提下临时屏蔽掉某些编号的Cookie
## 多个Cookie编号以半角的空格分隔两侧一对半角双引号使用此功能后在运行js脚本时账户编号将发生变化
## 举例1TempBlockCookie="2" 临时屏蔽掉Cookie2
## 举例2TempBlockCookie="2 4" 临时屏蔽掉Cookie2和Cookie4
## 如果只是想要屏蔽某个账号不玩某些小游戏,可以参考下面 case 这个命令的例子来控制,脚本名称请去掉后缀 “.js”
## case $1 in
## jd_fruit)
## TempBlockCookie="5" # 账号5不玩东东农场
## ;;
## jd_dreamFactory | jd_jdfactory)
## TempBlockCookie="2" # 账号2不玩京喜工厂和东东工厂
## ;;
## jd_jdzz | jd_joy)
## TempBlockCookie="3 6" # 账号3、账号6不玩京东赚赚和宠汪汪
## ;;
## esac
TempBlockCookie=""
################################## 定义是否自动删除失效的脚本与定时任务(选填) ##################################
## 有的时候某些JS脚本只在特定的时间有效过了时间就失效了需要自动删除失效的本地定时任务则设置为 "true" ,否则请设置为 "false"
## 检测文件LXK9301/jd_scripts 仓库中的 docker/crontab_list.sh和 shylocks/Loon 仓库中的 docker/crontab_list.sh
## 当设置为 "true" 时会自动从检测文件中读取比对删除的任务识别以“jd_”、“jr_”、“jx_”开头的任务
## 当设置为 "true" 时脚本只会删除一整行失效的定时任务不会修改其他现有任务所以任何时候你都可以自己调整你的crontab.list
## 当设置为 "true" 时如果你有添加额外脚本是以“jd_”“jr_”“jx_”开头的如检测文件中会被删除不是以“jd_”“jr_”“jx_”开头的任务则不受影响
AutoDelCron="true"
################################## 定义是否自动增加新的本地定时任务(选填) ##################################
## LXK9301 大佬会在有需要的时候,增加定时任务,如需要本地自动增加新的定时任务,则设置为 "true" ,否则请设置为 "false"
## 检测文件LXK9301/jd_scripts 仓库中的 docker/crontab_list.sh和 shylocks/Loon 仓库中的 docker/crontab_list.sh
## 当设置为 "true" 时如果检测到检测文件中有增加新的定时任务那么在本地也增加识别以“jd_”、“jr_”、“jx_”开头的任务
## 当设置为 "true" 时,会自动从检测文件新增加的任务中读取时间,该时间为北京时间
## 当设置为 "true" 时脚本只会增加新的定时任务不会修改其他现有任务所以任何时候你都可以自己调整你的crontab.list
AutoAddCron="true"
################################## 定义删除日志的时间(选填) ##################################
## 定义在运行删除旧的日志任务时,要删除多少天以前的日志,请输入正整数,不填则禁用删除日志的功能
RmLogDaysAgo="7"
################################## 定义随机延迟启动任务(选填) ##################################
## 如果任务不是必须准点运行的任务,那么给它增加一个随机延迟,由你定义最大延迟时间,单位为秒,如 RandomDelay="300" ,表示任务将在 1-300 秒内随机延迟一个秒数,然后再运行
## 在crontab.list中在每小时第0-2分、第30-31分、第59分这几个时间内启动的任务均算作必须准点运行的任务在启动这些任务时即使你定义了RandomDelay也将准点运行不启用随机延迟
## 在crontab.list中除掉每小时上述时间启动的任务外其他任务在你定义了 RandomDelay 的情况下一律启用随机延迟但如果你按照Wiki教程给某些任务添加了 "now",那么这些任务也将无视随机延迟直接启动
RandomDelay="300"
################################## 定义User-Agent选填 ##################################
## 自定义LXK9301大佬仓库里京东系列js脚本的User-Agent不懂不知不会User-Agent的请不要随意填写内容随意填写了出错概不负责
## 如需使用,请自行解除下一行注释
# export JD_USER_AGENT=""
################################## 定义通知TOKEN选填 ##################################
## 想通过什么渠道收取通知,就填入对应渠道的值
## 1. ServerChan教程http://sc.ftqq.com/3.version
export PUSH_KEY=""
## 2. BARK教程看BARK_PUSH和BARK_SOUND的说明https://gitee.com/lxk0301/jd_scripts/blob/master/githubAction.md
export BARK_PUSH=""
export BARK_SOUND=""
## 3. Telegram如需使用TG_BOT_TOKEN和TG_USER_ID必须同时赋值教程https://gitee.com/lxk0301/jd_scripts/blob/master/backUp/TG_PUSH.md
export TG_BOT_TOKEN=""
export TG_USER_ID=""
## 4. 钉钉教程看DD_BOT_TOKEN和DD_BOT_SECRET部分https://gitee.com/lxk0301/jd_scripts/blob/master/githubAction.md
export DD_BOT_TOKEN=""
export DD_BOT_SECRET=""
## 5. iGot聚合推送支持多方式推送填写iGot的推送key。教程https://gitee.com/lxk0301/jd_scripts/blob/master/githubAction.md
export IGOT_PUSH_KEY=""
## 6. Push Plus微信扫码登录后一对一推送或一对多推送参考文档http://pushplus.hxtrip.com/
## 其中PUSH_PLUS_USER是一对多推送的“群组编码”一对多推送下面->您的群组(如无则新建)->群组编码)注:(1、需订阅者扫描二维码 2、如果您是创建群组所属人也需点击“查看二维码”扫描绑定否则不能接受群组消息推送)只填PUSH_PLUS_TOKEN默认为一对一推送
export PUSH_PLUS_TOKEN=""
export PUSH_PLUS_USER=""
## 7. 企业微信机器人消息推送 webhook 后面的 key文档https://work.weixin.qq.com/api/doc/90000/90136/91770
export QYWX_KEY=""
## 8. 企业微信应用消息推送的值教程https://note.youdao.com/ynoteshare1/index.html?id=351e08a72378206f9dd64d2281e9b83b&type=note
## 依次填上corpid的值,corpsecret的值,touser的值,agentid,media_id的值注意用,号隔开,例如:"wwcff56746d9adwers,B-791548lnzXBE6_BWfxdf3kSTMJr9vFEPKAbh6WERQ,mingcheng,1000001,2COXgjH2UIfERF2zxrtUOKgQ9XklUqMdGSWLBoW_lSDAdafat"
export QYWX_AM=""
################################## 定义每日签到的通知形式(选填) ##################################
## js脚本每日签到提供3种通知方式分别为
## 关闭通知那么请在下方填入0
## 简洁通知那么请在下方填入1其效果见https://github.com/LXK9301/jd_scripts/blob/master/icon/bean_sign_simple.jpg
## 原始通知那么请在下方填入2如果不填也默认为2内容比较长这也是默认通知方式
NotifyBeanSign=""
################################## 定义每日签到每个接口间的延迟时间(选填) ##################################
## 默认每个签到接口并发无延迟,如需要依次进行每个接口,请自定义延迟时间,单位为毫秒,延迟作用于每个签到接口, 如填入延迟则切换顺序签到(耗时较长)
export JD_BEAN_STOP=""
################################## 定义东东农场互助(选填) ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
MyFruit1=""
MyFruit2=""
MyFruit3=""
MyFruit4=""
MyFruit5=""
MyFruit6=""
MyFruitA=""
MyFruitB=""
ForOtherFruit1=""
ForOtherFruit2=""
ForOtherFruit3=""
ForOtherFruit4=""
ForOtherFruit5=""
ForOtherFruit6=""
################################## 定义东东萌宠互助(选填) ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
MyPet1=""
MyPet2=""
MyPet3=""
MyPet4=""
MyPet5=""
MyPet6=""
MyPetA=""
MyPetB=""
ForOtherPet1=""
ForOtherPet2=""
ForOtherPet3=""
ForOtherPet4=""
ForOtherPet5=""
ForOtherPet6=""
################################## 定义种豆得豆互助(选填) ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
MyBean1=""
MyBean2=""
MyBean3=""
MyBean4=""
MyBean5=""
MyBean6=""
MyBeanA=""
MyBeanB=""
ForOtherBean1=""
ForOtherBean2=""
ForOtherBean3=""
ForOtherBean4=""
ForOtherBean5=""
ForOtherBean6=""
################################## 定义京喜工厂互助(选填) ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
MyDreamFactory1=""
MyDreamFactory2=""
MyDreamFactory3=""
MyDreamFactory4=""
MyDreamFactory5=""
MyDreamFactory6=""
MyDreamFactoryA=""
MyDreamFactoryB=""
ForOtherDreamFactory1=""
ForOtherDreamFactory2=""
ForOtherDreamFactory3=""
ForOtherDreamFactory4=""
ForOtherDreamFactory5=""
ForOtherDreamFactory6=""
################################## 定义东东工厂互助(选填) ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
MyJdFactory1=""
MyJdFactory2=""
MyJdFactory3=""
MyJdFactory4=""
MyJdFactory5=""
MyJdFactory6=""
MyJdFactoryA=""
MyJdFactoryB=""
ForOtherJdFactory1=""
ForOtherJdFactory2=""
ForOtherJdFactory3=""
ForOtherJdFactory4=""
ForOtherJdFactory5=""
ForOtherJdFactory6=""
################################## 定义京东赚赚互助(选填) ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
MyJdzz1=""
MyJdzz2=""
MyJdzz3=""
MyJdzz4=""
MyJdzz5=""
MyJdzz6=""
MyJdzzA=""
MyJdzzB=""
ForOtherJdzz1=""
ForOtherJdzz2=""
ForOtherJdzz3=""
ForOtherJdzz4=""
ForOtherJdzz5=""
ForOtherJdzz6=""
################################## 定义疯狂的JOY互助选填 ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
MyJoy1=""
MyJoy2=""
MyJoy3=""
MyJoy4=""
MyJoy5=""
MyJoy6=""
MyJoyA=""
MyJoyB=""
ForOtherJoy1=""
ForOtherJoy2=""
ForOtherJoy3=""
ForOtherJoy4=""
ForOtherJoy5=""
ForOtherJoy6=""
################################## 定义京喜农场互助(选填) ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
## 京喜农场助力码为 JSON 格式因此使用单引号json 格式如下
## {"smp":"22bdadsfaadsfadse8a","active":"jdnc_1_btorange210113_2","joinnum":"1"}
## 助力码获取可以通过 js jd_get_share_code now 命令获取
## 注意:京喜农场 种植种子发生变化的时候,互助码也会变!!
MyJxnc1=''
MyJxnc2=''
MyJxnc3=''
MyJxnc4=''
MyJxnc5=''
MyJxnc6=''
MyJxncA=''
MyJxncB=''
ForOtherJxnc1=""
ForOtherJxnc2=""
ForOtherJxnc3=""
ForOtherJxnc4=""
ForOtherJxnc5=""
ForOtherJxnc6=""
################################## 定义京喜农场TOKEN选填 ##################################
## 如果某个Cookie的账号种植的是app种子则必须填入有效的TOKEN而种植非app种子则不需要TOKEN
## TOKEN的形式{"farm_jstoken":"749a90f871adsfads8ffda7bf3b1576760","timestamp":"1610165423873","phoneid":"42c7e3dadfadsfdsaac-18f0e4f4a0cf"}
## 因TOKEN中带有双引号因此变量值两侧必须由一对单引号引起来
## TOKEN如何获取请阅读以下文件的注释https://github.com/LXK9301/jd_scripts/blob/master/jd_jxnc.js
TokenJxnc1=''
TokenJxnc2=''
TokenJxnc3=''
TokenJxnc4=''
TokenJxnc5=''
TokenJxnc6=''
################################## 定义口袋书店互助(选填) ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
MyBookShop1=""
MyBookShop2=""
MyBookShop3=""
MyBookShop4=""
MyBookShop5=""
MyBookShop6=""
MyBookShopA=""
MyBookShopB=""
ForOtherBookShop1=""
ForOtherBookShop2=""
ForOtherBookShop3=""
ForOtherBookShop4=""
ForOtherBookShop5=""
ForOtherBookShop6=""
################################## 定义签到领现金互助(选填) ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
MyCash1=""
MyCash2=""
MyCash3=""
MyCash4=""
MyCash5=""
MyCash6=""
MyCashA=""
MyCashB=""
ForOtherCash1=""
ForOtherCash2=""
ForOtherCash3=""
ForOtherCash4=""
ForOtherCash5=""
ForOtherCash6=""
################################## 定义闪购盲盒互助(选填) ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
MySgmh1=""
MySgmh2=""
MySgmh3=""
MySgmh4=""
MySgmh5=""
MySgmh6=""
MySgmhA=""
MySgmhB=""
ForOtherSgmh1=""
ForOtherSgmh2=""
ForOtherSgmh3=""
ForOtherSgmh4=""
ForOtherSgmh5=""
ForOtherSgmh6=""
################################## 定义京东环球挑战赛活动互助(选填) ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
## 仅2021年2月22日(含)前有效
MyGLOBAL1=""
MyGLOBAL2=""
MyGLOBAL3=""
MyGLOBAL4=""
MyGLOBAL5=""
MyGLOBAL6=""
MyGLOBALA=""
MyGLOBALB=""
ForOtherGLOBAL1=""
ForOtherGLOBAL2=""
ForOtherGLOBAL3=""
ForOtherGLOBAL4=""
ForOtherGLOBAL5=""
ForOtherGLOBAL6=""
################################## 定义惊喜财富岛互助(选填) ##################################
## 具体填法及要求详见本文件最下方“互助码填法示例”
MyJdcfd1=""
MyJdcfd2=""
MyJdcfd3=""
MyJdcfd4=""
MyJdcfd5=""
MyJdcfd6=""
MyJdcfdA=""
MyJdcfdB=""
ForOtherJdcfd1=""
ForOtherJdcfd2=""
ForOtherJdcfd3=""
ForOtherJdcfd4=""
ForOtherJdcfd5=""
ForOtherJdcfd6=""
################################## 定义东东超市蓝币兑换数量(选填) ##################################
## 东东超市蓝币兑换,可用值包括:
## 一、0表示不兑换京豆这也是js脚本的默认值
## 二、20表示兑换20个京豆
## 三、1000表示兑换1000个京豆
## 四、可兑换清单的商品名称输入能跟唯一识别出来的关键词即可比如MARKET_COIN_TO_BEANS="抽纸"
## 注意:有些比较贵的实物商品京东只是展示出来忽悠人的,即使你零点用脚本去抢,也会提示没有或提示已下架
export MARKET_COIN_TO_BEANS="0"
################################## 定义东东超市蓝币成功兑换奖品是否静默运行(选填) ##################################
## 默认 "false" 关闭(即:奖品兑换成功后会发出通知提示),如需要静默运行不发出通知,请改为 "true"
export MARKET_REWARD_NOTIFY=""
################################## 定义东东超市是否自动升级商品和货架(选填) ##################################
## 升级顺序:解锁升级商品、升级货架,默认 "true" 自动升级,如需关闭自动升级,请改为 "false"
export SUPERMARKET_UPGRADE=""
################################## 定义东东超市是否自动更换商圈(选填) ##################################
## 小于对方300热力值自动更换商圈队伍默认 "true" 自动更换,如不想更换商圈,请改为 "false"
## 目前已无此功能,申明了也无效
# export BUSINESS_CIRCLE_JUMP=""
################################## 定义东东超市是否自动使用金币去抽奖(选填) ##################################
## 是否用金币去抽奖,默认 "false" 关闭,如需开启,请修改为 "true"
export SUPERMARKET_LOTTERY=""
################################## 定义东东超市是否自动参加PK队伍选填 ##################################
## 是否每次PK活动参加脚本作者创建的PK队伍"true" 表示参加,"false" 表示不参加,默认为 "true"
export JOIN_PK_TEAM=""
################################## 定义东东农场是否静默运行(选填) ##################################
## 默认为 "false",不静默,发送推送通知消息,如不想收到通知,请修改为 "true"
## 如果你不想完全关闭或者完全开启通知只想在特定的时间发送通知可以参考下面的“定义东东萌宠是否静默运行”部分设定几个if判断条件
export FRUIT_NOTIFY_CONTROL=""
################################## 定义东东农场是否使用水滴换豆卡(选填) ##################################
## 如果出现限时活动时100g水换20豆此时比浇水划算"true" 表示换豆(不浇水),"false" 表示不换豆(继续浇水),默认是"false"
## 如需切换为换豆(不浇水),请修改为 "true"
export FRUIT_BEAN_CARD=""
################################## 定义宠汪汪喂食克数(选填) ##################################
## 你期望的宠汪汪每次喂食克数只能填入10、20、40、80默认为10
## 如实际持有食物量小于所设置的克数,脚本会自动降一档,直到降无可降
## 具体情况请自行在宠汪汪游戏中去查阅攻略
export JOY_FEED_COUNT=""
################################## 定义宠汪汪兑换京豆数量(选填) ##################################
## 目前的可用值包括0、20、500、1000其中0表示为不自动兑换京豆如不设置将默认为"20"
## 不同等级可兑换不同数量的京豆,详情请见宠汪汪游戏中兑换京豆选项
## 500、1000的京豆每天有总量限制设置了并且你也有足够积分时也并不代表就一定能抢到
export JD_JOY_REWARD_NAME=""
################################## 定义宠汪汪兑换京豆是否静默运行(选填) ##################################
## 默认为 "false",在成功兑换京豆时将发送推送通知消息(失败不发送),如想要静默不发送通知,请修改为 "true"
export JD_JOY_REWARD_NOTIFY=""
################################## 定义宠汪汪是否自动给好友的汪汪喂食(选填) ##################################
## 默认 "false" 不会自动给好友的汪汪喂食,如想自动喂食,请改成 "true"
export JOY_HELP_FEED=""
################################## 定义宠汪汪是否自动报名宠物赛跑(选填) ##################################
## 默认 "true" 参加宠物赛跑,如需关闭,请改成 "false"
export JOY_RUN_FLAG=""
################################## 定义宠汪汪参加比赛类型(选填) ##################################
## 当JOY_RUN_FLAG不设置或设置为 "true" 时生效
## 可选值2,10,50其他值不可以。其中2代表参加双人PK赛10代表参加10人突围赛50代表参加50人挑战赛不填时默认为2
## 各个账号间请使用 & 分隔比如JOY_TEAM_LEVEL="2&2&50&10"
## 如果你有5个账号但只写了四个数字那么第5个账号将默认参加2人赛账号如果更多与此类似
export JOY_TEAM_LEVEL=""
################################## 定义宠汪汪赛跑获胜后是否推送通知(选填) ##################################
## 控制jd_joy.js脚本宠汪汪赛跑获胜后是否推送通知"false" 为否(不推送通知消息)"true" 为是(即:发送推送通知消息),默认为 "true"
export JOY_RUN_NOTIFY=""
################################## 定义摇钱树是否自动将金果卖出变成金币(选填) ##################################
## 金币有时效,默认为 "false",不卖出金果为金币,如想希望自动卖出,请修改为 "true"
export MONEY_TREE_SELL_FRUIT=""
################################## 定义东东萌宠是否静默运行(选填) ##################################
## 默认 "false"(不静默,发送推送通知消息),如想静默请修改为 true
## 每次执行脚本通知太频繁了,改成只在周三和周六中午那一次运行时发送通知提醒
## 除掉上述提及时间之外,均设置为 true静默不发通知
## 特别说明:针对北京时间有效。
if [ $(date "+%w") -eq 6 ] && [ $(date "+%H") -ge 9 ] && [ $(date "+%H") -lt 14 ]; then
export PET_NOTIFY_CONTROL="false"
elif [ $(date "+%w") -eq 3 ] && [ $(date "+%H") -ge 9 ] && [ $(date "+%H") -lt 14 ]; then
export PET_NOTIFY_CONTROL="false"
else
export PET_NOTIFY_CONTROL="true"
fi
################################## 定义京喜工厂控制哪个京东账号不运行此脚本(选填) ##################################
## 输入"1"代表第一个京东账号不运行,多个使用 & 连接,例:"1&3" 代表账号1和账号3不运行京喜工厂脚本输入"0",代表全部账号不运行京喜工厂脚本
## 如果使用了 “临时屏蔽某个Cookie” TempBlockCookie 功能,编号会发生变化
export DREAMFACTORY_FORBID_ACCOUNT=""
################################## 定义东东工厂控制哪个京东账号不运行此脚本(选填) ##################################
## 输入"1"代表第一个京东账号不运行,多个使用 & 连接,例:"1&3" 代表账号1和账号3不运行东东工厂脚本输入"0",代表全部账号不运行东东工厂脚本
## 如果使用了 “临时屏蔽某个Cookie” TempBlockCookie 功能,编号会发生变化
export JDFACTORY_FORBID_ACCOUNT=""
################################## 定义东东工厂心仪的商品(选填) ##################################
## 只有在满足以下条件时,才自动投入电力:一是存储的电力满足生产商品所需的电力,二是心仪的商品有库存,如果没有输入心仪的商品,那么当前你正在生产的商品视作心仪的商品
## 如果你看不懂上面的话,请去东东工厂游戏中查阅攻略
## 心仪的商品请输入商品的全称或能唯一识别出该商品的关键字
export FACTORAY_WANTPRODUCT_NAME=""
################################## 定义京喜农场通知级别(选填) ##################################
## 可用值: 0(不通知); 1(本次获得水滴>0); 2(任务执行); 3(任务执行+未种植种子),默认为"3"
export JXNC_NOTIFY_LEVEL="3"
################################## 定义取关参数(选填) ##################################
## jd_unsubscribe这个任务是用来取关每天做任务关注的商品和店铺默认在每次运行时取关20个商品和20个店铺
## 如果取关数量不够,可以根据情况增加,还可以设置 jdUnsubscribeStopGoods 和 jdUnsubscribeStopShop
## 商品取关数量
goodPageSize=""
## 店铺取关数量
shopPageSize=""
## 遇到此商品不再取关此商品以及它后面的商品,需去商品详情页长按拷贝商品信息
jdUnsubscribeStopGoods=""
## 遇到此店铺不再取关此店铺以及它后面的店铺,请从头开始输入店铺名称
jdUnsubscribeStopShop=""
################################## 疯狂的JOY选填 ##################################
## 疯狂的JOY循环助力"true" 表示循环助力,"false" 表示不循环助力,默认 "false"
export JDJOY_HELPSELF=""
## 疯狂的JOY京豆兑换目前最小值为500/1000京豆默认为 "0" 不开启京豆兑换
export JDJOY_APPLYJDBEAN=""
## 疯狂的JOY自动购买什么等级的JOY如需要使用请自行解除注释
# export BUY_JOY_LEVEL=""
################################## 定义是否自动加购物车(选填) ##################################
## 口袋书店和东东小窝有些任务需要将商品加进购物车才能完成,默认 "false" 不做这些任务,如想做,请设置为 "true"
export PURCHASE_SHOPS=""
################################## 定义京喜财富岛通知(选填) ##################################
## 输入true为通知,默认 "false",不填则为不通知
export CFD_NOTIFY_CONTROL=""
################################## 定义京小兑是否自动把抽奖卷兑换为兑币,(选填) ##################################
## 输入true为自动兑换,不填则为不兑换
export JD_JXD_EXCHANGE=""
################################## 定义宠汪汪是否开启内部互助,(选填) ##################################
## 输入true为开启内部互助,不填默认关闭
export JOY_RUN_HELP_MYSELF=""
################################## Telegram 代理(选填) ##################################
## Telegram 代理的 IP代理类型为 http比如你代理是 http://127.0.0.1:1080则填写 "127.0.0.1"
## 如需使用,请自行解除下一行的注释
# export TG_PROXY_HOST=""
## Telegram 代理的端口,代理类型为 http比如你代理是 http://127.0.0.1:1080则填写 "1080"
## 如需使用,请自行解除下一行的注释
# export TG_PROXY_PORT=""
################################## 是否添加DIY脚本选填 ##################################
## 如果你自己会写shell脚本并且希望在每次git_pull.sh这个脚本运行时额外运行你的DIY脚本请赋值为 "true"
## 同时,请务必将你的脚本命名为 extra.sh (只能叫这个文件名),放在 config 目录下
## 仓库下已经上传extra.sh模板如果你想使用可以参考本仓库下 extra.sh 文件地址https://raw.githubusercontent.com/dockere/jd-base/master/sample/diy.sh
EnableExtraShell=""
################################## 互助码填法示例 ##################################
## **互助码是填在My系列变量中的ForOther系统变量中只要填入My系列的变量名即可按注释中的例子拼接以东东农场为例如下所示。**
## **实际上东东农场一个账号只能给别人助力3次我多写的话只有前几个会被助力。但如果前面的账号获得的助力次数已经达到上限了那么还是会尝试继续给余下的账号助力所以多填也是有意义的。**
## **ForOther系列变量必须从1开始编号依次编下去。**
# MyFruit1="e6e04602d5e343258873af1651b603ec" # 这是Cookie1这个账号的互助码
# MyFruit2="52801b06ce2a462f95e1d59d7e856ef4" # 这是Cookie2这个账号的互助码
# MyFruit3="e2fd1311229146cc9507528d0b054da8" # 这是Cookie3这个账号的互助码
# MyFruit4="6dc9461f662d490991a31b798f624128" # 这是Cookie4这个账号的互助码
# MyFruit5="30f29addd75d44e88fb452bbfe9f2110" # 这是Cookie5这个账号的互助码
# MyFruit6="1d02fc9e0e574b4fa928e84cb1c5e70b" # 这是Cookie6这个账号的互助码
# MyFruitA="5bc73a365ff74a559bdee785ea97fcc5" # 这是我和别人交换互助另外一个用户A的互助码
# MyFruitB="6d402dcfae1043fba7b519e0d6579a6f" # 这是我和别人交换互助另外一个用户B的互助码
# MyFruitC="5efc7fdbb8e0436f8694c4c393359576" # 这是我和别人交换互助另外一个用户C的互助码
# ForOtherFruit1="${MyFruit2}@${MyFruitB}@${MyFruit4}" # Cookie1这个账号助力Cookie2的账号的账号、Cookie4的账号以及用户B
# ForOtherFruit2="${MyFruit1}@${MyFruitA}@${MyFruit4}" # Cookie2这个账号助力Cookie1的账号的账号、Cookie4的账号以及用户A
# ForOtherFruit3="${MyFruit1}@${MyFruit2}@${MyFruitC}@${MyFruit4}@${MyFruitA}@${MyFruit6}" # 解释同上东东农场实际上只能助力3次
# ForOtherFruit4="${MyFruit1}@${MyFruit2}@${MyFruit3}@${MyFruitC}@${MyFruit6}@${MyFruitA}" # 解释同上东东农场实际上只能助力3次
# ForOtherFruit5="${MyFruit1}@${MyFruit2}@${MyFruit3}@${MyFruitB}@${MyFruit4}@${MyFruit6}@${MyFruitC}@${MyFruitA}"
# ForOtherFruit6="${MyFruit1}@${MyFruit2}@${MyFruit3}@${MyFruitA}@${MyFruit4}@${MyFruit5}@${MyFruitC}"

View File

@ -1,27 +0,0 @@
# 更新shell及面板代码
55 2,13 * * * git_pull >> ${QL_DIR}/log/git_pull.log 2>&1
# 更新你需要的仓库的代码
# 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
31 * * * * diy monk-coder dust i-chenzhe >> ${QL_DIR}/log/diy_pull.log 2>&1
# 重新build面板
# 30 7 */7 * * rebuild >> ${QL_DIR}/log/rebuild.log 2>&1
# 删除 RmLogDaysAgo 指定天数以前的旧日志,本行为不记录日志
57 13 * * * rm_log >/dev/null 2>&1
# 导出所有互助码清单日志在log/export_sharecodes下
48 5 * * * export_sharecodes
# 重启挂机脚本
# 33 3 * * * js hangup
# 重置密码
# 33 6 */7 * * js resetpwd
# 运行所有脚本(慎用)
# 33 9 */7 * * js runall
# 其他定时任务

View File

@ -0,0 +1,11 @@
# 更新所有脚本
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 命令
# 如果由本程序自动添加的任务你不想运行,注释即可,不要删除,请在最后保留一个空行

34
sample/jdCookie.js Normal file
View File

@ -0,0 +1,34 @@
/*
此文件为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();
}

29
sample/package.json Normal file
View File

@ -0,0 +1,29 @@
{
"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"
}
}

711
sample/sendNotify.js Normal file

File diff suppressed because one or more lines are too long

40
shell/api.sh Executable file → Normal file
View File

@ -1,35 +1,35 @@
#!/usr/bin/env bash #!/usr/bin/env bash
get_token() { get_token() {
token=$(cat $AuthConf | jq -r .token) token=$(cat $file_auth_user | jq -r .token)
} }
get_json_value() { get_json_value() {
local json=$1 local json=$1
local key=$2 local key=$2
if [[ -z "$3" ]]; then if [[ -z "$3" ]]; then
local num=1 local num=1
else else
local num=$3 local num=$3
fi fi
local value=$(echo "${json}" | awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'${key}'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p) local value=$(echo "${json}" | awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'${key}'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p)
echo ${value} echo ${value}
} }
add_cron_api() { add_cron_api() {
local currentTimeStamp=$(date +%s) local currentTimeStamp=$(date +%s)
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
local schedule=$(echo "$1" | awk -F ":" '{print $1}') local schedule=$(echo "$1" | awk -F ":" '{print $1}')
local command=$(echo "$1" | awk -F ":" '{print $2}') local command=$(echo "$1" | awk -F ":" '{print $2}')
local name=$(echo "$1" | awk -F ":" '{print $3}') local name=$(echo "$1" | awk -F ":" '{print $3}')
else else
local schedule=$1 local schedule=$1
local command=$2 local command=$2
local name=$3 local name=$3
fi fi
local api=$(curl "http://localhost:5600/api/crons?t=$currentTimeStamp" \ local api=$(curl "http://localhost:5600/api/crons?t=$currentTimeStamp" \
-H "Accept: application/json" \ -H "Accept: application/json" \

View File

@ -1,141 +0,0 @@
#!/usr/bin/env bash
## 路径、环境判断
ShellDir=${QL_DIR:-$(cd $(dirname $0); pwd)}
LogDir=${ShellDir}/log
ConfigDir=${ShellDir}/config
FileConf=${ConfigDir}/config.sh
CookieConf=${ConfigDir}/cookie.sh
[[ ${ANDROID_RUNTIME_ROOT}${ANDROID_ROOT} ]] && Opt="P" || Opt="E"
Tips="从日志中未找到任何互助码"
## 所有有互助码的活动,只需要把脚本名称去掉前缀 jd_ 后列在 Name1 中,将其中文名称列在 Name2 中,对应 config.sh 中互助码后缀列在 Name3 中即可。
## Name1、Name2 和 Name3 中的三个名称必须一一对应。
Name1=(fruit pet plantBean dreamFactory jdfactory crazy_joy jdzz jxnc bookshop cash sgmh cfd global)
Name2=(东东农场 东东萌宠 京东种豆得豆 京喜工厂 东东工厂 crazyJoy任务 京东赚赚 京喜农场 口袋书店 签到领现金 闪购盲盒 京喜财富岛 环球挑战赛)
Name3=(Fruit Pet Bean DreamFactory JdFactory Joy Jdzz Jxnc BookShop Cash Sgmh Cfd Global)
## 导入 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
}
## 用户数量 UserSum
function Count_UserSum {
UserSum=$(awk '{print NR}' ${CookieConf} | tail -n1)
}
## 导出互助码的通用程序
function Cat_Scodes {
if [ -d ${LogDir}/jd_$1 ] && [[ $(ls ${LogDir}/jd_$1) != "" ]]; then
cd ${LogDir}/jd_$1
## 导出助力码变量My
for log in $(ls -r); do
case $# in
2)
codes=$(cat ${log} | grep -${Opt} "开始【京东账号|您的(好友)?助力码为" | uniq | perl -0777 -pe "{s|\*||g; s|开始||g; s|\n您的(好友)?助力码为()?:?||g; s|.+||g}" | sed -r "s/【京东账号/My$2/;s/】.*?/='/;s/】.*?/='/;s/$/'/;s/\(每次运行都变化,不影响\)//")
;;
3)
codes=$(grep -${Opt} $3 ${log} | uniq | sed -r "s/【京东账号/My$2/;s/.*?】/='/;s/$/'/")
;;
esac
if [[ ${codes} ]]; then
## 添加判断,若未找到该用户互助码,则设置为空值
for ((user_num=1;user_num<=${UserSum};user_num++)); do
echo -e "${codes}" | grep -${Opt}q "My$2${user_num}="
if [ $? -eq 1 ]; then
if [ $user_num == 1 ]; then
codes=$(echo "${codes}" | sed -r "1i My${2}1=''")
else
codes=$(echo "${codes}" | sed -r "/My$2$(expr ${user_num} - 1)=/a\My$2${user_num}=''")
fi
fi
done
break
fi
done
## 导出为他人助力变量ForOther
if [[ ${codes} ]]; then
help_code=""
for ((user_num=1;user_num<=${UserSum};user_num++)); do
echo -e "${codes}" | grep -${Opt}q "My$2${user_num}=''"
if [ $? -eq 1 ]; then
help_code=${help_code}"\${My"$2${user_num}"}@"
fi
done
## 生成互助规则模板
for_other_codes=""
case $HelpType in
0) ### 统一优先级助力模板
new_code=$(echo ${help_code} | sed "s/@$//")
for ((user_num=1;user_num<=${UserSum};user_num++)); do
if [ $user_num == 1 ]; then
for_other_codes=${for_other_codes}"ForOther"$2${user_num}"=\""${new_code}"\"\n"
else
for_other_codes=${for_other_codes}"ForOther"$2${user_num}"=\"\${ForOther"${2}1"}\"\n"
fi
done
;;
1) ### 均匀助力模板
for ((user_num=1;user_num<=${UserSum};user_num++)); do
echo ${help_code} | grep "\${My"$2${user_num}"}@" > /dev/null
if [ $? -eq 0 ]; then
left_str=$(echo ${help_code} | sed "s/\${My$2${user_num}}@/ /g" | awk '{print $1}')
right_str=$(echo ${help_code} | sed "s/\${My$2${user_num}}@/ /g" | awk '{print $2}')
mark="\${My$2${user_num}}@"
else
left_str=$(echo ${help_code} | sed "s/${mark}/ /g" | awk '{print $1}')${mark}
right_str=$(echo ${help_code} | sed "s/${mark}/ /g" | awk '{print $2}')
fi
new_code=$(echo ${right_str}${left_str} | sed "s/@$//")
for_other_codes=${for_other_codes}"ForOther"$2${user_num}"=\""${new_code}"\"\n"
done
;;
*) ### 普通优先级助力模板
for ((user_num=1;user_num<=${UserSum};user_num++)); do
new_code=$(echo ${help_code} | sed "s/\${My"$2${user_num}"}@//;s/@$//")
for_other_codes=${for_other_codes}"ForOther"$2${user_num}"=\""${new_code}"\"\n"
done
;;
esac
echo -e "${codes}\n\n${for_other_codes}" | sed s/[[:space:]]//g
else
echo ${Tips}
fi
else
echo "未运行过 jd_$1 脚本,未产生日志"
fi
}
## 汇总
function Cat_All {
echo -e "\n从最后一个日志提取互助码受日志内容影响仅供参考。"
for ((i=0; i<${#Name1[*]}; i++)); do
echo -e "\n${Name2[i]}"
[[ $(Cat_Scodes "${Name1[i]}" "${Name3[i]}" "${Name2[i]}好友互助码") == ${Tips} ]] && Cat_Scodes "${Name1[i]}" "${Name3[i]}" || Cat_Scodes "${Name1[i]}" "${Name3[i]}" "${Name2[i]}好友互助码"
done
}
## 执行并写入日志
LogTime=$(date "+%Y-%m-%d-%H-%M-%S")
LogFile="${LogDir}/export_sharecodes/${LogTime}.log"
[ ! -d "${LogDir}/export_sharecodes" ] && mkdir -p ${LogDir}/export_sharecodes
Import_Conf && Count_UserSum && Cat_All | perl -pe "{s|京东种豆|种豆|; s|crazyJoy任务|疯狂的JOY|}" | tee ${LogFile}

View File

@ -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 <auth> <repo> <path> <blacklist>'
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

View File

@ -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 --production --no-save --no-bin-links || npm install --production --no-bin-links --no-save --registry=https://registry.npm.taobao.org
elif ! type yarn >/dev/null 2>&1; then
npm install --production --no-save || npm install --production --no-save --registry=https://registry.npm.taobao.org
else
echo -e "检测到本机安装了 yarn使用 yarn 替代 npm...\n"
yarn install --production --network-timeout 1000000000 || yarn install --production --registry=https://registry.npm.taobao.org --network-timeout 1000000000
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

View File

@ -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

1
shell/mytask.sh Symbolic link
View File

@ -0,0 +1 @@
task.sh

View File

@ -1,4 +1,4 @@
const notify = require('/ql/scripts/sendNotify'); const notify = require('../scripts/sendNotify.js');
const title = process.argv[2]; const title = process.argv[2];
const content = process.argv[3]; const content = process.argv[3];

18
shell/rebuild.sh Executable file → Normal file
View File

@ -1,12 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
ShellDir=${QL_DIR:-$(cd $(dirname $0); pwd)} dir_shell=$(dirname $(readlink -f "$0"))
dir_root=$(cd $dir_shell; cd ..; pwd)
echo -e "更新shell...\n" echo -e "更新qinglong...\n"
cd ${ShellDir} cd $dir_root
git fetch --all git fetch --all
git pull git pull
echo -e "更新shell完成...\n" echo -e "更新更新qinglong完成...\n"
echo -e "重新build...\n" echo -e "重新build...\n"
yarn install --network-timeout 1000000000 || yarn install --registry=https://registry.npm.taobao.org --network-timeout 1000000000 yarn install --network-timeout 1000000000 || yarn install --registry=https://registry.npm.taobao.org --network-timeout 1000000000
@ -15,14 +16,7 @@ yarn build-back
echo -e "重新build完成...\n" echo -e "重新build完成...\n"
echo -e "重启服务...\n" echo -e "重启服务...\n"
pm2 restart panel 2>/dev/null || pm2 start $dir_root/build/app.js -n panel
PIDS=`ps -ef|grep "app.js"|grep -v grep`
if [ "$PIDS" != "" ]; then
pm2 restart panel
else
pm2 start ${QL_DIR}/build/app.js -n panel
fi
nginx -s reload nginx -s reload
echo -e "重启服务完成...\n" echo -e "重启服务完成...\n"

View File

@ -1,58 +0,0 @@
#!/usr/bin/env bash
## 判断环境
ShellDir=${QL_DIR:-$(cd $(dirname $0); pwd)}
LogDir=${ShellDir}/log
## 导入配置文件
. ${ShellDir}/config/cookie.sh
. ${ShellDir}/config/config.sh
## 删除运行js脚本的旧日志
function Rm_JsLog {
LogFileList=$(ls -l ${LogDir}/*/*.log | awk '{print $9}')
for log in ${LogFileList}
do
LogDate=$(echo ${log} | awk -F "/" '{print $NF}' | cut -c1-10) #文件名比文件属性获得的日期要可靠
if [[ $(uname -s) == Darwin ]]
then
DiffTime=$(($(date +%s) - $(date -j -f "%Y-%m-%d" "${LogDate}" +%s)))
else
DiffTime=$(($(date +%s) - $(date +%s -d "${LogDate}")))
fi
[ ${DiffTime} -gt $((${RmLogDaysAgo} * 86400)) ] && rm -vf ${log}
done
}
## 删除git_pull.sh的运行日志
function Rm_GitPullLog {
if [[ $(uname -s) == Darwin ]]
then
DateDelLog=$(date -v-${RmLogDaysAgo}d "+%Y-%m-%d")
else
Stmp=$(($(date "+%s") - 86400 * ${RmLogDaysAgo}))
DateDelLog=$(date -d "@${Stmp}" "+%Y-%m-%d")
fi
LineEndGitPull=$[$(cat ${LogDir}/git_pull.log | grep -n "${DateDelLog} " | head -1 | awk -F ":" '{print $1}') - 3]
[ ${LineEndGitPull} -gt 0 ] && perl -i -ne "{print unless 1 .. ${LineEndGitPull} }" ${LogDir}/git_pull.log
}
## 删除空文件夹
function Rm_EmptyDir {
cd ${LogDir}
for dir in $(ls)
do
if [ -d ${dir} ] && [[ $(ls ${dir}) == "" ]]; then
rm -rf ${dir}
fi
done
}
## 运行
if [ -n "${RmLogDaysAgo}" ]; then
echo -e "查找旧日志文件中...\n"
Rm_JsLog
Rm_GitPullLog
Rm_EmptyDir
echo -e "删除旧日志执行完毕\n"
fi

46
shell/rmlog.sh Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env bash
## 判断环境
dir_shell=$(dirname $(readlink -f "$0"))
dir_root=$(cd $dir_shell; cd ..; pwd)
## 导入通用变量与函数
. $dir_shell/share.sh
## 导入配置文件,检测平台
import_config_no_check rmlog
detect_termux
detect_macos
## 删除运行js脚本的旧日志
remove_js_log () {
local log_full_path_list=$(ls -l $dir_log/*/*.log | awk '{print $9}')
local diff_time
for log in $log_full_path_list; do
local log_date=$(echo $log | awk -F "/" '{print $NF}' | cut -c1-10) #文件名比文件属性获得的日期要可靠
if [[ $is_macos -eq 1 ]]; then
diff_time=$(($(date +%s) - $(date -j -f "%Y-%m-%d" "$log_date" +%s)))
else
diff_time=$(($(date +%s) - $(date +%s -d "$log_date")))
fi
[[ $diff_time -gt $((${RmLogDaysAgo} * 86400)) ]] && rm -vf $log
done
}
## 删除空文件夹
remove_empty_dir () {
cd $dir_log
for dir in $(ls); do
if [ -d $dir ] && [[ -z $(ls $dir) ]]; then
rm -rf $dir
fi
done
}
## 运行
if [[ ${RmLogDaysAgo} ]]; then
echo -e "查找旧日志文件中...\n"
remove_js_log
remove_empty_dir
echo -e "删除旧日志执行完毕\n"
fi

223
shell/share.sh Normal file
View File

@ -0,0 +1,223 @@
## 目录
dir_sample=$dir_root/sample
dir_config=$dir_root/config
dir_scripts=$dir_root/scripts
dir_raw=$dir_scripts/raw
dir_log=$dir_root/log
dir_list_tmp=$dir_log/.tmp
## 文件
file_config_sample=$dir_sample/config.sample.sh
file_cookie=$dir_config/cookie.sh
file_sharecode=$dir_config/sharecode.sh
file_config_user=$dir_config/config.sh
file_auth_sample=$dir_sample/auth.sample.json
file_auth_user=$dir_config/auth.json
file_extra_shell=$dir_config/extra.sh
## 清单文件
list_crontab_user=$dir_config/crontab.list
list_crontab_sample=$dir_sample/crontab.sample.list
list_own_scripts=$dir_list_tmp/own_scripts.list
list_own_user=$dir_list_tmp/own_user.list
list_own_add=$dir_list_tmp/own_add.list
list_own_drop=$dir_list_tmp/own_drop.list
## 需组合的环境变量列表env_name需要和var_name一一对应需要从api取信息
env_name=(
JD_COOKIE
)
var_name=(
Cookie
)
## 软连接及其原始文件对应关系
link_name=(
task
mytask
rmlog
update
rebuild
)
original_name=(
task.sh
task.sh
rmlog.sh
update.sh
rebuild.sh
)
## 导入配置文件不校验
import_config_no_check () {
[ -f $file_cookie ] && . $file_cookie
[ -f $file_config_user ] && . $file_config_user
}
## 导入配置文件并校验,$1任务名称
import_config_and_check () {
import_config_no_check $1
if [[ ! -s $file_cookie ]]; then
echo -e "请先配置好Cookie...\n"
exit 1
else
user_sum=0
for line in $(cat $file_cookie); do
let user_sum++
[[ $user_sum -gt $((3 * 5)) ]] && break
eval Cookie${user_sum}="\"$line\""
done
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
[ ! -d $dir ] && mkdir -p $dir
}
## 检测termux
detect_termux () {
if [[ ${ANDROID_RUNTIME_ROOT}${ANDROID_ROOT} ]] || [[ $PATH == *com.termux* ]]; then
is_termux=1
else
is_termux=0
fi
}
## 检测macos
detect_macos () {
[[ $(uname -s) == Darwin ]] && is_macos=1 || is_macos=0
}
## 生成随机数,$1用来求余的数字
gen_random_num () {
local divi=$1
echo $((${RANDOM} % $divi))
}
## 创建软连接的子函数,$1软连接文件路径$2要连接的对象
link_shell_sub () {
local link_path="$1"
local original_path="$2"
if [ ! -L $link_path ] || [[ $(readlink -f $link_path) != $original_path ]]; then
rm -f $link_path 2>/dev/null
ln -sf $original_path $link_path
fi
}
## 创建软连接
link_shell () {
if [[ $is_termux -eq 1 ]]; then
local path="/data/data/com.termux/files/usr/bin/"
elif [[ $PATH == */usr/local/bin* ]] && [ -d /usr/local/bin ]; then
local path="/usr/local/bin/"
else
local path=""
echo -e "脚本功能受限,请自行添加命令的软连接...\n"
fi
if [[ $path ]]; then
for ((i=0; i<${#link_name[*]}; i++)); do
link_shell_sub "$path${link_name[i]}" "$dir_shell/${original_name[i]}"
done
fi
}
## 定义各命令
define_cmd () {
local cmd_prefix cmd_suffix
if type task >/dev/null 2>&1; then
cmd_suffix=""
if [ -x "$dir_shell/task.sh" ]; then
cmd_prefix=""
else
cmd_prefix="bash "
fi
else
cmd_suffix=".sh"
if [ -x "$dir_shell/task.sh" ]; then
cmd_prefix="$dir_shell/"
else
cmd_prefix="bash $dir_shell/"
fi
fi
for ((i=0; i<${#link_name[*]}; i++)); do
export cmd_${link_name[i]}="${cmd_prefix}${link_name[i]}${cmd_suffix}"
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_pathrepo存放的绝对路径组成的数组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
if [ ! -s $file_config_user ]; then
echo -e "复制一份 $file_config_sample$file_config_user,随后请按注释编辑你的配置文件:$file_config_user\n"
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
}" $list_crontab_user
}

189
shell/task.sh Normal file
View File

@ -0,0 +1,189 @@
#!/usr/bin/env bash
## 路径
dir_shell=$(dirname $(readlink -f "$0"))
dir_root=$(cd $dir_shell; cd ..; 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
local combined_all=""
local tmp1 tmp2
for ((i=1; i<=$user_sum; i++)); do
for num in $TempBlockCookie; do
[[ $i -eq $num ]] && continue 2
done
local tmp1=$what_combine$i
local tmp2=${!tmp1}
combined_all="$combined_all&$tmp2"
done
echo $combined_all | perl -pe "{s|^&||; s|^@+||; s|&@|&|g; s|@+&|&|g; s|@+|@|g; s|@+$||}"
}
## 正常依次运行时组合所有账号的Cookie与互助码
combine_all () {
for ((i=0; i<${#env_name[*]}; i++)); do
export ${env_name[i]}=$(combine_sub ${var_name[i]})
done
}
## 并发运行时直接申明每个账号的Cookie与互助码$1用户Cookie编号
combine_one () {
local user_num=$1
for ((i=0; i<${#env_name[*]}; i++)); do
local tmp=${var_name[i]}$user_num
export ${env_name[i]}=${!tmp}
done
}
## 选择python3还是node
define_program () {
local p1=$1
[[ $p1 == *.js ]] && which_program="node"
[[ $p1 == *.py ]] && which_program="python3"
}
random_delay () {
local random_delay_max=$RandomDelay
if [[ $random_delay_max ]] && [[ $random_delay_max -gt 0 ]]; then
local current_min=$(date "+%-M")
if [[ $current_min -gt 2 && $current_min -lt 30 ]] || [[ $current_min -gt 31 && $current_min -lt 59 ]]; then
delay_second=$(($(gen_random_num $random_delay_max) + 1))
echo -e "\n命令未添加 \"now\",随机延迟 $delay_second 秒后再执行任务,如需立即终止,请按 CTRL+C...\n"
sleep $delay_second
fi
fi
}
## 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]}
for file in $(ls); do
if [ -f $file ] && [[ $(grep "new Env" $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_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
}
## 使用说明
usage () {
define_cmd
gen_array_scripts
echo -e "\ntask命令运行本程序自动添加进crontab的脚本需要输入脚本的绝对路径或去掉 “$dir_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 # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中"
echo -e "\nmytask命令运行未识别出cron的脚本以及你自己添加的脚本用法同task。mytask和task命令均为同一脚本的不同名字二者仅用来在crontab.list中区分不同类型的任务以方便自动增删任务手动直接运行task即可。"
echo -e "\n当前有以下脚本可以运行已省略路径 “$dir_scripts/” "
for ((i=0; i<${#array_scripts[*]}; i++)); do
echo -e "$(($i + 1)). ${array_scripts_name[i]}${array_scripts[i]}"
done
}
## run nohup$1文件名不含路径带后缀
run_nohup () {
local file_name=$1
nohup node $file_name &>$log_path &
}
## 正常运行单个脚本,$1传入参数
run_normal () {
local p1=$1
cd $dir_scripts
if [ -f $p1 ]; then
import_config_and_check "$p1"
update_crontab
define_program "$p1"
combine_all
[[ $# -eq 1 ]] && random_delay
log_time=$(date "+%Y-%m-%d-%H-%M-%S")
log_path="$dir_log/$p1/$log_time.log"
make_dir "$dir_log/$p1"
$which_program $p1 2>&1 | tee $log_path
else
update_crontab
echo -e "\n $p1 脚本不存在,请确认...\n"
usage
fi
}
## 并发执行因为是并发所以日志只能直接记录在日志文件中日志文件以Cookie编号结尾前台执行并发跑时不会输出日志
## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行
run_concurrent () {
local p1=$1
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")
echo -e "\n各账号间已经在后台开始并发执行前台不输入日志日志直接写入文件中。\n"
for ((user_num=1; user_num<=$user_sum; user_num++)); do
for num in ${TempBlockCookie}; do
[[ $user_num -eq $num ]] && continue 2
done
combine_one $user_num
log_path="$dir_log/$p1/${log_time}_${user_num}.log"
$which_program $p1 &>$log_path &
done
else
update_crontab
echo -e "\n $p1 脚本不存在,请确认...\n"
usage
fi
}
## 命令检测
main () {
case $# in
0)
echo
usage
;;
1)
run_normal $1
;;
2)
case $2 in
now)
run_normal $1 $2
;;
conc)
run_concurrent $1 $2
;;
*)
echo -e "\n命令输入错误...\n"
usage
;;
esac
;;
*)
echo -e "\n命令过多...\n"
usage
;;
esac
}
main "$@"

423
shell/update.sh Normal file
View File

@ -0,0 +1,423 @@
#!/usr/bin/env bash
## 文件路径、脚本网址
dir_shell=$(dirname $(readlink -f "$0"))
dir_root=$(cd $dir_shell; cd ..; pwd)
send_mark=$dir_shell/send_mark
## 导入通用变量与函数
. $dir_shell/share.sh
. $dir_shell/api.sh
## 导入配置文件,检测平台,创建软连接,识别命令,修复配置文件
detect_termux
detect_macos
link_shell
define_cmd
fix_config
import_config_no_check "update"
get_token
## 重置仓库remote urldocker专用$1要重置的目录$2要重置为的网址
reset_romote_url () {
local dir_current=$(pwd)
local dir_work=$1
local url=$2
if [ -d "$dir_work/.git" ]; then
cd $dir_work
git remote set-url origin $url >/dev/null
git reset --hard >/dev/null
cd $dir_current
fi
}
## 克隆脚本,$1仓库地址$2仓库保存路径$3分支可省略
git_clone_scripts () {
local url=$1
local dir=$2
local branch=$3
[[ $branch ]] && local cmd="-b $branch "
echo -e "开始克隆仓库 $url$dir\n"
git clone $cmd $url $dir
exit_status=$?
}
## 更新脚本,$1仓库保存路径
git_pull_scripts () {
local dir_current=$(pwd)
local dir_work=$1
cd $dir_work
echo -e "开始更新仓库:$dir_work\n"
git fetch --all
exit_status=$?
git reset --hard
git pull
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脚本清单文件路径$2cron任务清单文件路径$3增加任务清单文件路径$4删除任务清单文件路径
diff_cron () {
make_dir $dir_list_tmp
local list_scripts="$1"
local list_task="$2"
local list_add="$3"
local list_drop="$4"
if [ -s $list_task ]; then
grep -vwf $list_task $list_scripts > $list_add
elif [ ! -s $list_task ] && [ -s $list_scripts ]; then
cp -f $list_scripts $list_add
fi
if [ -s $list_scripts ]; then
grep -vwf $list_scripts $list_task > $list_drop
else
cp -f $list_task $list_drop
fi
}
## 更新docker-entrypointdocker专用
update_docker_entrypoint () {
if [[ $QL_DIR ]] && [[ $(diff $dir_root/docker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh) ]]; then
cp -f $dir_root/docker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
chmod 777 /usr/local/bin/docker-entrypoint.sh
fi
}
## 检测配置文件版本
detect_config_version () {
## 识别出两个文件的版本号
ver_config_sample=$(grep " Version: " $file_config_sample | perl -pe "s|.+v((\d+\.?){3})|\1|")
[ -f $file_config_user ] && ver_config_user=$(grep " Version: " $file_config_user | perl -pe "s|.+v((\d+\.?){3})|\1|")
## 删除旧的发送记录文件
[ -f $send_mark ] && [[ $(cat $send_mark) != $ver_config_sample ]] && rm -f $send_mark
## 识别出更新日期和更新内容
update_date=$(grep " Date: " $file_config_sample | awk -F ": " '{print $2}')
update_content=$(grep " Update Content: " $file_config_sample | awk -F ": " '{print $2}')
## 如果是今天,并且版本号不一致,则发送通知
if [ -f $file_config_user ] && [[ $ver_config_user != $ver_config_sample ]] && [[ $update_date == $(date "+%Y-%m-%d") ]]; then
if [ ! -f $send_mark ]; then
local notify_title="配置文件更新通知"
local notify_content="更新日期: $update_date\n用户版本: $ver_config_user\n新的版本: $ver_config_sample\n更新内容: $update_content\n更新说明: 如需使用新功能请对照config.sample.sh将相关新参数手动增加到你自己的config.sh中否则请无视本消息。本消息只在该新版本配置文件更新当天发送一次。\n"
echo -e $notify_content
notify "$notify_title" "$notify_content"
[[ $? -eq 0 ]] && echo $ver_config_sample > $send_mark
fi
else
[ -f $send_mark ] && rm -f $send_mark
fi
}
## npm install 子程序判断是否为安卓判断是否安装有yarn
npm_install_sub () {
if [ $is_termux -eq 1 ]; then
npm install --production --no-save --no-bin-links --registry=https://registry.npm.taobao.org || npm install --production --no-bin-links --no-save
elif ! type yarn >/dev/null 2>&1; then
npm install --production --no-save --registry=https://registry.npm.taobao.org || npm install --production --no-save
else
echo -e "检测到本机安装了 yarn使用 yarn 替代 npm...\n"
yarn install --production --network-timeout 1000000000 --registry=https://registry.npm.taobao.org || yarn install --production --network-timeout 1000000000
fi
}
## npm install$1package.json文件所在路径
npm_install_1 () {
local dir_current=$(pwd)
local dir_work=$1
cd $dir_work
echo -e "运行 npm install...\n"
npm_install_sub
[[ $? -ne 0 ]] && echo -e "\nnpm install 运行不成功,请进入 $dir_work 目录后手动运行 npm install...\n"
cd $dir_current
}
npm_install_2 () {
local dir_current=$(pwd)
local dir_work=$1
cd $dir_work
echo -e "检测到 $dir_work 的依赖包有变化,运行 npm install...\n"
npm_install_sub
[[ $? -ne 0 ]] && echo -e "\n安装 $dir_work 的依赖包运行不成功,再次尝试一遍...\n"
npm_install_1 $dir_work
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 -f $copy_source $copy_to
fi
}
## 更新依赖
update_depend () {
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
[ ! -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新/失效
output_list_add_drop () {
local list=$1
local type=$2
if [ -s $list ]; then
echo -e "检测到有$type的定时任务\n"
cat $list
echo
fi
}
## 自动删除失效的脚本与定时任务需要1.AutoDelCron/AutoDelCron 设置为 true2.正常更新js脚本没有报错3.存在失效任务4.crontab.list存在并且不为空
## $1失效任务清单文件路径
del_cron () {
local list_drop=$1
local detail detail2
if [ -s $list_drop ] && [ -s $list_crontab_user ]; then
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|")
del_cron_api "$id"
done
detail2=$(echo $detail | perl -pe "s| |\\\n|g")
echo -e "成功删除失效的的定时任务...\n"
notify "删除失效任务通知" "成功删除以下失效的定时任务:\n$detail2"
fi
}
## 自动增加定时任务需要1.AutoAddCron 设置为 true2.正常更新js脚本没有报错3.存在新任务4.crontab.list存在并且不为空
## $1新任务清单文件路径
add_cron () {
local list_add=$1
if [ -s $list_crontab_user ]; then
echo -e "开始尝试自动添加定时任务...\n"
local detail=$(cat $list_add)
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_relative_path | \
perl -pe "{
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_relative_path | awk -F "'|\"" '{print $2}' | head -1)
[[ -z $cron_name ]] && cron_name="$file_name"
add_cron_api "$cron_line:$cron_name"
fi
done
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]}
else
git_clone_scripts ${array_own_repo_url[i]} ${array_own_repo_path[i]} ${array_own_repo_branch[i]}
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"
else
echo -e "\n更新${array_own_repo_path[i]}失败,请检查原因...\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
}
## 更新所有 raw 文件
update_own_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"
wget -q --no-check-certificate -O "$dir_raw/${raw_file_name[$i]}.new" ${RawUrl[i]}
if [[ $? -eq 0 ]]; then
mv "$dir_raw/${raw_file_name[$i]}.new" "$dir_raw/${raw_file_name[$i]}"
echo -e "下载 ${raw_file_name[$i]} 成功...\n"
else
echo -e "下载 ${raw_file_name[$i]} 失败,保留之前正常下载的版本...\n"
[ -f "$dir_raw/${raw_file_name[$i]}.new" ] && rm -f "$dir_raw/${raw_file_name[$i]}.new"
fi
done
fi
}
## 调用用户自定义的extra.sh
run_extra_shell () {
if [[ ${EnableExtraShell} == true ]]; then
if [ -f $file_extra_shell ]
then
echo -e "--------------------------------------------------------------\n"
. $file_extra_shell
else
echo -e "$file_extra_shell文件不存在,跳过执行...\n"
fi
fi
}
## 脚本用法
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 "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"
make_dir $dir_config
cp -f $file_config_sample $dir_config/config.sample.sh
update_docker_entrypoint
update_depend
detect_config_version
else
echo -e "\n更新$dir_root失败,请检查原因...\n"
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
diff_cron $list_own_scripts $list_own_user $list_own_add $list_own_drop
if [ -s $list_own_drop ]; then
output_list_add_drop $list_own_drop "失效"
[[ ${AutoDelCron} == true ]] && del_cron $list_own_drop
fi
if [ -s $list_own_add ]; then
output_list_add_drop $list_own_add "新"
if [[ ${AutoAddCron} == true ]]; then
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"
fi
else
echo -e "$dir_scripts/$tmp_dir 还不存在可能是还没有clone\n"
usage
fi
}
main () {
local p1=$1
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_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