mirror of
				https://github.com/whyour/qinglong.git
				synced 2025-10-31 08:56:06 +08:00 
			
		
		
		
	增加git_diy脚本,支持自定义拉取仓库
This commit is contained in:
		
							parent
							
								
									6ad50be6fb
								
							
						
					
					
						commit
						602e2775f7
					
				
							
								
								
									
										24
									
								
								csv.sh
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								csv.sh
									
									
									
									
									
								
							|  | @ -1,24 +0,0 @@ | ||||||
| #!/usr/bin/env bash |  | ||||||
| 
 |  | ||||||
| ## 判断环境 |  | ||||||
| ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)} |  | ||||||
| LogDir=${ShellDir}/log |  | ||||||
| Income=${LogDir}/bean_income.csv |  | ||||||
| Outlay=${LogDir}/bean_outlay.csv |  | ||||||
| 
 |  | ||||||
| ## 执行 |  | ||||||
| cd ${LogDir}/jd_bean_change |  | ||||||
| for log in $(ls); do |  | ||||||
|   LogDate=$(echo ${log} | cut -c1-10) |  | ||||||
|   BeanDate=$(date "+%Y-%m-%d" -d "1 day ago ${LogDate}") |  | ||||||
| 
 |  | ||||||
|   if [[ -z $(grep "${BeanDate}" ${Income}) ]]; then |  | ||||||
|     echo -n "${BeanDate}," >> ${Income} |  | ||||||
|     grep -E "昨日收入" ${log} | grep -oE "\d+" | perl -0777 -pe "s|\n(\d+)|,\1|g" >> ${Income} |  | ||||||
|   fi |  | ||||||
| 
 |  | ||||||
|   if [[ -z $(grep "${BeanDate}" ${Outlay}) ]]; then |  | ||||||
|     echo -n "${BeanDate}," >> ${Outlay} |  | ||||||
|     grep -E "昨日支出" ${log} | grep -oE "\d+" | perl -0777 -pe "s|\n(\d+)|,\1|g" >> ${Outlay} |  | ||||||
|   fi |  | ||||||
| done |  | ||||||
|  | @ -35,6 +35,12 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories | ||||||
|     && git clone -b ${JD_BASE_BRANCH} ${JD_BASE_URL} ${JD_DIR} \ |     && git clone -b ${JD_BASE_BRANCH} ${JD_BASE_URL} ${JD_DIR} \ | ||||||
|     && cd ${JD_DIR} \ |     && cd ${JD_DIR} \ | ||||||
|     && cp -f .env.example .env \ |     && cp -f .env.example .env \ | ||||||
|  |     && ln -sf ${JD_DIR}/shell/jd.sh /usr/local/bin/jd \ | ||||||
|  |     && ln -sf ${JD_DIR}/shell/git_pull.sh /usr/local/bin/git_pull \ | ||||||
|  |     && ln -sf ${JD_DIR}/shell/rm_log.sh /usr/local/bin/rm_log \ | ||||||
|  |     && ln -sf ${JD_DIR}/shell/export_sharecodes.sh /usr/local/bin/export_sharecodes \ | ||||||
|  |     && ln -sf ${JD_DIR}/shell/git_diy.sh /usr/local/bin/diy \ | ||||||
|  |     && ln -sf ${JD_DIR}/shell/notify.sh /usr/local/bin/notify \ | ||||||
|     && yarn install \ |     && yarn install \ | ||||||
|     && yarn build \ |     && yarn build \ | ||||||
|     && yarn build-back \ |     && yarn build-back \ | ||||||
|  |  | ||||||
|  | @ -34,13 +34,13 @@ nginx -c /etc/nginx/nginx.conf | ||||||
| echo | echo | ||||||
| 
 | 
 | ||||||
| echo -e "======================3. 更新源代码========================\n" | echo -e "======================3. 更新源代码========================\n" | ||||||
| bash ${JD_DIR}/git_pull.sh | bash ${JD_DIR}/shell/git_pull.sh | ||||||
| echo | echo | ||||||
| 
 | 
 | ||||||
| echo -e "======================4. 启动挂机程序========================\n" | echo -e "======================4. 启动挂机程序========================\n" | ||||||
| . ${JD_DIR}/config/config.sh | . ${JD_DIR}/config/config.sh | ||||||
| if [ -n "${Cookie1}" ]; then | if [ -n "${Cookie1}" ]; then | ||||||
|   bash ${JD_DIR}/jd.sh hangup 2>/dev/null |   bash ${JD_DIR}/shell/jd.sh hangup 2>/dev/null | ||||||
|   echo -e "挂机程序启动成功...\n" |   echo -e "挂机程序启动成功...\n" | ||||||
| else | else | ||||||
|   echo -e "config.sh中还未填入有效的Cookie,可能是首次部署容器,因此不启动挂机程序...\n" |   echo -e "config.sh中还未填入有效的Cookie,可能是首次部署容器,因此不启动挂机程序...\n" | ||||||
|  |  | ||||||
|  | @ -272,7 +272,7 @@ ForOtherJoy6="" | ||||||
| ## 具体填法及要求详见本文件最下方“互助码填法示例” | ## 具体填法及要求详见本文件最下方“互助码填法示例” | ||||||
| ## 京喜农场助力码为 JSON 格式因此使用单引号,json 格式如下 | ## 京喜农场助力码为 JSON 格式因此使用单引号,json 格式如下 | ||||||
| ## {"smp":"22bdadsfaadsfadse8a","active":"jdnc_1_btorange210113_2","joinnum":"1"} | ## {"smp":"22bdadsfaadsfadse8a","active":"jdnc_1_btorange210113_2","joinnum":"1"} | ||||||
| ## 助力码获取可以通过 bash jd.sh jd_get_share_code now 命令获取 | ## 助力码获取可以通过 bash jd jd_get_share_code now 命令获取 | ||||||
| ## 注意:京喜农场 种植种子发生变化的时候,互助码也会变!! | ## 注意:京喜农场 种植种子发生变化的时候,互助码也会变!! | ||||||
| MyJxnc1='' | MyJxnc1='' | ||||||
| MyJxnc2='' | MyJxnc2='' | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| # 更新lxk0301大佬的js脚本,添加随机cron,日志为log/git_pull.log,每天只更新两次 | # 更新你需要的仓库的代码 | ||||||
| 55 2,13 * * * bash git_pull >> ${JD_DIR}/log/git_pull.log 2>&1 | 55 2,13 * * * bash git_pull >> ${JD_DIR}/log/git_pull.log 2>&1 | ||||||
|  | 30 * * * * bash diy i-chenzhe qx >> ${JD_DIR}/log/diy_pull.log 2>&1 | ||||||
| 
 | 
 | ||||||
