mirror of
https://github.com/juewuy/ShellCrash.git
synced 2024-11-16 03:32:34 +08:00
v1.8.5d
~全面适配singbox内核(自定义节点和规则相关功能除外) ·增加了singbox专属dns模式-mix模式 ·增加了singbox数据库文件下载 ·增加从/tmp导入singbox内核及singbox配置文件的功能 ~正式改名为ShellCrash并调整脚本内相关说明 ~重写systemd和procd启动脚本,优化启动流程和启动日志 ~重写保守模式及本机代理相关功能,适配singbox内核 ~增加第三方Geo数据库下载功能 ~任务功能优化,增加旧版任务管理,增加可定时系统重启的任务 ~保守模式启动优化 ~修改部分在线生成服务器以适配singbox配置生成 ~自定义clash节点功能提示优化,修复相关bug ~修复推荐任务每10分钟保存节点配置未生效的bug
This commit is contained in:
parent
101bbae2ba
commit
ce907f5a6d
14
install.sh
14
install.sh
|
@ -174,7 +174,7 @@ if [ ! -w $dir ];then
|
||||||
else
|
else
|
||||||
$echo "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)"
|
$echo "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)"
|
||||||
read -p "确认安装?(1/0) > " res
|
read -p "确认安装?(1/0) > " res
|
||||||
[ "$res" = "1" ] && CRASHDIR=$dir/clash || setdir
|
[ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
install(){
|
install(){
|
||||||
|
@ -225,20 +225,20 @@ read -p "请输入相应数字 > " num
|
||||||
if [ -z $num ];then
|
if [ -z $num ];then
|
||||||
echo 安装已取消! && exit 1;
|
echo 安装已取消! && exit 1;
|
||||||
elif [ "$num" = "2" ];then
|
elif [ "$num" = "2" ];then
|
||||||
webget /tmp/clashrelease $url_cdn@master/bin/release_version echoon rediroff 2>/tmp/clashrelease
|
webget /tmp/release_version $url_cdn@master/bin/release_version echoon rediroff 2>/tmp/release_version
|
||||||
if [ "$result" = "200" ];then
|
if [ "$result" = "200" ];then
|
||||||
release_new=$(cat /tmp/clashrelease | head -1)
|
release_new=$(cat /tmp/release_version | head -1)
|
||||||
url_dl="$url_cdn@$release_new"
|
url_dl="$url_cdn@$release_new"
|
||||||
else
|
else
|
||||||
$echo "\033[33m无法获取稳定版安装地址,将尝试安装公测版!\033[0m"
|
$echo "\033[33m无法获取稳定版安装地址,将尝试安装公测版!\033[0m"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
[ -z "$url_dl" ] && url_dl=$url
|
[ -z "$url_dl" ] && url_dl=$url
|
||||||
webget /tmp/clashversion "$url_dl/bin/version" echooff
|
webget /tmp/test_version "$url_dl/bin/version" echooff
|
||||||
[ "$result" = "200" ] && versionsh=$(cat /tmp/clashversion | grep "versionsh" | awk -F "=" '{print $2}')
|
[ "$result" = "200" ] && versionsh=$(cat /tmp/test_version | grep "versionsh" | awk -F "=" '{print $2}')
|
||||||
[ -z "$release_new" ] && release_new=$versionsh
|
[ -z "$release_new" ] && release_new=$versionsh
|
||||||
rm -rf /tmp/clashversion
|
rm -rf /tmp/test_version
|
||||||
rm -rf /tmp/clashrelease
|
rm -rf /tmp/release_version
|
||||||
tarurl=$url_dl/bin/ShellCrash.tar.gz
|
tarurl=$url_dl/bin/ShellCrash.tar.gz
|
||||||
|
|
||||||
#输出
|
#输出
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
# ID&类型 说明 地址 其他说明 (类型:100-稳定源;200-测试源;300-基础sub;400-meta_sub;500-规则地址)
|
# ID&类型 说明 地址 其他说明 (类型:100-稳定源;200-测试源;300-基础sub;400-meta_sub;500-规则地址)
|
||||||
|
|
||||||
101 Jsdelivr-CDN源 https://fastly.jsdelivr.net/gh/juewuy/ShellClash 稳定版
|
101 Jsdelivr-CDN源 https://fastly.jsdelivr.net/gh/juewuy/ShellCrash 稳定版
|
||||||
102 Github源(须clash服务启用) https://raw.githubusercontent.com/juewuy/ShellClash 稳定版
|
102 Github源(须clash服务启用) https://raw.githubusercontent.com/juewuy/ShellCrash 稳定版
|
||||||
|
|
||||||
201 Jsdelivr-CDN源 https://fastly.jsdelivr.net/gh/juewuy/ShellClash@master 公测版
|
201 Jsdelivr-CDN源 https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master 公测版
|
||||||
202 ShellClash自建源 https://gh.jwsc.eu.org/master 公测版
|
202 ShellClash自建源 https://gh.jwsc.eu.org/master 公测版
|
||||||
203 ShellClash-cfworkers源 https://gh.shellclash.workers.dev/https://raw.githubusercontent.com/juewuy/ShellClash 公测版
|
203 ShellClash-cfworkers源 https://gh.shellclash.workers.dev/https://raw.githubusercontent.com/juewuy/ShellCrash 公测版
|
||||||
204 Github源(须clash服务启用) https://raw.githubusercontent.com/juewuy/ShellClash/master 公测版
|
204 Github源(须clash服务启用) https://raw.githubusercontent.com/juewuy/ShellCrash/master 公测版
|
||||||
205 (请加讨论组-https://t.me/ShellClash) http://t.jwsc.eu.org 内测版
|
205 (请加讨论组-https://t.me/ShellClash) http://t.jwsc.eu.org 内测版
|
||||||
206 wwng2333自建CN源 https://mirrors.csgo.ovh/ShellClash 公测版
|
206 wwng2333自建CN源 https://mirrors.csgo.ovh/ShellClash 公测版
|
||||||
|
|
||||||
301 墙洞提供 https://api.dler.io
|
301 墙洞提供,不支持vless|hy https://api.dler.io
|
||||||
302 SUB作者提供 https://sub.xeton.dev
|
302 SUB作者提供,不支持vless|hy https://sub.xeton.dev
|
||||||
303 猫熊提供 https://sub.maoxiongnet.com
|
303 品云提供,不支持vless|hy https://sub.id9.cc
|
||||||
|
|
||||||
401 肥羊提供(有广告),支持vless|hy https://sub.d1.mk
|
401 肥羊提供(有广告),支持vless|hy2 https://sub.d1.mk
|
||||||
402 品云提供,支持vless|hy https://v.id9.cc
|
402 肥羊提供(有广告),支持vless|hy2 https://api.v1.mk
|
||||||
403 作者提供,支持vless|hy https://sub.jwsc.eu.org
|
403 作者提供,支持vless|hy2 https://sub.jwsc.eu.org
|
||||||
|
|
||||||
497 作者提供,未加密仅备用 http://sub2.jwsc.eu.org
|
497 作者提供,未加密仅备用 http://sub2.jwsc.eu.org
|
||||||
498 本地服务器 http://127.0.0.1:25500
|
498 本地服务器 http://127.0.0.1:25500
|
||||||
|
|
||||||
501 Acl4SSR全能优化版 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash.ini (推荐)
|
501 Acl4SSR全能优化版 https://github.com/juewuy/ShellCrash/raw/master/rules/ShellClash.ini (推荐)
|
||||||
502 Acl4SSR精简优化版 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Mini.ini (推荐)
|
502 Acl4SSR精简优化版 https://github.com/juewuy/ShellCrash/raw/master/rules/ShellClash_Mini.ini (推荐)
|
||||||
503 Acl4SSR全能优化+去广告增强 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Block.ini
|
503 Acl4SSR全能优化+去广告增强 https://github.com/juewuy/ShellCrash/raw/master/rules/ShellClash_Block.ini
|
||||||
504 Acl4SSR极简版 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Nano.ini (适合自建节点)
|
504 Acl4SSR极简版 https://github.com/juewuy/ShellCrash/raw/master/rules/ShellClash_Nano.ini (适合自建节点)
|
||||||
505 Acl4SSR分流&游戏增强 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Full.ini
|
505 Acl4SSR分流&游戏增强 https://github.com/juewuy/ShellCrash/raw/master/rules/ShellClash_Full.ini
|
||||||
506 Acl4SSR分流&游戏&去广告增强 https://github.com/juewuy/ShellClash/raw/master/rules/ShellClash_Full_Block.ini (低性能设备慎用)
|
506 Acl4SSR分流&游戏&去广告增强 https://github.com/juewuy/ShellCrash/raw/master/rules/ShellClash_Full_Block.ini (低性能设备慎用)
|
||||||
507 洞主规则精简版 https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_clash.ini
|
507 洞主规则精简版 https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_clash.ini
|
||||||
508 洞主规则重度完整版 https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_dler.ini
|
508 洞主规则重度完整版 https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_dler.ini
|
||||||
509 Acl4SSR多国精简 https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiCountry.ini
|
509 Acl4SSR多国精简 https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiCountry.ini
|
||||||
|
|
|
@ -3,14 +3,16 @@
|
||||||
101#$CRASHDIR/start.sh start#启动clash服务
|
101#$CRASHDIR/start.sh start#启动clash服务
|
||||||
102#$CRASHDIR/start.sh stop#停止clash服务
|
102#$CRASHDIR/start.sh stop#停止clash服务
|
||||||
103#$CRASHDIR/start.sh restart#重启clash服务
|
103#$CRASHDIR/start.sh restart#重启clash服务
|
||||||
104#$CRASHDIR/start.sh getyaml && $CRASHDIR/start.sh restart#更新订阅并重启服务
|
104#$CRASHDIR/start.sh update_config#更新订阅并重启服务
|
||||||
105#$CRASHDIR/start.sh updateyaml#热更新订阅
|
105#$CRASHDIR/start.sh hotupdate#热更新订阅
|
||||||
106#$CRASHDIR/start.sh web_save#自动保存面板配置
|
106#$CRASHDIR/start.sh web_save#自动保存面板配置
|
||||||
107#$CRASHDIR/start.sh ntp#自动同步ntp时间
|
107#$CRASHDIR/task/task.sh ntp#自动同步ntp时间
|
||||||
|
|
||||||
111#$CRASHDIR/task/task.sh update_core#自动更新内核
|
111#$CRASHDIR/task/task.sh update_core#自动更新内核
|
||||||
112#$CRASHDIR/task/task.sh update_shellclash#自动更新脚本
|
112#$CRASHDIR/task/task.sh update_shellclash#自动更新脚本
|
||||||
113#$CRASHDIR/task/task.sh update_mmdb#自动更新数据库文件
|
113#$CRASHDIR/task/task.sh update_mmdb#自动更新数据库文件
|
||||||
|
|
||||||
121#$CRASHDIR/task/task.sh reset_firewall#重设透明路由防火墙
|
121#$CRASHDIR/task/task.sh reset_firewall#重设透明路由防火墙
|
||||||
|
122#reboot#重启路由设备(慎用)
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Copyright (C) Juewuy
|
# Copyright (C) Juewuy
|
||||||
|
|
||||||
version=1.8.3e
|
version=1.8.5d
|
||||||
|
|
||||||
setdir(){
|
setdir(){
|
||||||
dir_avail(){
|
dir_avail(){
|
||||||
|
@ -119,16 +119,16 @@ if [ ! -w $dir ];then
|
||||||
else
|
else
|
||||||
echo -e "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)"
|
echo -e "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)"
|
||||||
read -p "确认安装?(1/0) > " res
|
read -p "确认安装?(1/0) > " res
|
||||||
[ "$res" = "1" ] && CRASHDIR=$dir/clash || setdir
|
[ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
setconfig(){
|
setconfig(){
|
||||||
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
||||||
[ -z "$3" ] && configpath=$CRASHDIR/configs/ShellCrash.cfg || configpath=$3
|
[ -z "$3" ] && configpath=${CRASHDIR}/configs/ShellCrash.cfg || configpath="${3}"
|
||||||
[ -n "$(grep -E "^${1}=" $configpath)" ] && sed -i "s#^${1}=\(.*\)#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath
|
[ -n "$(grep "${1}=" "$configpath")" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath
|
||||||
}
|
}
|
||||||
|
|
||||||
$CRASHDIR/start.sh stop 2>/dev/null #防止进程冲突
|
${CRASHDIR}/start.sh stop 2>/dev/null #防止进程冲突
|
||||||
#特殊固件识别及标记
|
#特殊固件识别及标记
|
||||||
[ -f "/etc/storage/started_script.sh" ] && {
|
[ -f "/etc/storage/started_script.sh" ] && {
|
||||||
systype=Padavan #老毛子固件
|
systype=Padavan #老毛子固件
|
||||||
|
@ -144,30 +144,29 @@ $CRASHDIR/start.sh stop 2>/dev/null #防止进程冲突
|
||||||
|
|
||||||
#检查环境变量
|
#检查环境变量
|
||||||
[ -z "$CRASHDIR" -a -n "$clashdir" ] && CRASHDIR=$clashdir
|
[ -z "$CRASHDIR" -a -n "$clashdir" ] && CRASHDIR=$clashdir
|
||||||
[ -z "$CRASHDIR" -a -d /tmp/SC_tmp ] && {
|
[ -z "$CRASHDIR" -a -d /tmp/SC_tmp ] && setdir
|
||||||
setdir
|
|
||||||
}
|
|
||||||
#移动文件
|
#移动文件
|
||||||
mkdir -p $CRASHDIR
|
mkdir -p ${CRASHDIR}
|
||||||
mv -f /tmp/SC_tmp/* $CRASHDIR 2>/dev/null
|
mv -f /tmp/SC_tmp/* ${CRASHDIR} 2>/dev/null
|
||||||
|
|
||||||
#初始化
|
#初始化
|
||||||
mkdir -p $CRASHDIR/configs
|
mkdir -p ${CRASHDIR}/configs
|
||||||
[ -f "$CRASHDIR/configs/ShellCrash.cfg" ] || echo '#ShellCrash配置文件,不明勿动!' > $CRASHDIR/configs/ShellCrash.cfg
|
[ -f "${CRASHDIR}/configs/ShellCrash.cfg" ] || echo '#ShellCrash配置文件,不明勿动!' > ${CRASHDIR}/configs/ShellCrash.cfg
|
||||||
#本地安装跳过新手引导
|
#本地安装跳过新手引导
|
||||||
#[ -z "$url" ] && setconfig userguide 1
|
#[ -z "$url" ] && setconfig userguide 1
|
||||||
#判断系统类型写入不同的启动文件
|
#判断系统类型写入不同的启动文件
|
||||||
if [ -f /etc/rc.common ] && [ -n "$(pidof procd)" ];then
|
if [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ];then
|
||||||
#设为init.d方式启动
|
#设为init.d方式启动
|
||||||
cp -f $CRASHDIR/crash.rc /etc/init.d/shellcrash
|
cp -f ${CRASHDIR}/shellcrash.procd /etc/init.d/shellcrash
|
||||||
chmod 755 /etc/init.d/shellcrash
|
chmod 755 /etc/init.d/shellcrash
|
||||||
else
|
else
|
||||||
[ -w /etc/systemd/system ] && sysdir=/etc/systemd/system
|
|
||||||
[ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system
|
[ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system
|
||||||
if [ -n "$sysdir" -a -z "$WSL_DISTRO_NAME" ];then #wsl环境不使用systemd
|
[ -w /etc/systemd/system ] && sysdir=/etc/systemd/system
|
||||||
|
if [ -n "$sysdir" -a "$USER" = "root" -a "$(cat /proc/1/comm)" = "systemd" ];then
|
||||||
#设为systemd方式启动
|
#设为systemd方式启动
|
||||||
mv -f $CRASHDIR/shellcrash.service $sysdir/shellcrash.service 2>/dev/null
|
mv -f ${CRASHDIR}/shellcrash.service $sysdir/shellcrash.service 2>/dev/null
|
||||||
sed -i "s%/etc/ShellCrash%$CRASHDIR%g" $sysdir/shellcrash.service
|
sed -i "s%/etc/ShellCrash%$CRASHDIR%g" $sysdir/shellcrash.service
|
||||||
|
rm -rf $sysdir/clash.service #旧版文件清理
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
else
|
else
|
||||||
#设为保守模式启动
|
#设为保守模式启动
|
||||||
|
@ -176,9 +175,23 @@ else
|
||||||
fi
|
fi
|
||||||
#修饰文件及版本号
|
#修饰文件及版本号
|
||||||
type bash &>/dev/null && shtype=bash || shtype=sh
|
type bash &>/dev/null && shtype=bash || shtype=sh
|
||||||
sed -i "s|/bin/sh|/bin/$shtype|" $CRASHDIR/start.sh
|
for file in start.sh task.sh ;do
|
||||||
chmod 755 $CRASHDIR/start.sh
|
sed -i "s|/bin/sh|/bin/$shtype|" ${CRASHDIR}/${file}
|
||||||
|
chmod 755 ${CRASHDIR}/${file}
|
||||||
|
done
|
||||||
setconfig versionsh_l $version
|
setconfig versionsh_l $version
|
||||||
|
#生成用于执行systemd及procd服务的变量文件
|
||||||
|
TMPDIR='/tmp/ShellCrash'
|
||||||
|
BINDIR=${CRASHDIR}
|
||||||
|
touch ${CRASHDIR}/configs/command.env
|
||||||
|
setconfig TMPDIR ${TMPDIR} ${CRASHDIR}/configs/command.env
|
||||||
|
setconfig BINDIR ${BINDIR} ${CRASHDIR}/configs/command.env
|
||||||
|
if [ -x ${CRASHDIR}/CrashCore ] && ${CRASHDIR}/CrashCore version &>/dev/null ;then
|
||||||
|
COMMAND='"$BINDIR/CrashCore run -D $BINDIR -c $TMPDIR/config.json"'
|
||||||
|
else
|
||||||
|
COMMAND='"$BINDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"'
|
||||||
|
fi
|
||||||
|
setconfig COMMAND "$COMMAND" ${CRASHDIR}/configs/command.env
|
||||||
#设置更新地址
|
#设置更新地址
|
||||||
[ -n "$url" ] && setconfig update_url $url
|
[ -n "$url" ] && setconfig update_url $url
|
||||||
#设置环境变量
|
#设置环境变量
|
||||||
|
@ -212,7 +225,7 @@ fi
|
||||||
}
|
}
|
||||||
#镜像化OpenWrt(snapshot)额外设置
|
#镜像化OpenWrt(snapshot)额外设置
|
||||||
if [ "$systype" = "mi_snapshot" -o "$systype" = "ng_snapshot" ];then
|
if [ "$systype" = "mi_snapshot" -o "$systype" = "ng_snapshot" ];then
|
||||||
chmod 755 $CRASHDIR/misnap_init.sh
|
chmod 755 ${CRASHDIR}/misnap_init.sh
|
||||||
uci delete firewall.ShellClash 2>/dev/null
|
uci delete firewall.ShellClash 2>/dev/null
|
||||||
uci delete firewall.ShellCrash 2>/dev/null
|
uci delete firewall.ShellCrash 2>/dev/null
|
||||||
uci set firewall.ShellCrash=include
|
uci set firewall.ShellCrash=include
|
||||||
|
@ -222,11 +235,11 @@ if [ "$systype" = "mi_snapshot" -o "$systype" = "ng_snapshot" ];then
|
||||||
uci commit firewall
|
uci commit firewall
|
||||||
setconfig systype $systype
|
setconfig systype $systype
|
||||||
else
|
else
|
||||||
rm -rf $CRASHDIR/misnap_init.sh
|
rm -rf ${CRASHDIR}/misnap_init.sh
|
||||||
fi
|
fi
|
||||||
#华硕USB启动额外设置
|
#华硕USB启动额外设置
|
||||||
[ "$usb_status" = "1" ] && {
|
[ "$usb_status" = "1" ] && {
|
||||||
echo "$CRASHDIR/start.sh init #ShellCrash初始化脚本" > $CRASHDIR/asus_usb_mount.sh
|
echo "$CRASHDIR/start.sh init #ShellCrash初始化脚本" > ${CRASHDIR}/asus_usb_mount.sh
|
||||||
nvram set script_usbmount="$CRASHDIR/asus_usb_mount.sh"
|
nvram set script_usbmount="$CRASHDIR/asus_usb_mount.sh"
|
||||||
nvram commit
|
nvram commit
|
||||||
}
|
}
|
||||||
|
@ -234,39 +247,43 @@ fi
|
||||||
rm -rf /tmp/*rash*gz
|
rm -rf /tmp/*rash*gz
|
||||||
rm -rf /tmp/SC_tmp
|
rm -rf /tmp/SC_tmp
|
||||||
#转换&清理旧版本文件
|
#转换&清理旧版本文件
|
||||||
mkdir -p $CRASHDIR/yamls
|
mkdir -p ${CRASHDIR}/yamls
|
||||||
mkdir -p $CRASHDIR/tools
|
mkdir -p ${CRASHDIR}/jsons
|
||||||
mkdir -p $CRASHDIR/task
|
mkdir -p ${CRASHDIR}/tools
|
||||||
|
mkdir -p ${CRASHDIR}/task
|
||||||
for file in config.yaml.bak user.yaml proxies.yaml proxy-groups.yaml rules.yaml others.yaml ;do
|
for file in config.yaml.bak user.yaml proxies.yaml proxy-groups.yaml rules.yaml others.yaml ;do
|
||||||
mv -f $CRASHDIR/$file $CRASHDIR/yamls/$file 2>/dev/null
|
mv -f ${CRASHDIR}/$file ${CRASHDIR}/yamls/$file 2>/dev/null
|
||||||
done
|
done
|
||||||
[ ! -L $CRASHDIR/config.yaml ] && mv -f $CRASHDIR/config.yaml $CRASHDIR/yamls/config.yaml 2>/dev/null
|
[ ! -L ${CRASHDIR}/config.yaml ] && mv -f ${CRASHDIR}/config.yaml ${CRASHDIR}/yamls/config.yaml 2>/dev/null
|
||||||
for file in fake_ip_filter mac web_save servers.list fake_ip_filter.list fallback_filter.list;do
|
for file in fake_ip_filter mac web_save servers.list fake_ip_filter.list fallback_filter.list;do
|
||||||
mv -f $CRASHDIR/$file $CRASHDIR/configs/$file 2>/dev/null
|
mv -f ${CRASHDIR}/$file ${CRASHDIR}/configs/$file 2>/dev/null
|
||||||
done
|
done
|
||||||
#配置文件改名
|
#配置文件改名
|
||||||
mv -f $CRASHDIR/mark $CRASHDIR/configs/ShellCrash.cfg 2>/dev/null
|
mv -f ${CRASHDIR}/mark ${CRASHDIR}/configs/ShellCrash.cfg 2>/dev/null
|
||||||
mv -f $CRASHDIR/configs/ShellClash.cfg $CRASHDIR/configs/ShellCrash.cfg 2>/dev/null
|
mv -f ${CRASHDIR}/configs/ShellClash.cfg ${CRASHDIR}/configs/ShellCrash.cfg 2>/dev/null
|
||||||
#内核改名
|
#内核改名
|
||||||
mv -f $CRASHDIR/clash $CRASHDIR/CrashCore 2>/dev/null
|
mv -f ${CRASHDIR}/clash ${CRASHDIR}/CrashCore 2>/dev/null
|
||||||
for file in dropbear_rsa_host_key authorized_keys tun.ko ShellDDNS.sh;do
|
for file in dropbear_rsa_host_key authorized_keys tun.ko ShellDDNS.sh;do
|
||||||
mv -f $CRASHDIR/$file $CRASHDIR/tools/$file 2>/dev/null
|
mv -f ${CRASHDIR}/$file ${CRASHDIR}/tools/$file 2>/dev/null
|
||||||
done
|
done
|
||||||
for file in cron task.sh task.list;do
|
for file in cron task.sh task.list;do
|
||||||
mv -f $CRASHDIR/$file $CRASHDIR/task/$file 2>/dev/null
|
mv -f ${CRASHDIR}/$file ${CRASHDIR}/task/$file 2>/dev/null
|
||||||
done
|
done
|
||||||
chmod 755 $CRASHDIR/task/task.sh
|
chmod 755 ${CRASHDIR}/task/task.sh
|
||||||
#旧版文件清理
|
#旧版文件清理
|
||||||
rm -rf $sysdir/shellcrash.service
|
|
||||||
|
rm -rf /etc/init.d/clash
|
||||||
|
rm -rf $CRASHDIR/clash.sh
|
||||||
for file in log shellcrash.service mark? mark.bak;do
|
for file in log shellcrash.service mark? mark.bak;do
|
||||||
rm -rf $CRASHDIR/$file
|
rm -rf ${CRASHDIR}/$file
|
||||||
done
|
done
|
||||||
#旧版变量改名
|
#旧版变量改名
|
||||||
sed -i "s/clashcore/crashcore/g" $configpath
|
sed -i "s/clashcore/crashcore/g" $configpath
|
||||||
|
sed -i "s/clash.meta/meta/g" $configpath
|
||||||
sed -i "s/ShellClash/ShellCrash/g" $configpath
|
sed -i "s/ShellClash/ShellCrash/g" $configpath
|
||||||
#旧版任务清理
|
#旧版任务清理
|
||||||
$CRASHDIR/start.sh cronset "clash服务" 2>/dev/null
|
${CRASHDIR}/start.sh cronset "clash服务" 2>/dev/null
|
||||||
$CRASHDIR/start.sh cronset "订阅链接" 2>/dev/null
|
${CRASHDIR}/start.sh cronset "订阅链接" 2>/dev/null
|
||||||
$CRASHDIR/start.sh cronset "ShellCrash初始化" 2>/dev/null
|
${CRASHDIR}/start.sh cronset "ShellCrash初始化" 2>/dev/null
|
||||||
sleep 1
|
sleep 1
|
||||||
echo -e "\033[32m脚本初始化完成,请输入\033[30;47m crash \033[0;33m命令开始使用!\033[0m"
|
echo -e "\033[32m脚本初始化完成,请输入\033[30;47m crash \033[0;33m命令开始使用!\033[0m"
|
||||||
|
|
434
scripts/menu.sh
434
scripts/menu.sh
File diff suppressed because it is too large
Load Diff
|
@ -52,12 +52,12 @@ init(){
|
||||||
#初始化环境变量
|
#初始化环境变量
|
||||||
sed -i "/alias crash/d" $profile
|
sed -i "/alias crash/d" $profile
|
||||||
sed -i "/export CRASHDIR/d" $profile
|
sed -i "/export CRASHDIR/d" $profile
|
||||||
echo "alias crash=\"$CRASHDIR/menu.sh\"" >>$profile
|
echo "alias crash=\"sh $CRASHDIR/menu.sh\"" >>$profile
|
||||||
echo "export CRASHDIR=\"$CRASHDIR\"" >>$profile
|
echo "export CRASHDIR=\"$CRASHDIR\"" >>$profile
|
||||||
#软固化功能
|
#软固化功能
|
||||||
autoSSH
|
autoSSH
|
||||||
#设置init.d服务
|
#设置init.d服务
|
||||||
cp -f $CRASHDIR/shellcrash.rc /etc/init.d/shellcrash
|
cp -f $CRASHDIR/shellcrash.procd /etc/init.d/shellcrash
|
||||||
chmod 755 /etc/init.d/shellcrash
|
chmod 755 /etc/init.d/shellcrash
|
||||||
#启动服务
|
#启动服务
|
||||||
if [ ! -f $CRASHDIR/.dis_startup ]; then
|
if [ ! -f $CRASHDIR/.dis_startup ]; then
|
||||||
|
|
|
@ -8,9 +8,7 @@ USE_PROCD=1
|
||||||
#获取目录
|
#获取目录
|
||||||
CRASHDIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}')
|
CRASHDIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}')
|
||||||
[ -z "$CRASHDIR" ] && CRASHDIR=$(cat ~/.bashrc | grep CRASHDIR | awk -F "\"" '{print $2}')
|
[ -z "$CRASHDIR" ] && CRASHDIR=$(cat ~/.bashrc | grep CRASHDIR | awk -F "\"" '{print $2}')
|
||||||
BINDIR=$(cat $DIR/configs/ShellCrash.cfg | grep bindir | awk -F "=" '{print $2}')
|
source ${CRASHDIR}/configs/command.env #加载启动命令和启动目录
|
||||||
[ -z "$BINDIR" ] && BINDIR=$DIR
|
|
||||||
source $DIR/configs/service.env
|
|
||||||
|
|
||||||
start_service() {
|
start_service() {
|
||||||
#检测必须文件
|
#检测必须文件
|
||||||
|
@ -19,12 +17,16 @@ start_service() {
|
||||||
#使用procd创建clash后台进程
|
#使用procd创建clash后台进程
|
||||||
procd_open_instance
|
procd_open_instance
|
||||||
procd_set_param respawn
|
procd_set_param respawn
|
||||||
|
procd_set_param command $COMMAND
|
||||||
procd_set_param stderr 0
|
procd_set_param stderr 0
|
||||||
procd_set_param stdout 0
|
procd_set_param stdout 0
|
||||||
procd_set_param command $COMMAND
|
|
||||||
procd_close_instance
|
procd_close_instance
|
||||||
#其他设置
|
#启动结束执行
|
||||||
$CRASHDIR/start.sh afstart
|
$CRASHDIR/start.sh afstart
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
stop_service(){
|
||||||
|
procd_close_instance
|
||||||
|
$CRASHDIR/start.sh stop_firewall
|
||||||
|
$CRASHDIR/start.sh unset_proxy
|
||||||
|
}
|
|
@ -7,10 +7,10 @@ Type=simple
|
||||||
User=root
|
User=root
|
||||||
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
|
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
|
||||||
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
|
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
|
||||||
EnvironmentFile=/etc/ShellCrash/configs/systemd.env
|
ExecStartPre=/etc/ShellCrash/start.sh bfstart
|
||||||
ExecStartPre=$CRASHDIR/start.sh bfstart
|
ExecStart=/etc/ShellCrash/CrashCore run -D /etc/ShellCrash -c /tmp/ShellCrash/config.json
|
||||||
ExecStart=$ExecStart
|
ExecStartPost=/etc/ShellCrash/start.sh afstart
|
||||||
ExecStartPost=$CRASHDIR/start.sh afstart
|
ExecStopPost=/etc/ShellCrash/start.sh stop_firewall ; /etc/ShellCrash/start.sh unset_proxy
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5s
|
RestartSec=5s
|
||||||
LimitNOFILE=infinity
|
LimitNOFILE=infinity
|
||||||
|
|
1239
scripts/start.sh
1239
scripts/start.sh
File diff suppressed because it is too large
Load Diff
229
scripts/task.sh
229
scripts/task.sh
|
@ -2,14 +2,12 @@
|
||||||
# Copyright (C) Juewuy
|
# Copyright (C) Juewuy
|
||||||
|
|
||||||
#加载全局变量
|
#加载全局变量
|
||||||
[ -d "/etc/storage/clash" ] && CRASHDIR=/etc/storage/clash
|
CRASHDIR=$(cd $(dirname $0);pwd)
|
||||||
[ -d "/jffs/clash" ] && CRASHDIR=/jffs/clash
|
[ -z "$BINDIR" ] && BINDIR=${CRASHDIR}
|
||||||
[ -z "$CRASHDIR" ] && CRASHDIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}')
|
CFG_PATH=${CRASHDIR}/configs/ShellCrash.cfg
|
||||||
[ -z "$CRASHDIR" ] && CRASHDIR=$(cat ~/.bashrc | grep CRASHDIR | awk -F "\"" '{print $2}')
|
TMPDIR=/tmp/ShellCrash && [ ! -f ${TMPDIR} ] && mkdir -p ${TMPDIR}
|
||||||
[ -z "$bindir" ] && bindir=$CRASHDIR
|
|
||||||
CFG_PATH=$CRASHDIR/configs/ShellCrash.cfg
|
|
||||||
TMPDIR=/tmp/ShellCrash && [ ! -f $TMPDIR ] && mkdir -p $TMPDIR
|
|
||||||
source $CFG_PATH &> /dev/null
|
source $CFG_PATH &> /dev/null
|
||||||
|
|
||||||
setconfig(){
|
setconfig(){
|
||||||
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
||||||
[ -z "$3" ] && configpath=$CFG_PATH || configpath=$3
|
[ -z "$3" ] && configpath=$CFG_PATH || configpath=$3
|
||||||
|
@ -18,9 +16,9 @@ setconfig(){
|
||||||
|
|
||||||
#任务命令
|
#任务命令
|
||||||
check_update(){ #检查更新工具
|
check_update(){ #检查更新工具
|
||||||
$CRASHDIR/start.sh webget $TMPDIR/crashversion "$update_url/bin/version" echooff
|
${CRASHDIR}/start.sh webget ${TMPDIR}/crashversion "$update_url/bin/version" echooff
|
||||||
[ "$?" = "0" ] && source $TMPDIR/crashversion 2>/dev/null
|
[ "$?" = "0" ] && source ${TMPDIR}/crashversion 2>/dev/null
|
||||||
rm -rf $TMPDIR/crashversion
|
rm -rf ${TMPDIR}/crashversion
|
||||||
}
|
}
|
||||||
update_core(){ #自动更新内核
|
update_core(){ #自动更新内核
|
||||||
#检查版本
|
#检查版本
|
||||||
|
@ -32,29 +30,29 @@ update_core(){ #自动更新内核
|
||||||
else
|
else
|
||||||
#更新内核
|
#更新内核
|
||||||
[ "$crashcore" = singbox ] && core_new=singbox || core_new=clash
|
[ "$crashcore" = singbox ] && core_new=singbox || core_new=clash
|
||||||
$CRASHDIR/start.sh webget $TMPDIR/core.new "${update_url}/bin/${crashcore}/${core_new}-linux-${cpucore}"
|
${CRASHDIR}/start.sh webget ${TMPDIR}/core.new "${update_url}/bin/${crashcore}/${core_new}-linux-${cpucore}"
|
||||||
if [ "$?" != "0" ];then
|
if [ "$?" != "0" ];then
|
||||||
logger "任务【自动更新内核】出错-下载失败!"
|
logger "任务【自动更新内核】出错-下载失败!"
|
||||||
rm -rf $TMPDIR/core.new
|
rm -rf ${TMPDIR}/core.new
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
chmod +x $TMPDIR/core.new
|
chmod +x ${TMPDIR}/core.new
|
||||||
$CRASHDIR/start.sh stop
|
${CRASHDIR}/start.sh stop
|
||||||
if [ "$crashcore" = singbox ];then
|
if [ "$crashcore" = singbox ];then
|
||||||
core_v=$($TMPDIR/core.new version 2>/dev/null | grep version | awk '{print $3}')
|
core_v=$(${TMPDIR}/core.new version 2>/dev/null | grep version | awk '{print $3}')
|
||||||
else
|
else
|
||||||
core_v=$($TMPDIR/core.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //')
|
core_v=$(${TMPDIR}/core.new -v 2>/dev/null | sed 's/ linux.*//;s/.* //')
|
||||||
fi
|
fi
|
||||||
if [ -z "$core_v" ];then
|
if [ -z "$core_v" ];then
|
||||||
logger "任务【自动更新内核】出错-内核校验失败!"
|
logger "任务【自动更新内核】出错-内核校验失败!"
|
||||||
rm -rf $TMPDIR/core.new
|
rm -rf ${TMPDIR}/core.new
|
||||||
$CRASHDIR/start.sh start
|
${CRASHDIR}/start.sh start
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
mv -f $TMPDIR/core.new $bindir/CrashCore
|
mv -f ${TMPDIR}/core.new ${BINDIR}/CrashCore
|
||||||
logger "任务【自动更新内核】下载完成,正在重启服务!"
|
logger "任务【自动更新内核】下载完成,正在重启服务!"
|
||||||
setconfig core_v $core_v
|
setconfig core_v $core_v
|
||||||
$CRASHDIR/start.sh start
|
${CRASHDIR}/start.sh start
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -67,20 +65,20 @@ update_shellcrash(){ #自动更新脚本
|
||||||
logger "任务【自动更新脚本】中止-未检测到版本更新"
|
logger "任务【自动更新脚本】中止-未检测到版本更新"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
$CRASHDIR/start.sh webget $TMPDIR/clashfm.tar.gz "$update_url/bin/clashfm.tar.gz"
|
${CRASHDIR}/start.sh webget ${TMPDIR}/update.tar.gz "$update_url/bin/update.tar.gz"
|
||||||
if [ "$?" != "0" ];then
|
if [ "$?" != "0" ];then
|
||||||
rm -rf $TMPDIR/clashfm.tar.gz
|
rm -rf ${TMPDIR}/update.tar.gz
|
||||||
logger "任务【自动更新内核】出错-下载失败!"
|
logger "任务【自动更新内核】出错-下载失败!"
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
#解压
|
#解压
|
||||||
tar -zxvf "$TMPDIR/clashfm.tar.gz" -C $CRASHDIR/ || tar -zxvf "$TMPDIR/clashfm.tar.gz" --no-same-owner -C $CRASHDIR/
|
tar -zxvf "${TMPDIR}/update.tar.gz" -C ${CRASHDIR}/ || tar -zxvf "${TMPDIR}/update.tar.gz" --no-same-owner -C ${CRASHDIR}/
|
||||||
if [ $? -ne 0 ];then
|
if [ $? -ne 0 ];then
|
||||||
rm -rf $TMPDIR/clashfm.tar.gz
|
rm -rf ${TMPDIR}/update.tar.gz
|
||||||
logger "任务【自动更新内核】出错-解压失败!"
|
logger "任务【自动更新内核】出错-解压失败!"
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
source $CRASHDIR/init.sh >/dev/null
|
source ${CRASHDIR}/init.sh >/dev/null
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -97,13 +95,13 @@ update_mmdb(){ #自动更新数据库
|
||||||
logger "任务【自动更新数据库文件】跳过-未检测到$2版本更新"
|
logger "任务【自动更新数据库文件】跳过-未检测到$2版本更新"
|
||||||
else
|
else
|
||||||
#更新文件
|
#更新文件
|
||||||
$CRASHDIR/start.sh webget $TMPDIR/$1 "$update_url/bin/geodata/$2"
|
${CRASHDIR}/start.sh webget ${TMPDIR}/$1 "$update_url/bin/geodata/$2"
|
||||||
if [ "$?" != "0" ];then
|
if [ "$?" != "0" ];then
|
||||||
logger "任务【自动更新数据库文件】更新【$2】下载失败!"
|
logger "任务【自动更新数据库文件】更新【$2】下载失败!"
|
||||||
rm -rf $TMPDIR/$1
|
rm -rf ${TMPDIR}/$1
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
mv -f $TMPDIR/$1 $bindir/$1
|
mv -f ${TMPDIR}/$1 ${BINDIR}/$1
|
||||||
setconfig $geo_v $GeoIP_v
|
setconfig $geo_v $GeoIP_v
|
||||||
logger "任务【自动更新数据库文件】更新【$2】成功!"
|
logger "任务【自动更新数据库文件】更新【$2】成功!"
|
||||||
return 0
|
return 0
|
||||||
|
@ -119,8 +117,11 @@ update_mmdb(){ #自动更新数据库
|
||||||
[ -n "${geosite_cn_v}" ] && getgeo geosite.db geosite_cn.db
|
[ -n "${geosite_cn_v}" ] && getgeo geosite.db geosite_cn.db
|
||||||
}
|
}
|
||||||
reset_firewall(){ #重设透明路由防火墙
|
reset_firewall(){ #重设透明路由防火墙
|
||||||
$CRASHDIR/start.sh stop_firewall
|
${CRASHDIR}/start.sh stop_firewall
|
||||||
$CRASHDIR/start.sh afstart
|
${CRASHDIR}/start.sh afstart
|
||||||
|
}
|
||||||
|
ntp(){
|
||||||
|
ckcmd ntpd && ntpd -n -q -p 203.107.6.88 &>/dev/null || exit 0 &
|
||||||
}
|
}
|
||||||
#任务工具
|
#任务工具
|
||||||
|
|
||||||
|
@ -128,7 +129,7 @@ logger(){
|
||||||
[ "$task_push" = 1 ] && push= || push=off
|
[ "$task_push" = 1 ] && push= || push=off
|
||||||
[ -n "$2" -a "$2" != 0 ] && echo -e "\033[$2m$1\033[0m"
|
[ -n "$2" -a "$2" != 0 ] && echo -e "\033[$2m$1\033[0m"
|
||||||
[ "$3" = 'off' ] && push=off
|
[ "$3" = 'off' ] && push=off
|
||||||
$CRASHDIR/start.sh logger $1 0 $push
|
${CRASHDIR}/start.sh logger $1 0 $push
|
||||||
}
|
}
|
||||||
croncmd(){
|
croncmd(){
|
||||||
if [ -n "$(crontab -h 2>&1 | grep '\-l')" ];then
|
if [ -n "$(crontab -h 2>&1 | grep '\-l')" ];then
|
||||||
|
@ -145,14 +146,14 @@ croncmd(){
|
||||||
}
|
}
|
||||||
cronset(){
|
cronset(){
|
||||||
# 参数1代表要移除的关键字,参数2代表要添加的任务语句
|
# 参数1代表要移除的关键字,参数2代表要添加的任务语句
|
||||||
tmpcron=$TMPDIR/cron_$USER
|
tmpcron=${TMPDIR}/cron_$USER
|
||||||
croncmd -l > $tmpcron
|
croncmd -l > $tmpcron
|
||||||
sed -i "/$1/d" $tmpcron
|
sed -i "/$1/d" $tmpcron
|
||||||
sed -i '/^$/d' $tmpcron
|
sed -i '/^$/d' $tmpcron
|
||||||
echo "$2" >> $tmpcron
|
echo "$2" >> $tmpcron
|
||||||
croncmd $tmpcron
|
croncmd $tmpcron
|
||||||
#华硕/Padavan固件存档在本地,其他则删除
|
#华硕/Padavan固件存档在本地,其他则删除
|
||||||
[ "$CRASHDIR" = "/jffs/clash" -o "$CRASHDIR" = "/etc/storage/clash" ] && mv -f $tmpcron $CRASHDIR/task/cron || rm -f $tmpcron
|
[ -d /jffs -o -d /etc/storage/clash -o -d /etc/storage/ShellCrash ] && mv -f $tmpcron ${CRASHDIR}/task/cron || rm -f $tmpcron
|
||||||
}
|
}
|
||||||
set_cron(){
|
set_cron(){
|
||||||
[ -z $week ] && week=*
|
[ -z $week ] && week=*
|
||||||
|
@ -164,14 +165,14 @@ set_cron(){
|
||||||
if [ "$res" = '1' ]; then
|
if [ "$res" = '1' ]; then
|
||||||
task_txt="$min $hour * * $week $CRASHDIR/task/task.sh $task_id $cron_time$task_name"
|
task_txt="$min $hour * * $week $CRASHDIR/task/task.sh $task_id $cron_time$task_name"
|
||||||
cronset "$cron_time$task_name" "$task_txt"
|
cronset "$cron_time$task_name" "$task_txt"
|
||||||
|
echo -e "任务【$cron_time$task_name】\033[32m已添加!\033[0m"
|
||||||
fi
|
fi
|
||||||
unset week hour min
|
unset week hour min
|
||||||
echo -e "任务【$cron_time$task_name】\033[32m添加成功!\033[0m"
|
|
||||||
sleep 1
|
sleep 1
|
||||||
}
|
}
|
||||||
set_service(){
|
set_service(){
|
||||||
# 参数1代表要任务类型,参数2代表任务ID,参数3代表任务描述,参数4代表running任务cron时间
|
# 参数1代表要任务类型,参数2代表任务ID,参数3代表任务描述,参数4代表running任务cron时间
|
||||||
task_file=$CRASHDIR/task/$1
|
task_file=${CRASHDIR}/task/$1
|
||||||
[ -s $task_file ] && sed -i "/$3/d" $task_file
|
[ -s $task_file ] && sed -i "/$3/d" $task_file
|
||||||
#运行时每分钟执行的任务特殊处理
|
#运行时每分钟执行的任务特殊处理
|
||||||
if [ "$1" = "running" ];then
|
if [ "$1" = "running" ];then
|
||||||
|
@ -188,18 +189,18 @@ set_service(){
|
||||||
task_user_add(){ #自定义命令添加
|
task_user_add(){ #自定义命令添加
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
echo -e "\033[33m命令可包含空格,请确保命令可执行!\033[0m"
|
echo -e "\033[33m命令可包含空格,请确保命令可执行!\033[0m"
|
||||||
echo -e "也可以手动编辑\033[32m$CRASHDIR/task/task.user\033[0m添加"
|
echo -e "也可以手动编辑\033[32m${CRASHDIR}/task/task.user\033[0m添加"
|
||||||
read -p "请输入命令语句 > " script
|
read -p "请输入命令语句 > " script
|
||||||
if [ -n "$script" ];then
|
if [ -n "$script" ];then
|
||||||
task_command=$script
|
task_command=$script
|
||||||
echo -e "请检查输入:\033[32m$task_command\033[0m"
|
echo -e "请检查输入:\033[32m$task_command\033[0m"
|
||||||
#获取本任务ID
|
#获取本任务ID
|
||||||
task_max_id=$(awk -F'#' '{print $1}' $CRASHDIR/task/task.user | sort -n | tail -n 1)
|
task_max_id=$(awk -F'#' '{print $1}' ${CRASHDIR}/task/task.user | sort -n | tail -n 1)
|
||||||
[ -z "$task_max_id" ] && task_max_id=200
|
[ -z "$task_max_id" ] && task_max_id=200
|
||||||
task_id=$((task_max_id + 1))
|
task_id=$((task_max_id + 1))
|
||||||
read -p "请输入任务备注 > " txt
|
read -p "请输入任务备注 > " txt
|
||||||
[ -n "$txt" ] && task_name=$txt || task_name=自定义任务$task_id
|
[ -n "$txt" ] && task_name=$txt || task_name=自定义任务$task_id
|
||||||
echo "$task_id#$task_command#$task_name" >> $CRASHDIR/task/task.user
|
echo "$task_id#$task_command#$task_name" >> ${CRASHDIR}/task/task.user
|
||||||
echo -e "\033[32m自定义任务已添加!\033[0m"
|
echo -e "\033[32m自定义任务已添加!\033[0m"
|
||||||
sleep 1
|
sleep 1
|
||||||
else
|
else
|
||||||
|
@ -210,15 +211,15 @@ task_user_add(){ #自定义命令添加
|
||||||
task_user_del(){ #自定义命令删除
|
task_user_del(){ #自定义命令删除
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
echo -e "请输入对应ID移除对应自定义任务(不会影响内置任务)"
|
echo -e "请输入对应ID移除对应自定义任务(不会影响内置任务)"
|
||||||
echo -e "也可以手动编辑\033[32m$CRASHDIR/task/task.user\033[0m"
|
echo -e "也可以手动编辑\033[32m${CRASHDIR}/task/task.user\033[0m"
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
cat $CRASHDIR/task/task.user 2>/dev/null | grep -Ev '^#' | awk -F '#' '{print $1" "$3}'
|
cat ${CRASHDIR}/task/task.user 2>/dev/null | grep -Ev '^#' | awk -F '#' '{print $1" "$3}'
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
echo 0 返回上级菜单
|
echo 0 返回上级菜单
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
read -p "请输入对应数字 > " num
|
read -p "请输入对应数字 > " num
|
||||||
if [ -n "$num" ];then
|
if [ -n "$num" ];then
|
||||||
sed -i "/^$num#/d" $CRASHDIR/task/task.user 2>/dev/null
|
sed -i "/^$num#/d" ${CRASHDIR}/task/task.user 2>/dev/null
|
||||||
[ "$num" != 0 ] && task_user_del
|
[ "$num" != 0 ] && task_user_del
|
||||||
else
|
else
|
||||||
echo -e "\033[31m输入错误,请重新输入!\033[0m"
|
echo -e "\033[31m输入错误,请重新输入!\033[0m"
|
||||||
|
@ -230,9 +231,9 @@ task_add(){ #任务添加
|
||||||
echo -e "\033[36m请选择需要添加的任务\033[0m"
|
echo -e "\033[36m请选择需要添加的任务\033[0m"
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
#检测并创建自定义任务文件
|
#检测并创建自定义任务文件
|
||||||
[ -f $CRASHDIR/task/task.user ] || echo '#任务ID(必须>200并顺序排列)#任务命令#任务说明(#号隔开,任务命令和说明中都不允许包含#号)' > $CRASHDIR/task/task.user
|
[ -f ${CRASHDIR}/task/task.user ] || echo '#任务ID(必须>200并顺序排列)#任务命令#任务说明(#号隔开,任务命令和说明中都不允许包含#号)' > ${CRASHDIR}/task/task.user
|
||||||
#输出任务列表
|
#输出任务列表
|
||||||
cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | awk -F '#' '{print " "NR" "$3}'
|
cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | awk -F '#' '{print " "NR" "$3}'
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
echo -e " 0 返回上级菜单"
|
echo -e " 0 返回上级菜单"
|
||||||
read -p "请输入对应数字 > " num
|
read -p "请输入对应数字 > " num
|
||||||
|
@ -240,9 +241,9 @@ task_add(){ #任务添加
|
||||||
0)
|
0)
|
||||||
;;
|
;;
|
||||||
[1-9]|[1-9][0-9])
|
[1-9]|[1-9][0-9])
|
||||||
if [ "$num" -le "$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | wc -l)" ];then
|
if [ "$num" -le "$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | wc -l)" ];then
|
||||||
task_id=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | sed -n "$num p" | awk -F '#' '{print $1}')
|
task_id=$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | sed -n "$num p" | awk -F '#' '{print $1}')
|
||||||
task_name=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | sed -n "$num p" | awk -F '#' '{print $3}')
|
task_name=$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep -Ev '^(#|$)' | sed -n "$num p" | awk -F '#' '{print $3}')
|
||||||
task_type
|
task_type
|
||||||
else
|
else
|
||||||
errornum
|
errornum
|
||||||
|
@ -255,14 +256,14 @@ task_add(){ #任务添加
|
||||||
}
|
}
|
||||||
task_del(){ #任务删除
|
task_del(){ #任务删除
|
||||||
#删除定时任务
|
#删除定时任务
|
||||||
croncmd -l > $TMPDIR/cron && sed -i "/$1/d" $TMPDIR/cron && croncmd $TMPDIR/cron
|
croncmd -l > ${TMPDIR}/cron && sed -i "/$1/d" ${TMPDIR}/cron && croncmd ${TMPDIR}/cron
|
||||||
rm -f $TMPDIR/cron
|
rm -f ${TMPDIR}/cron
|
||||||
#删除条件任务
|
#删除条件任务
|
||||||
sed -i "/$1/d" $CRASHDIR/task/cron 2>/dev/null
|
sed -i "/$1/d" ${CRASHDIR}/task/cron 2>/dev/null
|
||||||
sed -i "/$1/d" $CRASHDIR/task/bfstart 2>/dev/null
|
sed -i "/$1/d" ${CRASHDIR}/task/bfstart 2>/dev/null
|
||||||
sed -i "/$1/d" $CRASHDIR/task/afstart 2>/dev/null
|
sed -i "/$1/d" ${CRASHDIR}/task/afstart 2>/dev/null
|
||||||
sed -i "/$1/d" $CRASHDIR/task/running 2>/dev/null
|
sed -i "/$1/d" ${CRASHDIR}/task/running 2>/dev/null
|
||||||
sed -i "/$1/d" $CRASHDIR/task/affirewall 2>/dev/null
|
sed -i "/$1/d" ${CRASHDIR}/task/affirewall 2>/dev/null
|
||||||
}
|
}
|
||||||
task_type(){ #任务条件选择菜单
|
task_type(){ #任务条件选择菜单
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
|
@ -355,25 +356,32 @@ task_type(){ #任务条件选择菜单
|
||||||
task_manager(){ #任务管理列表
|
task_manager(){ #任务管理列表
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
#抽取并生成临时列表
|
#抽取并生成临时列表
|
||||||
croncmd -l > $TMPDIR/task_cronlist
|
croncmd -l > ${TMPDIR}/task_cronlist
|
||||||
cat $TMPDIR/task_cronlist $CRASHDIR/task/running 2>/dev/null | sort -u | grep -oE "task/task.sh .*" | awk -F ' ' '{print $2" "$3}' > $TMPDIR/task_list
|
cat ${TMPDIR}/task_cronlist ${CRASHDIR}/task/running 2>/dev/null | sort -u | grep -oE "task/task.sh .*" | awk -F ' ' '{print $2" "$3}' > ${TMPDIR}/task_list
|
||||||
cat $CRASHDIR/task/bfstart $CRASHDIR/task/afstart $CRASHDIR/task/affirewall 2>/dev/null | awk -F ' ' '{print $2" "$3}' >> $TMPDIR/task_list
|
cat ${CRASHDIR}/task/bfstart ${CRASHDIR}/task/afstart ${CRASHDIR}/task/affirewall 2>/dev/null | awk -F ' ' '{print $2" "$3}' >> ${TMPDIR}/task_list
|
||||||
rm -rf $TMPDIR/task_cronlist
|
cat ${TMPDIR}/task_cronlist 2>/dev/null | sort -u | grep -oE " #.*" | grep -v "守护" | awk -F '#' '{print "0 旧版任务-"$2}' >> ${TMPDIR}/task_list
|
||||||
|
rm -rf ${TMPDIR}/task_cronlist
|
||||||
#判断为空则返回
|
#判断为空则返回
|
||||||
if [ ! -s $TMPDIR/task_list ];then
|
if [ ! -s ${TMPDIR}/task_list ];then
|
||||||
echo -e "\033[31m当前没有可供管理的任务!\033[36m"
|
echo -e "\033[31m当前没有可供管理的任务!\033[36m"
|
||||||
sleep 1
|
sleep 1
|
||||||
else
|
else
|
||||||
echo -e "\033[33m已添加的任务:\033[0m"
|
echo -e "\033[33m已添加的任务:\033[0m"
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
cat $TMPDIR/task_list | awk '{print " " NR " " $2}'
|
cat ${TMPDIR}/task_list | awk '{print " " NR " " $2}'
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
echo -e " d 清空任务列表"
|
echo -e " a 清空旧版任务"
|
||||||
|
echo -e " d 清空任务列表"
|
||||||
echo -e " 0 返回上级菜单"
|
echo -e " 0 返回上级菜单"
|
||||||
read -p "请输入对应数字 > " num
|
read -p "请输入对应数字 > " num
|
||||||
case "$num" in
|
case "$num" in
|
||||||
0)
|
0)
|
||||||
;;
|
;;
|
||||||
|
a)
|
||||||
|
task_del "#"
|
||||||
|
echo -e "\033[31m旧版任务已清空!\033[36m"
|
||||||
|
sleep 1
|
||||||
|
;;
|
||||||
d)
|
d)
|
||||||
task_del "task.sh"
|
task_del "task.sh"
|
||||||
echo -e "\033[31m全部任务已清空!\033[36m"
|
echo -e "\033[31m全部任务已清空!\033[36m"
|
||||||
|
@ -381,48 +389,57 @@ task_manager(){ #任务管理列表
|
||||||
;;
|
;;
|
||||||
[1-9]|[1-9][0-9])
|
[1-9]|[1-9][0-9])
|
||||||
|
|
||||||
task_txt=$(sed -n "$num p" $TMPDIR/task_list)
|
task_txt=$(sed -n "$num p" ${TMPDIR}/task_list)
|
||||||
task_id=$(echo $task_txt | awk '{print $1}')
|
task_id=$(echo $task_txt | awk '{print $1}')
|
||||||
task_des=$(echo $task_txt | awk '{print $2}')
|
if [ "$task_id" = 0 ];then
|
||||||
task_name=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep "$task_id" | awk -F '#' '{print $3}')
|
read -p "旧版任务不支持管理,是否移除?(1/0) > " res
|
||||||
echo -----------------------------------------------
|
[ "$res" = 1 ] && {
|
||||||
echo -e "当前任务为:\033[36m $task_des\033[0m"
|
cronname=$(echo $task_txt | awk -F '-' '{print $2}')
|
||||||
echo -e " 1 \033[33m修改\033[0m当前任务"
|
croncmd -l > $TMPDIR/conf && sed -i "/$cronname/d" $TMPDIR/conf && croncmd $TMPDIR/conf
|
||||||
echo -e " 2 \033[31m删除\033[0m当前任务"
|
sed -i "/$cronname/d" $clashdir/tools/cron 2>/dev/null
|
||||||
echo -e " 3 \033[32m立即执行\033[0m一次"
|
rm -f $TMPDIR/conf
|
||||||
echo -e " 4 查看\033[33m执行记录\033[0m"
|
}
|
||||||
echo -----------------------------------------------
|
else
|
||||||
echo -e " 0 返回上级菜单"
|
task_des=$(echo $task_txt | awk '{print $2}')
|
||||||
read -p "请选择需要执行的操作 > " num
|
task_name=$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep "$task_id" | awk -F '#' '{print $3}')
|
||||||
case "$num" in
|
|
||||||
0)
|
|
||||||
;;
|
|
||||||
1)
|
|
||||||
task_type && task_del $task_des
|
|
||||||
;;
|
|
||||||
2)
|
|
||||||
task_del $task_des
|
|
||||||
;;
|
|
||||||
3)
|
|
||||||
task_command=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep "$task_id" | awk -F '#' '{print $2}')
|
|
||||||
eval $task_command && task_res='执行成功!' || task_res='执行失败!'
|
|
||||||
logger "任务【$task_des】$task_res" 33 off
|
|
||||||
sleep 1
|
|
||||||
;;
|
|
||||||
4)
|
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
if [ -n "$(cat $TMPDIR/ShellCrash.log | grep "$task_name")" ];then
|
echo -e "当前任务为:\033[36m $task_des\033[0m"
|
||||||
cat $TMPDIR/ShellCrash.log | grep "$task_name"
|
echo -e " 1 \033[33m修改\033[0m当前任务"
|
||||||
else
|
echo -e " 2 \033[31m删除\033[0m当前任务"
|
||||||
echo -e "\033[31m未找到相关执行记录!\033[0m"
|
echo -e " 3 \033[32m立即执行\033[0m一次"
|
||||||
fi
|
echo -e " 4 查看\033[33m执行记录\033[0m"
|
||||||
sleep 1
|
echo -----------------------------------------------
|
||||||
;;
|
echo -e " 0 返回上级菜单"
|
||||||
*)
|
read -p "请选择需要执行的操作 > " num
|
||||||
errornum
|
case "$num" in
|
||||||
;;
|
0)
|
||||||
esac
|
;;
|
||||||
|
1)
|
||||||
|
task_type && task_del $task_des
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
task_del $task_des
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
task_command=$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep "$task_id" | awk -F '#' '{print $2}')
|
||||||
|
eval $task_command && task_res='执行成功!' || task_res='执行失败!'
|
||||||
|
logger "任务【$task_des】$task_res" 33 off
|
||||||
|
sleep 1
|
||||||
|
;;
|
||||||
|
4)
|
||||||
|
echo -----------------------------------------------
|
||||||
|
if [ -n "$(cat ${TMPDIR}/ShellCrash.log | grep "$task_name")" ];then
|
||||||
|
cat ${TMPDIR}/ShellCrash.log | grep "$task_name"
|
||||||
|
else
|
||||||
|
echo -e "\033[31m未找到相关执行记录!\033[0m"
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
errornum
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
task_manager
|
task_manager
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -443,7 +460,7 @@ task_recom(){ #任务推荐
|
||||||
[ "$res" = 1 ] && {
|
[ "$res" = 1 ] && {
|
||||||
set_service running "106" "运行时每10分钟自动保存面板配置" "*/10 * * * *"
|
set_service running "106" "运行时每10分钟自动保存面板配置" "*/10 * * * *"
|
||||||
set_service afstart "107" "服务启动后自动同步ntp时间"
|
set_service afstart "107" "服务启动后自动同步ntp时间"
|
||||||
cronset "在每周3的3点整更新订阅并重启服务" "0 3 * * 3 $CRASHDIR/task/task.sh 104 在每周3的3点整更新订阅并重启服务" && \
|
cronset "在每周3的3点整更新订阅并重启服务" "0 3 * * 3 ${CRASHDIR}/task/task.sh 104 在每周3的3点整更新订阅并重启服务" && \
|
||||||
echo -e "任务【在每周3的3点整更新订阅并重启服务】\033[32m添加成功!\033[0m"
|
echo -e "任务【在每周3的3点整更新订阅并重启服务】\033[32m添加成功!\033[0m"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -470,13 +487,13 @@ task_menu(){ #任务菜单
|
||||||
;;
|
;;
|
||||||
2)
|
2)
|
||||||
task_manager
|
task_manager
|
||||||
rm -rf $TMPDIR/task_list
|
rm -rf ${TMPDIR}/task_list
|
||||||
task_menu
|
task_menu
|
||||||
;;
|
;;
|
||||||
3)
|
3)
|
||||||
if [ -n "$(cat $TMPDIR/ShellCrash.log | grep '任务【')" ];then
|
if [ -n "$(cat ${TMPDIR}/ShellCrash.log | grep '任务【')" ];then
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
cat $TMPDIR/ShellCrash.log | grep '任务【'
|
cat ${TMPDIR}/ShellCrash.log | grep '任务【'
|
||||||
else
|
else
|
||||||
echo -e "\033[31m未找到任务相关执行日志!\033[0m"
|
echo -e "\033[31m未找到任务相关执行日志!\033[0m"
|
||||||
fi
|
fi
|
||||||
|
@ -514,8 +531,8 @@ case "$1" in
|
||||||
task_menu
|
task_menu
|
||||||
;;
|
;;
|
||||||
[1-9][0-9][0-9])
|
[1-9][0-9][0-9])
|
||||||
task_command=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $2}')
|
task_command=$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $2}')
|
||||||
task_name=$(cat $CRASHDIR/task/task.list $CRASHDIR/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $3}')
|
task_name=$(cat ${CRASHDIR}/task/task.list ${CRASHDIR}/task/task.user 2>/dev/null | grep "$1" | awk -F '#' '{print $3}')
|
||||||
#logger "任务$task_name 开始执行"
|
#logger "任务$task_name 开始执行"
|
||||||
eval $task_command && task_res=成功 || task_res=失败
|
eval $task_command && task_res=成功 || task_res=失败
|
||||||
logger "任务【$2】执行$task_res"
|
logger "任务【$2】执行$task_res"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user