-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshell_script_mod.sh
38 lines (35 loc) · 2.43 KB
/
shell_script_mod.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
## CUSTOM_SHELL_FILE for https://gitee.com/lxk0301/jd_docker/tree/master/docker
### 编辑docker-compose.yml文件添加: - CUSTOM_SHELL_FILE=https://raw.githubusercontent.com/monk-coder/dust/dust/shell_script_mod.sh
#### 容器完全启动后执行 docker exec -it jd_scripts /bin/sh -c 'crontab -l' 查看目前修行的经书
function monkcoder(){
# https://github.com/monk-coder/dust
rm -rf /monkcoder /scripts/monkcoder_*
git clone https://github.com/Sooongz/dust-bak.git /monkcoder
# 拷贝脚本
for jsname in $(find /monkcoder -name "*.js" | grep -vE "\/backup\/"); do cp ${jsname} /scripts/monkcoder_${jsname##*/}; done
# 匹配js脚本中的cron设置定时任务
for jsname in $(find /monkcoder -name "*.js" | grep -vE "\/backup\/"); do
jsnamecron="$(cat $jsname | grep -oE "/?/?cron \".*\"" | cut -d\" -f2)"
test -z "$jsnamecron" || echo "$jsnamecron node /scripts/monkcoder_${jsname##*/} >> /scripts/logs/monkcoder_${jsname##*/}.log 2>&1" >> /scripts/docker/merged_list_file.sh
done
}
function main(){
# 首次运行时拷贝docker目录下文件
[[ ! -d /jd_diy ]] && mkdir /jd_diy && cp -rf /scripts/docker/* /jd_diy
# DIY脚本执行前后信息
a_jsnum=$(ls -l /scripts | grep -oE "^-.*js$" | wc -l)
a_jsname=$(ls -l /scripts | grep -oE "^-.*js$" | grep -oE "[^ ]*js$")
monkcoder
b_jsnum=$(ls -l /scripts | grep -oE "^-.*js$" | wc -l)
b_jsname=$(ls -l /scripts | grep -oE "^-.*js$" | grep -oE "[^ ]*js$")
# DIY脚本更新TG通知
info_more=$(echo $a_jsname $b_jsname | tr " " "\n" | sort | uniq -c | grep -oE "1 .*$" | grep -oE "[^ ]*js$" | tr "\n" " ")
[[ "$a_jsnum" == "0" || "$a_jsnum" == "$b_jsnum" ]] || curl -sX POST "https://api.telegram.org/bot$TG_BOT_TOKEN/sendMessage" -d "chat_id=$TG_USER_ID&text=DIY脚本更新完成:$a_jsnum $b_jsnum $info_more" >/dev/null
# LXK脚本更新TG通知
lxktext="$(diff /jd_diy/crontab_list.sh /scripts/docker/crontab_list.sh | grep -E "^[+-]{1}[^+-]+" | grep -oE "node.*\.js" | cut -d/ -f3 | tr "\n" " ")"
test -z "$lxktext" || curl -sX POST "https://api.telegram.org/bot$TG_BOT_TOKEN/sendMessage" -d "chat_id=$TG_USER_ID&text=LXK脚本更新完成:$(cat /jd_diy/crontab_list.sh | grep -vE "^#" | wc -l) $(cat /scripts/docker/crontab_list.sh | grep -vE "^#" | wc -l) $lxktext" >/dev/null
# 拷贝docker目录下文件供下次更新时对比
cp -rf /scripts/docker/* /jd_diy
}
main