| # 删除 RmLogDaysAgo 指定天数以前的旧日志,本行为不记录日志 | # 删除 RmLogDaysAgo 指定天数以前的旧日志,本行为不记录日志 | ||||||
| 57 13 * * * bash rm_log >/dev/null 2>&1 | 57 13 * * * bash rm_log >/dev/null 2>&1 | ||||||
|  |  | ||||||
							
								
								
									
										89
									
								
								shell/git_diy.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								shell/git_diy.sh
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,89 @@ | ||||||
|  | #!/usr/bin/env bash | ||||||
|  | #author:spark thanks to: https://github.com/sparkssssssss/scripts | ||||||
|  | #需要docker环境,下载本文件到容器内任意位置,以下示例是放到了/jd/scripts | ||||||
|  | #*/30 * * * *  bash diy i-chenzhe qx | ||||||
|  | 
 | ||||||
|  | declare -A BlackListDict | ||||||
|  | author=$1 | ||||||
|  | repo=$2 | ||||||
|  | #指定仓库屏蔽关键词,不添加计划任务,多个按照格式二 | ||||||
|  | BlackListDict['i-chenzhe']="_get" | ||||||
|  | BlackListDict['sparkssssssss']="smzdm|tg|xxxxxxxx" | ||||||
|  | 
 | ||||||
|  | blackword=${BlackListDict["${author}"]} | ||||||
|  | blackword=${blackword:-"wojiushigejimo"} | ||||||
|  | 
 | ||||||
