基础命令重构

1. 移除命令中 bash 依赖
2. jd命令重命名为js
3. 修改默认初始目录
4. 移除冗余代码
This commit is contained in:
whyour
2021-03-25 23:44:57 +08:00
parent 43eab41579
commit 8906472ae0
17 changed files with 133 additions and 199 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
## 路径、环境判断
ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)}
ShellDir=${QL_DIR:-$(cd $(dirname $0); pwd)}
LogDir=${ShellDir}/log
ConfigDir=${ShellDir}/config
FileConf=${ConfigDir}/config.sh
+11 -13
View File
@@ -1,7 +1,5 @@
#!/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
@@ -18,7 +16,7 @@ if [ $# != 2 ] ; then
exit 0;
fi
diyscriptsdir=/jd/diyscripts
diyscriptsdir=/ql/diyscripts
mkdir -p ${diyscriptsdir}
if [ ! -d "$diyscriptsdir/${author}_${repo}" ]; then
@@ -52,29 +50,29 @@ function addnewcron {
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
[ $(grep -c -w "$croname" /ql/config/crontab.list) -eq 0 ] && sed -i "/hangup/a${script_date} js $croname" /ql/config/crontab.list && addname="${addname}\n${croname}" && echo -e "添加了新的脚本${croname}." && js ${croname} now >/dev/null &
if [ ! -f "/ql/scripts/${author}_$js" ];then
\cp $js /ql/scripts/${author}_$js
else
change=$(diff $js /jd/scripts/${author}_$js)
[ -n "${change}" ] && \cp $js /jd/scripts/${author}_$js && echo -e "${author}_$js 脚本更新了."
change=$(diff $js /ql/scripts/${author}_$js)
[ -n "${change}" ] && \cp $js /ql/scripts/${author}_$js && echo -e "${author}_$js 脚本更新了."
fi
done
[ "$addname" != "" ] && bash notify "新增 ${author} 自定义脚本" "${addname}"
[ "$addname" != "" ] && notify "新增 ${author} 自定义脚本" "${addname}"
}
function delcron {
delname=""
cronfiles=$(grep "$author" /jd/config/crontab.list|grep -v "^#"|awk '{print $8}'|awk -F"${author}_" '{print $2}')
cronfiles=$(grep "$author" /ql/config/crontab.list|grep -v "^#"|awk '{print $8}'|awk -F"${author}_" '{print $2}')
for filename in $cronfiles;
do
if [ ! -f "${diyscriptsdir}/${author}_${repo}/${filename}.js" ]; then
sed -i "/\<bash jd ${author}_${filename}\>/d" /jd/config/crontab.list && echo -e "删除失效脚本${filename}."
sed -i "/\<js ${author}_${filename}\>/d" /ql/config/crontab.list && echo -e "删除失效脚本${filename}."
delname="${delname}\n${author}_${filename}"
fi
done
[ "$delname" != "" ] && bash notify "删除 ${author} 失效脚本" "${delname}"
[ "$delname" != "" ] && notify "删除 ${author} 失效脚本" "${delname}"
}
if [[ ${gitpullstatus} -eq 0 ]]
@@ -83,7 +81,7 @@ then
delcron
else
echo -e "$author 仓库更新失败了."
bash notify "自定义仓库更新失败" "$author"
notify "自定义仓库更新失败" "$author"
fi
exit 0
+11 -11
View File
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
## 文件路径、脚本网址、文件版本以及各种环境的判断
ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)}
[[ ${JD_DIR} ]] && ShellJd=jd || ShellJd=${ShellDir}/shell/jd.sh
ShellDir=${QL_DIR:-$(cd $(dirname $0); pwd)}
[[ ${QL_DIR} ]] && ShellJs=js
LogDir=${ShellDir}/log
[ ! -d ${LogDir} ] && mkdir -p ${LogDir}
ScriptsDir=${ShellDir}/scripts
@@ -49,7 +49,7 @@ function Update_Cron {
for ((i=1; i<${#RanHourArray[*]}; i++)); do
RanHour="${RanHour},${RanHourArray[i]}"
done
perl -i -pe "s|.+(bash.+git_pull.+log.*)|${RanMin} ${RanHour} \* \* \* sleep ${RanSleep} && \1|" ${ListCron}
perl -i -pe "s|.+(git_pull.+log.*)|${RanMin} ${RanHour} \* \* \* sleep ${RanSleep} && \1|" ${ListCron}
crontab ${ListCron}
fi
}
@@ -104,7 +104,7 @@ function Git_PullScripts {
## 更新docker-entrypoint
function Update_Entrypoint {
if [[ ${JD_DIR} ]] && [[ $(cat ${ShellDir}/docker/docker-entrypoint.sh) != $(cat /usr/local/bin/docker-entrypoint.sh) ]]; then
if [[ ${QL_DIR} ]] && [[ $(cat ${ShellDir}/docker/docker-entrypoint.sh) != $(cat /usr/local/bin/docker-entrypoint.sh) ]]; then
cp -f ${ShellDir}/docker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
chmod 777 /usr/local/bin/docker-entrypoint.sh
fi
@@ -118,7 +118,7 @@ function Update_Entrypoint {
## js-drop.list 如果上述检测文件删除了定时任务,这个文件内容将不为空
function Diff_Cron {
if [ -f ${ListCron} ]; then
if [ -n "${JD_DIR}" ]
if [ -n "${QL_DIR}" ]
then
grep -E " j[drx]_\w+" ${ListCron} | perl -pe "s|.+ (j[drx]_\w+).*|\1|" | sort -u > ${ListTask}
else
@@ -149,7 +149,7 @@ function Notify_Version {
if [ -f ${FileConf} ] && [[ "${VerConf}" != "${VerConfSample}" ]] && [[ ${UpdateDate} == $(date "+%Y-%m-%d") ]]
then
if [ ! -f ${SendCount} ]; then
bash notify "检测到配置文件config.sh.sample有更新" "更新日期: ${UpdateDate}\n当前版本: ${VerConf}\n新的版本: ${VerConfSample}\n更新内容: ${UpdateContent}\n更新说明: 如需使用新功能请对照config.sh.sample,将相关新参数手动增加到你自己的config.sh中,否则请无视本消息。本消息只在该新版本配置文件更新当天发送一次。"
notify "检测到配置文件config.sh.sample有更新" "更新日期: ${UpdateDate}\n当前版本: ${VerConf}\n新的版本: ${VerConfSample}\n更新内容: ${UpdateContent}\n更新说明: 如需使用新功能请对照config.sh.sample,将相关新参数手动增加到你自己的config.sh中,否则请无视本消息。本消息只在该新版本配置文件更新当天发送一次。"
fi
else
[ -f ${ContentVersion} ] && rm -f ${ContentVersion}
@@ -234,7 +234,7 @@ function Del_Cron {
crontab -l
echo -e "\n--------------------------------------------------------------\n"
if [ -d ${ScriptsDir}/node_modules ]; then
bash notify "删除 lxk0301 失效脚本" "${JsDrop}"
notify "删除 lxk0301 失效脚本" "${JsDrop}"
fi
fi
}
@@ -254,9 +254,9 @@ function Add_Cron {
do
if [[ ${Cron} == jd_bean_sign ]]
then
echo "4 0,9 * * * bash ${ShellJd} ${Cron}" >> ${ListCron}
echo "4 0,9 * * * ${ShellJs} ${Cron}" >> ${ListCron}
else
cat ${ListCronLxk} | grep -E "\/${Cron}\." | perl -pe "s|(^.+)node */scripts/(j[drx]_\w+)\.js.+|\1bash ${ShellJd} \2|" >> ${ListCron}
cat ${ListCronLxk} | grep -E "\/${Cron}\." | perl -pe "s|(^.+)node */scripts/(j[drx]_\w+)\.js.+|\${ShellJs} \2|" >> ${ListCron}
fi
done
@@ -267,12 +267,12 @@ function Add_Cron {
crontab -l
echo -e "\n--------------------------------------------------------------\n"
if [ -d ${ScriptsDir}/node_modules ]; then
bash notify "新增 lxk0301 自定义脚本" "${JsAdd}"
notify "新增 lxk0301 自定义脚本" "${JsAdd}"
fi
else
echo -e "添加新的定时任务出错,请手动添加...\n"
if [ -d ${ScriptsDir}/node_modules ]; then
bash notify "尝试自动添加 lxk0301 以下新的定时任务出错,请手动添加:" "${JsAdd}"
notify "尝试自动添加 lxk0301 以下新的定时任务出错,请手动添加:" "${JsAdd}"
fi
fi
fi
+8 -9
View File
@@ -1,9 +1,8 @@
#!/usr/bin/env bash
## 路径
ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)}
[[ ${JD_DIR} ]] && HelpJd=jd || HelpJd=jd.sh
[[ ${JD_DIR} ]] && ShellJd=jd || ShellJd=${ShellDir}/shell/jd.sh
ShellDir=${QL_DIR:-$(cd $(dirname $0); pwd)}
[[ ${QL_DIR} ]] && ShellJS=js
ScriptsDir=${ShellDir}/scripts
ConfigDir=${ShellDir}/config
FileConf=${ConfigDir}/config.sh
@@ -142,11 +141,11 @@ function Random_Delay {
## 使用说明
function Help {
echo -e "本脚本的用法为:"
echo -e "1. bash ${HelpJd} xxx # 如果设置了随机延迟并且当时时间不在0-2、30-31、59分内,将随机延迟一定秒数"
echo -e "2. bash ${HelpJd} xxx now # 无论是否设置了随机延迟,均立即运行"
echo -e "3. bash ${HelpJd} runall # 运行所有非挂机脚本,非常耗时"
echo -e "4. bash ${HelpJd} hangup # 重启挂机程序"
echo -e "5. bash ${HelpJd} resetpwd # 重置控制面板用户名和密码"
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}
@@ -203,7 +202,7 @@ function Run_All {
done
for file in $(cat ${ListJs}); do
echo -e "==================== 运行 $file.js 脚本 ====================\n"
bash ${ShellJd} $file now
${ShellJS} $file now
done
}
+1 -1
View File
@@ -1,4 +1,4 @@
const notify = require('/jd/scripts/sendNotify');
const notify = require('/ql/scripts/sendNotify');
const title = process.argv[2];
const content = process.argv[3];
+3 -3
View File
@@ -1,9 +1,9 @@
#!/bin/bash
#author:spark thanks to: https://github.com/sparkssssssss/scripts
. /jd/config/cookie.sh
. /jd/config/config.sh
. /ql/config/cookie.sh
. /ql/config/config.sh
title=$(echo $1|sed 's/-/_/g')
msg=$(echo -e $2)
node /jd/shell/notify.js "$title" "$msg"
node /ql/shell/notify.js "$title" "$msg"
+1 -1
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)}
ShellDir=${QL_DIR:-$(cd $(dirname $0); pwd)}
echo -e "更新shell...\n"
cd ${ShellDir}
+1 -1
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
## 判断环境
ShellDir=${JD_DIR:-$(cd $(dirname $0); pwd)}
ShellDir=${QL_DIR:-$(cd $(dirname $0); pwd)}
LogDir=${ShellDir}/log
## 导入配置文件