|  | if [ $# != 2 ] ; then | ||||||
|  |   echo "USAGE: $0 author repo" | ||||||
|  |   exit 0; | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | diyscriptsdir=/jd/diyscripts | ||||||
|  | mkdir -p ${diyscriptsdir} | ||||||
|  | 
 | ||||||
|  | if [ ! -d "$diyscriptsdir/${author}_${repo}" ]; then | ||||||
|  |   echo -e "${author}本地仓库不存在,从gayhub拉取ing..." | ||||||
|  |   cd ${diyscriptsdir} &&  git clone https://github.com/${author}/${repo}.git ${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)) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function addnewcron { | ||||||
|  |   addname="" | ||||||
|  |   cd ${diyscriptsdir}/${author}_${repo} | ||||||
|  |   for js in `ls *.js|egrep -v $blackword`; | ||||||
|  |     do  | ||||||
|  |       croname=`echo "${author}_$js"|awk -F\. '{print $1}'` | ||||||
|  |       script_date=`cat  $js|grep ^[0-9]|awk '{print $1,$2,$3,$4,$5}'|egrep -v "[a-zA-Z]|:|\."|sort |uniq|head -n 1` | ||||||
|  |       [ -z "${script_date}" ] && script_date=`cat  $js|grep -Eo "([0-9]+|\*|[0-9]+[,-].*) ([0-9]+|\*|[0-9]+[,-].*) ([0-9]+|\*|[0-9]+[,-].*) ([0-9]+|\*|[0-9]+[,-].*) ([0-9]+|\*|[0-9][,-].*)"|sort |uniq|head -n 1` | ||||||
|  |       [ -z "${script_date}" ] && cron_min=$(rand 1 59) && cron_hour=$(rand 7 9) && script_date="${cron_min} ${cron_hour} * * *" | ||||||
|  |       [ $(grep -c -w "$croname" /jd/config/crontab.list) -eq 0 ] && sed -i "/hangup/a${script_date} bash jd $croname"  /jd/config/crontab.list && addname="${addname}\n${croname}" && echo -e "添加了新的脚本${croname}." && bash jd ${croname} now >/dev/null & | ||||||
|  |       if [ ! -f "/jd/scripts/${author}_$js" ];then | ||||||
|  |         \cp $js /jd/scripts/${author}_$js | ||||||
|  |       else | ||||||
|  |         change=$(diff $js /jd/scripts/${author}_$js) | ||||||
|  |         [ -n "${change}" ] && \cp $js /jd/scripts/${author}_$js && echo -e "${author}_$js 脚本更新了." | ||||||
|  |       fi | ||||||
|  |   done | ||||||
|  |   [ "$addname" != "" ] notify "新增 ${author} 自定义脚本" "${addname}" | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function delcron { | ||||||
|  |   delname="" | ||||||
|  |   cronfiles=$(grep "$author" /jd/config/crontab.list|grep -v "^#"|awk '{print $8}'|awk -F"${author}_" '{print $2}') | ||||||
|  |   for filename in $cronfiles; | ||||||
|  |     do | ||||||
|  |       if [ ! -f "${diyscriptsdir}/${author}_${repo}/${filename}.js" ]; then  | ||||||
|  |         sed -i "/\<bash jd ${author}_${filename}\>/d" /jd/config/crontab.list && echo -e "删除失效脚本${filename}." | ||||||
|  | 	delname="${delname}\n${author}_${filename}" | ||||||
|  |       fi | ||||||
|  |   done | ||||||
|  |   [ "$delname" != "" ] && notify  "删除 ${author} 失效脚本" "${delname}"  | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | if [[ ${gitpullstatus} -eq 0 ]] | ||||||
|  | then | ||||||
|  |   addnewcron | ||||||
|  |   delcron | ||||||
|  | else | ||||||
|  |   echo -e "$author 仓库更新失败了." | ||||||
|  |   notify "自定义仓库更新失败" "$author" | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | exit 0 | ||||||
|  | @ -2,18 +2,16 @@ | ||||||
| 
 | 
 | ||||||
| ## 文件路径、脚本网址、文件版本以及各种环境的判断 | ## 文件路径、脚本网址、文件版本以及各种环境的判断 | ||||||
| ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)} | ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)} | ||||||
| [[ ${JD_DIR} ]] && ShellJd=jd || ShellJd=${ShellDir}/jd.sh | [[ ${JD_DIR} ]] && ShellJd=jd || ShellJd=${ShellDir}/shell/jd.sh | ||||||
| LogDir=${ShellDir}/log | LogDir=${ShellDir}/log | ||||||
| [ ! -d ${LogDir} ] && mkdir -p ${LogDir} | [ ! -d ${LogDir} ] && mkdir -p ${LogDir} | ||||||
| ScriptsDir=${ShellDir}/scripts | ScriptsDir=${ShellDir}/scripts | ||||||
| Scripts2Dir=${ShellDir}/scripts2 |  | ||||||
| ConfigDir=${ShellDir}/config | ConfigDir=${ShellDir}/config | ||||||
| FileConf=${ConfigDir}/config.sh | FileConf=${ConfigDir}/config.sh | ||||||
| FileDiy=${ConfigDir}/diy.sh | FileDiy=${ConfigDir}/diy.sh | ||||||
| FileConfSample=${ShellDir}/sample/config.sh.sample | FileConfSample=${ShellDir}/sample/config.sh.sample | ||||||
| ListCron=${ConfigDir}/crontab.list | ListCron=${ConfigDir}/crontab.list | ||||||
| ListCronLxk=${ScriptsDir}/docker/crontab_list.sh | ListCronLxk=${ScriptsDir}/docker/crontab_list.sh | ||||||
| ListCronShylocks=${Scripts2Dir}/docker/crontab_list.sh |  | ||||||
| ListTask=${LogDir}/task.list | ListTask=${LogDir}/task.list | ||||||
| ListJs=${LogDir}/js.list | ListJs=${LogDir}/js.list | ||||||
| ListJsAdd=${LogDir}/js-add.list | ListJsAdd=${LogDir}/js-add.list | ||||||
|  | @ -23,8 +21,8 @@ ContentNewTask=${ShellDir}/new_task | ||||||
| ContentDropTask=${ShellDir}/drop_task | ContentDropTask=${ShellDir}/drop_task | ||||||
| SendCount=${ShellDir}/send_count | SendCount=${ShellDir}/send_count | ||||||
| isTermux=${ANDROID_RUNTIME_ROOT}${ANDROID_ROOT} | isTermux=${ANDROID_RUNTIME_ROOT}${ANDROID_ROOT} | ||||||
| ShellURL=${JD_SHELL_URL:-git@gitee.com:evine/jd_shell.git} | ShellURL=https://github.com.cnpmjs.org/whyour/qinglong | ||||||
| ScriptsURL=${JD_SCRIPTS_URL:-git@gitee.com:lxk0301/jd_scripts.git} | ScriptsURL=https://github.com.cnpmjs.org/RikudouPatrickstar/jd_scripts | ||||||
| 
 | 
 | ||||||
| ## 导入配置文件 | ## 导入配置文件 | ||||||
| function Import_Conf { | function Import_Conf { | ||||||
|  | @ -53,31 +51,16 @@ function Update_Cron { | ||||||
|     crontab ${ListCron} |     crontab ${ListCron} | ||||||
|   fi |   fi | ||||||
| } | } | ||||||
| 
 |  | ||||||
| ## 重置仓库remote url |  | ||||||
| function Reset_RepoUrl { |  | ||||||
|   if [[ ${JD_DIR} ]] && [[ ${ENABLE_RESET_REPO_URL} == true ]]; then |  | ||||||
|     if [ -d ${ShellDir}/.git ]; then |  | ||||||
|       cd ${ShellDir} |  | ||||||
|       git remote set-url origin ${ShellURL} |  | ||||||
|       git reset --hard |  | ||||||
|     fi |  | ||||||
|     if [ -d ${ScriptsDir}/.git ]; then |  | ||||||
|       cd ${ScriptsDir} |  | ||||||
|       git remote set-url origin ${ScriptsURL} |  | ||||||
|       git reset --hard |  | ||||||
|     fi |  | ||||||
|   fi |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| ## 更新shell |  | ||||||
| function Git_PullShell { | function Git_PullShell { | ||||||
|   echo -e "更新shell...\n" |   echo -e "更新shell...\n" | ||||||
|   cd ${ShellDir} |   cd ${ShellDir} | ||||||
|   git fetch --all |   git fetch --all | ||||||
|  |   git stash | ||||||
|  |   git pull | ||||||
|   ExitStatusShell=$? |   ExitStatusShell=$? | ||||||
|   git reset --hard origin/master |  | ||||||
|   echo |   echo | ||||||
|  |   git stash pop | ||||||
|  |   git reset --mixed | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ## 更新shell成功后的操作 | ## 更新shell成功后的操作 | ||||||
|  | @ -95,7 +78,6 @@ function Git_PullShellNext { | ||||||
| 
 | 
 | ||||||
| ## 克隆scripts | ## 克隆scripts | ||||||
| function Git_CloneScripts { | function Git_CloneScripts { | ||||||
|   echo -e "克隆scripts...\n" |  | ||||||
|   git clone -b master ${ScriptsURL} ${ScriptsDir} |   git clone -b master ${ScriptsURL} ${ScriptsDir} | ||||||
|   ExitStatusScripts=$? |   ExitStatusScripts=$? | ||||||
|   echo |   echo | ||||||
|  | @ -106,9 +88,16 @@ function Git_PullScripts { | ||||||
|   echo -e "更新scripts...\n" |   echo -e "更新scripts...\n" | ||||||
|   cd ${ScriptsDir} |   cd ${ScriptsDir} | ||||||
|   git fetch --all |   git fetch --all | ||||||
|  |   git rm -f i-chenzhe* | ||||||
|  |   git rm -f  moposmall* | ||||||
|  |   git rm -f qq34347476* | ||||||
|  |   git rm -f whyour* | ||||||
|  |   git stash | ||||||
|  |   git pull | ||||||
|   ExitStatusScripts=$? |   ExitStatusScripts=$? | ||||||
|   git reset --hard origin/master |  | ||||||
|   echo |   echo | ||||||
|  |   git stash pop | ||||||
|  |   git reset --mixed | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ## 更新docker-entrypoint | ## 更新docker-entrypoint | ||||||
|  | @ -274,8 +263,7 @@ function Del_Cron { | ||||||
|     crontab -l |     crontab -l | ||||||
|     echo -e "\n--------------------------------------------------------------\n" |     echo -e "\n--------------------------------------------------------------\n" | ||||||
|     if [ -d ${ScriptsDir}/node_modules ]; then |     if [ -d ${ScriptsDir}/node_modules ]; then | ||||||
|       echo -e "删除失效的定时任务:\n\n${JsDrop}" > ${ContentDropTask} |       notify "删除 lxk0301 失效脚本" "${JsDrop}" | ||||||
|       Notify_DropTask |  | ||||||
|     fi |     fi | ||||||
|   fi |   fi | ||||||
| } | } | ||||||
|  | @ -308,14 +296,12 @@ function Add_Cron { | ||||||
|       crontab -l |       crontab -l | ||||||
|       echo -e "\n--------------------------------------------------------------\n" |       echo -e "\n--------------------------------------------------------------\n" | ||||||
|       if [ -d ${ScriptsDir}/node_modules ]; then |       if [ -d ${ScriptsDir}/node_modules ]; then | ||||||
|         echo -e "成功添加新的定时任务:\n\n${JsAdd}" > ${ContentNewTask} |         notify "新增 lxk0301 自定义脚本" "${JsAdd}" | ||||||
|         Notify_NewTask |  | ||||||
|       fi |       fi | ||||||
|     else |     else | ||||||
|       echo -e "添加新的定时任务出错,请手动添加...\n" |       echo -e "添加新的定时任务出错,请手动添加...\n" | ||||||
|       if [ -d ${ScriptsDir}/node_modules ]; then |       if [ -d ${ScriptsDir}/node_modules ]; then | ||||||
|         echo -e "尝试自动添加以下新的定时任务出错,请手动添加:\n\n${JsAdd}" > ${ContentNewTask} |         notify "尝试自动添加 lxk0301 以下新的定时任务出错,请手动添加:" "${JsAdd}" | ||||||
|         Notify_NewTask |  | ||||||
|       fi |       fi | ||||||
|     fi |     fi | ||||||
|   fi |   fi | ||||||
|  | @ -336,7 +322,6 @@ echo -e "--------------------------------------------------------------\n" | ||||||
| ## 导入配置,更新cron,设置url,更新shell,复制sample,复制entrypoint,发送新配置通知 | ## 导入配置,更新cron,设置url,更新shell,复制sample,复制entrypoint,发送新配置通知 | ||||||
| Import_Conf "git_pull" | Import_Conf "git_pull" | ||||||
| Update_Cron | Update_Cron | ||||||
| Reset_RepoUrl |  | ||||||
| [ -f ${ShellDir}/panel/package.json ] && PanelDependOld=$(cat ${ShellDir}/panel/package.json) | [ -f ${ShellDir}/panel/package.json ] && PanelDependOld=$(cat ${ShellDir}/panel/package.json) | ||||||
| Git_PullShell | Git_PullShell | ||||||
| [ -f ${ShellDir}/panel/package.json ] && PanelDependNew=$(cat ${ShellDir}/panel/package.json) | [ -f ${ShellDir}/panel/package.json ] && PanelDependNew=$(cat ${ShellDir}/panel/package.json) | ||||||
|  | @ -3,7 +3,7 @@ | ||||||
| ## 路径 | ## 路径 | ||||||
| ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)} | ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)} | ||||||
| [[ ${JD_DIR} ]] && HelpJd=jd || HelpJd=jd.sh | [[ ${JD_DIR} ]] && HelpJd=jd || HelpJd=jd.sh | ||||||
| [[ ${JD_DIR} ]] && ShellJd=jd || ShellJd=${ShellDir}/jd.sh | [[ ${JD_DIR} ]] && ShellJd=jd || ShellJd=${ShellDir}/shell/jd.sh | ||||||
| ScriptsDir=${ShellDir}/scripts | ScriptsDir=${ShellDir}/scripts | ||||||
| ConfigDir=${ShellDir}/config | ConfigDir=${ShellDir}/config | ||||||
| FileConf=${ConfigDir}/config.sh | FileConf=${ConfigDir}/config.sh | ||||||
							
								
								
									
										5
									
								
								shell/notify.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								shell/notify.js
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | ||||||
|  | const notify = require('../scripts/sendNotify'); | ||||||
|  | const title = process.argv[2]; | ||||||
|  | const content = process.argv[3]; | ||||||
|  | 
 | ||||||
|  | notify.sendNotify(`${title}`, `${content}`); | ||||||
							
								
								
									
										8
									
								
								shell/notify.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								shell/notify.sh
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | ||||||
|  | #!/bin/bash | ||||||
|  | #author:spark thanks to: https://github.com/sparkssssssss/scripts | ||||||
|  | 
 | ||||||
|  | . /jd/config/config.sh | ||||||
|  | title=$(echo $1|sed 's/-/_/g') | ||||||
|  | msg=$(echo -e $2) | ||||||
|  | 
 | ||||||
|  | node /jd/shell/sendinfo.js "$title" "$msg" | ||||||
							
								
								
									
										447
									
								
								shell/update.js
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										447
									
								
								shell/update.js
									
									
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,447 @@ | ||||||
|  | /* | ||||||
|  |  * @Author: lxk0301 https://github.com/lxk0301
 | ||||||
|  |  * @Date: 2020-12-20 13:50:34 | ||||||
|  |  * @Last Modified by: lxk0301 | ||||||
|  |  * @Last Modified time: 2020-12-20 13:51:02 | ||||||
|  |  */ | ||||||
|  | const $ = new Env('通知'); | ||||||
|  | const notify = require('./scripts/sendNotify'); | ||||||
|  | const fs = require('fs'); | ||||||
|  | !(async () => { | ||||||
|  |   await update(); | ||||||
|  | })() | ||||||
|  |   .catch((e) => $.logErr(e)) | ||||||
|  |   .finally(() => $.done()); | ||||||
|  | 
 | ||||||
|  | async function update() { | ||||||
|  |   try { | ||||||
|  |     if (fs.existsSync('new_task')) { | ||||||
|  |       const newTaskContent = await fs.readFileSync('./new_task', 'utf8'); | ||||||
|  |       if (newTaskContent) { | ||||||
|  |         await notify.sendNotify('新增薅羊毛任务通知', newTaskContent); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (fs.existsSync('drop_task')) { | ||||||
|  |       const dropTaskContent = await fs.readFileSync('./drop_task', 'utf8'); | ||||||
|  |       if (dropTaskContent) { | ||||||
|  |         await notify.sendNotify('删除失效任务通知', dropTaskContent); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (fs.existsSync('version')) { | ||||||
|  |       const versionContent = await fs.readFileSync('./version', 'utf8'); | ||||||
|  |       if (versionContent) { | ||||||
|  |         await notify.sendNotify('配置文件更新通知', versionContent); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } catch (err) { | ||||||
|  |     console.error(err); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | function Env(t, e) { | ||||||
|  |   class s { | ||||||
|  |     constructor(t) { | ||||||
|  |       this.env = t; | ||||||
|  |     } | ||||||
|  |     send(t, e = 'GET') { | ||||||
|  |       t = 'string' == typeof t ? { url: t } : t; | ||||||
|  |       let s = this.get; | ||||||
|  |       return ( | ||||||
|  |         'POST' === e && (s = this.post), | ||||||
|  |         new Promise((e, i) => { | ||||||
|  |           s.call(this, t, (t, s, r) => { | ||||||
|  |             t ? i(t) : e(s); | ||||||
|  |           }); | ||||||
|  |         }) | ||||||
|  |       ); | ||||||
|  |     } | ||||||
|  |     get(t) { | ||||||
|  |       return this.send.call(this.env, t); | ||||||
|  |     } | ||||||
|  |     post(t) { | ||||||
|  |       return this.send.call(this.env, t, 'POST'); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   return new (class { | ||||||
|  |     constructor(t, e) { | ||||||
|  |       (this.name = t), | ||||||
|  |         (this.http = new s(this)), | ||||||
|  |         (this.data = null), | ||||||
|  |         (this.dataFile = 'box.dat'), | ||||||
|  |         (this.logs = []), | ||||||
|  |         (this.isMute = !1), | ||||||
|  |         (this.isNeedRewrite = !1), | ||||||
|  |         (this.logSeparator = '\n'), | ||||||
|  |         (this.startTime = new Date().getTime()), | ||||||
|  |         Object.assign(this, e), | ||||||
|  |         this.log('', `\ud83d\udd14${this.name}, \u5f00\u59cb!`); | ||||||
|  |     } | ||||||
|  |     isNode() { | ||||||
|  |       return 'undefined' != typeof module && !!module.exports; | ||||||
|  |     } | ||||||
|  |     isQuanX() { | ||||||
|  |       return 'undefined' != typeof $task; | ||||||
|  |     } | ||||||
|  |     isSurge() { | ||||||
|  |       return 'undefined' != typeof $httpClient && 'undefined' == typeof $loon; | ||||||
|  |     } | ||||||
|  |     isLoon() { | ||||||
|  |       return 'undefined' != typeof $loon; | ||||||
|  |     } | ||||||
|  |     toObj(t, e = null) { | ||||||
|  |       try { | ||||||
|  |         return JSON.parse(t); | ||||||
|  |       } catch { | ||||||
|  |         return e; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     toStr(t, e = null) { | ||||||
|  |       try { | ||||||
|  |         return JSON.stringify(t); | ||||||
|  |       } catch { | ||||||
|  |         return e; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     getjson(t, e) { | ||||||
|  |       let s = e; | ||||||
|  |       const i = this.getdata(t); | ||||||
|  |       if (i) | ||||||
|  |         try { | ||||||
|  |           s = JSON.parse(this.getdata(t)); | ||||||
|  |         } catch {} | ||||||
|  |       return s; | ||||||
|  |     } | ||||||
|  |     setjson(t, e) { | ||||||
|  |       try { | ||||||
|  |         return this.setdata(JSON.stringify(t), e); | ||||||
|  |       } catch { | ||||||
|  |         return !1; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     getScript(t) { | ||||||
|  |       return new Promise((e) => { | ||||||
|  |         this.get({ url: t }, (t, s, i) => e(i)); | ||||||
|  |       }); | ||||||
|  |     } | ||||||
|  |     runScript(t, e) { | ||||||
|  |       return new Promise((s) => { | ||||||
|  |         let i = this.getdata('@chavy_boxjs_userCfgs.httpapi'); | ||||||
|  |         i = i ? i.replace(/\n/g, '').trim() : i; | ||||||
|  |         let r = this.getdata('@chavy_boxjs_userCfgs.httpapi_timeout'); | ||||||
|  |         (r = r ? 1 * r : 20), (r = e && e.timeout ? e.timeout : r); | ||||||
|  |         const [o, h] = i.split('@'), | ||||||
|  |           a = { | ||||||
|  |             url: `http://${h}/v1/scripting/evaluate`, | ||||||
|  |             body: { script_text: t, mock_type: 'cron', timeout: r }, | ||||||
|  |             headers: { 'X-Key': o, Accept: '*/*' }, | ||||||
|  |           }; | ||||||
|  |         this.post(a, (t, e, i) => s(i)); | ||||||
|  |       }).catch((t) => this.logErr(t)); | ||||||
|  |     } | ||||||
|  |     loaddata() { | ||||||
|  |       if (!this.isNode()) return {}; | ||||||
|  |       { | ||||||
|  |         (this.fs = this.fs ? this.fs : require('fs')), | ||||||
|  |           (this.path = this.path ? this.path : require('path')); | ||||||
|  |         const t = this.path.resolve(this.dataFile), | ||||||
|  |           e = this.path.resolve(process.cwd(), this.dataFile), | ||||||
|  |           s = this.fs.existsSync(t), | ||||||
|  |           i = !s && this.fs.existsSync(e); | ||||||
|  |         if (!s && !i) return {}; | ||||||
|  |         { | ||||||
|  |           const i = s ? t : e; | ||||||
|  |           try { | ||||||
|  |             return JSON.parse(this.fs.readFileSync(i)); | ||||||
|  |           } catch (t) { | ||||||
|  |             return {}; | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     writedata() { | ||||||
|  |       if (this.isNode()) { | ||||||
|  |         (this.fs = this.fs ? this.fs : require('fs')), | ||||||
|  |           (this.path = this.path ? this.path : require('path')); | ||||||
|  |         const t = this.path.resolve(this.dataFile), | ||||||
|  |           e = this.path.resolve(process.cwd(), this.dataFile), | ||||||
|  |           s = this.fs.existsSync(t), | ||||||
|  |           i = !s && this.fs.existsSync(e), | ||||||
|  |           r = JSON.stringify(this.data); | ||||||
|  |         s | ||||||
|  |           ? this.fs.writeFileSync(t, r) | ||||||
|  |           : i | ||||||
|  |           ? this.fs.writeFileSync(e, r) | ||||||
|  |           : this.fs.writeFileSync(t, r); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     lodash_get(t, e, s) { | ||||||
|  |       const i = e.replace(/\[(\d+)\]/g, '.$1').split('.'); | ||||||
|  |       let r = t; | ||||||
|  |       for (const t of i) if (((r = Object(r)[t]), void 0 === r)) return s; | ||||||
|  |       return r; | ||||||
|  |     } | ||||||
|  |     lodash_set(t, e, s) { | ||||||
|  |       return Object(t) !== t | ||||||
|  |         ? t | ||||||
|  |         : (Array.isArray(e) || (e = e.toString().match(/[^.[\]]+/g) || []), | ||||||
|  |           (e | ||||||
|  |             .slice(0, -1) | ||||||
|  |             .reduce( | ||||||
|  |               (t, s, i) => | ||||||
|  |                 Object(t[s]) === t[s] | ||||||
|  |                   ? t[s] | ||||||
|  |                   : (t[s] = Math.abs(e[i + 1]) >> 0 == +e[i + 1] ? [] : {}), | ||||||
|  |               t, | ||||||
|  |             )[e[e.length - 1]] = s), | ||||||
|  |           t); | ||||||
|  |     } | ||||||
|  |     getdata(t) { | ||||||
|  |       let e = this.getval(t); | ||||||
|  |       if (/^@/.test(t)) { | ||||||
|  |         const [, s, i] = /^@(.*?)\.(.*?)$/.exec(t), | ||||||
|  |           r = s ? this.getval(s) : ''; | ||||||
|  |         if (r) | ||||||
|  |           try { | ||||||
|  |             const t = JSON.parse(r); | ||||||
|  |             e = t ? this.lodash_get(t, i, '') : e; | ||||||
|  |           } catch (t) { | ||||||
|  |             e = ''; | ||||||
|  |           } | ||||||
|  |       } | ||||||
|  |       return e; | ||||||
|  |     } | ||||||
|  |     setdata(t, e) { | ||||||
|  |       let s = !1; | ||||||
|  |       if (/^@/.test(e)) { | ||||||
|  |         const [, i, r] = /^@(.*?)\.(.*?)$/.exec(e), | ||||||
|  |           o = this.getval(i), | ||||||
|  |           h = i ? ('null' === o ? null : o || '{}') : '{}'; | ||||||
|  |         try { | ||||||
|  |           const e = JSON.parse(h); | ||||||
|  |           this.lodash_set(e, r, t), (s = this.setval(JSON.stringify(e), i)); | ||||||
|  |         } catch (e) { | ||||||
|  |           const o = {}; | ||||||
|  |           this.lodash_set(o, r, t), (s = this.setval(JSON.stringify(o), i)); | ||||||
|  |         } | ||||||
|  |       } else s = this.setval(t, e); | ||||||
|  |       return s; | ||||||
|  |     } | ||||||
|  |     getval(t) { | ||||||
|  |       return this.isSurge() || this.isLoon() | ||||||
|  |         ? $persistentStore.read(t) | ||||||
|  |         : this.isQuanX() | ||||||
|  |         ? $prefs.valueForKey(t) | ||||||
|  |         : this.isNode() | ||||||
|  |         ? ((this.data = this.loaddata()), this.data[t]) | ||||||
|  |         : (this.data && this.data[t]) || null; | ||||||
|  |     } | ||||||
|  |     setval(t, e) { | ||||||
|  |       return this.isSurge() || this.isLoon() | ||||||
|  |         ? $persistentStore.write(t, e) | ||||||
|  |         : this.isQuanX() | ||||||
|  |         ? $prefs.setValueForKey(t, e) | ||||||
|  |         : this.isNode() | ||||||
|  |         ? ((this.data = this.loaddata()), | ||||||
|  |           (this.data[e] = t), | ||||||
|  |           this.writedata(), | ||||||
|  |           !0) | ||||||
|  |         : (this.data && this.data[e]) || null; | ||||||
|  |     } | ||||||
|  |     initGotEnv(t) { | ||||||
|  |       (this.got = this.got ? this.got : require('got')), | ||||||
|  |         (this.cktough = this.cktough ? this.cktough : require('tough-cookie')), | ||||||
|  |         (this.ckjar = this.ckjar ? this.ckjar : new this.cktough.CookieJar()), | ||||||
|  |         t && | ||||||
|  |           ((t.headers = t.headers ? t.headers : {}), | ||||||
|  |           void 0 === t.headers.Cookie && | ||||||
|  |             void 0 === t.cookieJar && | ||||||
|  |             (t.cookieJar = this.ckjar)); | ||||||
|  |     } | ||||||
|  |     get(t, e = () => {}) { | ||||||
|  |       t.headers && | ||||||
|  |         (delete t.headers['Content-Type'], delete t.headers['Content-Length']), | ||||||
|  |         this.isSurge() || this.isLoon() | ||||||
|  |           ? (this.isSurge() && | ||||||
|  |               this.isNeedRewrite && | ||||||
|  |               ((t.headers = t.headers || {}), | ||||||
|  |               Object.assign(t.headers, { 'X-Surge-Skip-Scripting': !1 })), | ||||||
|  |             $httpClient.get(t, (t, s, i) => { | ||||||
|  |               !t && s && ((s.body = i), (s.statusCode = s.status)), e(t, s, i); | ||||||
|  |             })) | ||||||
|  |           : this.isQuanX() | ||||||
|  |           ? (this.isNeedRewrite && | ||||||
|  |               ((t.opts = t.opts || {}), Object.assign(t.opts, { hints: !1 })), | ||||||
|  |             $task.fetch(t).then( | ||||||
|  |               (t) => { | ||||||
|  |                 const { statusCode: s, statusCode: i, headers: r, body: o } = t; | ||||||
|  |                 e(null, { status: s, statusCode: i, headers: r, body: o }, o); | ||||||
|  |               }, | ||||||
|  |               (t) => e(t), | ||||||
|  |             )) | ||||||
|  |           : this.isNode() && | ||||||
|  |             (this.initGotEnv(t), | ||||||
|  |             this.got(t) | ||||||
|  |               .on('redirect', (t, e) => { | ||||||
|  |                 try { | ||||||
|  |                   if (t.headers['set-cookie']) { | ||||||
|  |                     const s = t.headers['set-cookie'] | ||||||
|  |                       .map(this.cktough.Cookie.parse) | ||||||
|  |                       .toString(); | ||||||
|  |                     this.ckjar.setCookieSync(s, null), | ||||||
|  |                       (e.cookieJar = this.ckjar); | ||||||
|  |                   } | ||||||
|  |                 } catch (t) { | ||||||
|  |                   this.logErr(t); | ||||||
|  |                 } | ||||||
|  |               }) | ||||||
|  |               .then( | ||||||
|  |                 (t) => { | ||||||
|  |                   const { | ||||||
|  |                     statusCode: s, | ||||||
|  |                     statusCode: i, | ||||||
|  |                     headers: r, | ||||||
|  |                     body: o, | ||||||
|  |                   } = t; | ||||||
|  |                   e(null, { status: s, statusCode: i, headers: r, body: o }, o); | ||||||
|  |                 }, | ||||||
|  |                 (t) => { | ||||||
|  |                   const { message: s, response: i } = t; | ||||||
|  |                   e(s, i, i && i.body); | ||||||
|  |                 }, | ||||||
|  |               )); | ||||||
|  |     } | ||||||
|  |     post(t, e = () => {}) { | ||||||
|  |       if ( | ||||||
|  |         (t.body && | ||||||
|  |           t.headers && | ||||||
|  |           !t.headers['Content-Type'] && | ||||||
|  |           (t.headers['Content-Type'] = 'application/x-www-form-urlencoded'), | ||||||
|  |         t.headers && delete t.headers['Content-Length'], | ||||||
|  |         this.isSurge() || this.isLoon()) | ||||||
|  |       ) | ||||||
|  |         this.isSurge() && | ||||||
|  |           this.isNeedRewrite && | ||||||
|  |           ((t.headers = t.headers || {}), | ||||||
|  |           Object.assign(t.headers, { 'X-Surge-Skip-Scripting': !1 })), | ||||||
|  |           $httpClient.post(t, (t, s, i) => { | ||||||
|  |             !t && s && ((s.body = i), (s.statusCode = s.status)), e(t, s, i); | ||||||
|  |           }); | ||||||
|  |       else if (this.isQuanX()) | ||||||
|  |         (t.method = 'POST'), | ||||||
|  |           this.isNeedRewrite && | ||||||
|  |             ((t.opts = t.opts || {}), Object.assign(t.opts, { hints: !1 })), | ||||||
|  |           $task.fetch(t).then( | ||||||
|  |             (t) => { | ||||||
|  |               const { statusCode: s, statusCode: i, headers: r, body: o } = t; | ||||||
|  |               e(null, { status: s, statusCode: i, headers: r, body: o }, o); | ||||||
|  |             }, | ||||||
|  |             (t) => e(t), | ||||||
|  |           ); | ||||||
|  |       else if (this.isNode()) { | ||||||
|  |         this.initGotEnv(t); | ||||||
|  |         const { url: s, ...i } = t; | ||||||
|  |         this.got.post(s, i).then( | ||||||
|  |           (t) => { | ||||||
|  |             const { statusCode: s, statusCode: i, headers: r, body: o } = t; | ||||||
|  |             e(null, { status: s, statusCode: i, headers: r, body: o }, o); | ||||||
|  |           }, | ||||||
|  |           (t) => { | ||||||
|  |             const { message: s, response: i } = t; | ||||||
|  |             e(s, i, i && i.body); | ||||||
|  |           }, | ||||||
|  |         ); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     time(t) { | ||||||
|  |       let e = { | ||||||
|  |         'M+': new Date().getMonth() + 1, | ||||||
|  |         'd+': new Date().getDate(), | ||||||
|  |         'H+': new Date().getHours(), | ||||||
|  |         'm+': new Date().getMinutes(), | ||||||
|  |         's+': new Date().getSeconds(), | ||||||
|  |         'q+': Math.floor((new Date().getMonth() + 3) / 3), | ||||||
|  |         S: new Date().getMilliseconds(), | ||||||
|  |       }; | ||||||
|  |       /(y+)/.test(t) && | ||||||
|  |         (t = t.replace( | ||||||
|  |           RegExp.$1, | ||||||
|  |           (new Date().getFullYear() + '').substr(4 - RegExp.$1.length), | ||||||
|  |         )); | ||||||
|  |       for (let s in e) | ||||||
|  |         new RegExp('(' + s + ')').test(t) && | ||||||
|  |           (t = t.replace( | ||||||
|  |             RegExp.$1, | ||||||
|  |             1 == RegExp.$1.length | ||||||
|  |               ? e[s] | ||||||
|  |               : ('00' + e[s]).substr(('' + e[s]).length), | ||||||
|  |           )); | ||||||
|  |       return t; | ||||||
|  |     } | ||||||
|  |     msg(e = t, s = '', i = '', r) { | ||||||
|  |       const o = (t) => { | ||||||
|  |         if (!t) return t; | ||||||
|  |         if ('string' == typeof t) | ||||||
|  |           return this.isLoon() | ||||||
|  |             ? t | ||||||
|  |             : this.isQuanX() | ||||||
|  |             ? { 'open-url': t } | ||||||
|  |             : this.isSurge() | ||||||
|  |             ? { url: t } | ||||||
|  |             : void 0; | ||||||
|  |         if ('object' == typeof t) { | ||||||
|  |           if (this.isLoon()) { | ||||||
|  |             let e = t.openUrl || t.url || t['open-url'], | ||||||
|  |               s = t.mediaUrl || t['media-url']; | ||||||
|  |             return { openUrl: e, mediaUrl: s }; | ||||||
|  |           } | ||||||
|  |           if (this.isQuanX()) { | ||||||
|  |             let e = t['open-url'] || t.url || t.openUrl, | ||||||
|  |               s = t['media-url'] || t.mediaUrl; | ||||||
|  |             return { 'open-url': e, 'media-url': s }; | ||||||
|  |           } | ||||||
|  |           if (this.isSurge()) { | ||||||
|  |             let e = t.url || t.openUrl || t['open-url']; | ||||||
|  |             return { url: e }; | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       }; | ||||||
|  |       this.isMute || | ||||||
|  |         (this.isSurge() || this.isLoon() | ||||||
|  |           ? $notification.post(e, s, i, o(r)) | ||||||
|  |           : this.isQuanX() && $notify(e, s, i, o(r))); | ||||||
|  |       let h = [ | ||||||
|  |         '', | ||||||
|  |         '==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3==============', | ||||||
|  |       ]; | ||||||
|  |       h.push(e), | ||||||
|  |         s && h.push(s), | ||||||
|  |         i && h.push(i), | ||||||
|  |         console.log(h.join('\n')), | ||||||
|  |         (this.logs = this.logs.concat(h)); | ||||||
|  |     } | ||||||
|  |     log(...t) { | ||||||
|  |       t.length > 0 && (this.logs = [...this.logs, ...t]), | ||||||
|  |         console.log(t.join(this.logSeparator)); | ||||||
|  |     } | ||||||
|  |     logErr(t, e) { | ||||||
|  |       const s = !this.isSurge() && !this.isQuanX() && !this.isLoon(); | ||||||
|  |       s | ||||||
|  |         ? this.log('', `\u2757\ufe0f${this.name}, \u9519\u8bef!`, t.stack) | ||||||
|  |         : this.log('', `\u2757\ufe0f${this.name}, \u9519\u8bef!`, t); | ||||||
|  |     } | ||||||
|  |     wait(t) { | ||||||
|  |       return new Promise((e) => setTimeout(e, t)); | ||||||
|  |     } | ||||||
|  |     done(t = {}) { | ||||||
|  |       const e = new Date().getTime(), | ||||||
|  |         s = (e - this.startTime) / 1e3; | ||||||
|  |       this.log( | ||||||
|  |         '', | ||||||
|  |         `\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`, | ||||||
|  |       ), | ||||||
|  |         this.log(), | ||||||
|  |         (this.isSurge() || this.isQuanX() || this.isLoon()) && $done(t); | ||||||
|  |     } | ||||||
|  |   })(t, e); | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 whyour
						whyour