mirror of
https://github.com/juewuy/ShellCrash.git
synced 2024-11-16 03:32:34 +08:00
~优化了推送机制,现在统一使用POST接口进行推送
~新增加在支持的设备上创建/usr/bin/crash启动文件以修复部分设备的环境变量写入失败问题 ~将singbox的内置tun网卡网段改为172.19.0.1/30,以修复tun模式下会将域名重定向到127.0.0.1的bug ~优化了延迟启动,现在延迟会在内核启动前进行而不是设置防火墙之前 ~优化了小米设备的自启机制,现在仅当检测到wan口ip时才会进行启动,以解决部分设备无法自启的问题 ~修复初始化脚本的若干报错 ~脚本在支持ash的环境会强制调用ash解析而不是sh ~修复新装脚本时,无法调用iptables的bug ~
This commit is contained in:
parent
c20e8f3d15
commit
ef4d6f51eb
|
@ -160,10 +160,10 @@ else
|
|||
[ -w /etc/systemd/system ] && sysdir=/etc/systemd/system
|
||||
if [ -n "$sysdir" -a "$USER" = "root" -a "$(cat /proc/1/comm)" = "systemd" ];then
|
||||
#创建shellcrash用户
|
||||
type userdel && userdel shellcrash 2>/dev/null
|
||||
userdel shellcrash 2>/dev/null
|
||||
sed -i '/0:7890/d' /etc/passwd
|
||||
sed -i '/x:7890/d' /etc/group
|
||||
if type useradd >/dev/null 2>&1; then
|
||||
if useradd -h >/dev/null 2>&1; then
|
||||
useradd shellcrash -u 7890 2>/dev/null
|
||||
sed -Ei s/7890:7890/0:7890/g /etc/passwd
|
||||
else
|
||||
|
@ -181,8 +181,9 @@ else
|
|||
fi
|
||||
fi
|
||||
#修饰文件及版本号
|
||||
command -v bash >/dev/null 2>&1 && shtype=bash || shtype=sh
|
||||
for file in start.sh task.sh ;do
|
||||
command -v bash >/dev/null 2>&1 && shtype=bash
|
||||
[ -x /bin/ash ] && shtype=ash
|
||||
for file in start.sh task.sh menu.sh;do
|
||||
sed -i "s|/bin/sh|/bin/$shtype|" ${CRASHDIR}/${file}
|
||||
chmod 755 ${CRASHDIR}/${file}
|
||||
done
|
||||
|
@ -203,7 +204,7 @@ fi
|
|||
setconfig COMMAND "$COMMAND" ${CRASHDIR}/configs/command.env
|
||||
#设置防火墙执行模式
|
||||
[ -z "$(grep firewall_mod $CRASHDIR/configs/ShellClash.cfg 2>/dev/null)" ] && {
|
||||
ckcmd iptables && firewall_mod=iptables
|
||||
iptables -j REDIRECT -h >/dev/null 2>&1 && firewall_mod=iptables
|
||||
nft add table inet shellcrash 2>/dev/null && firewall_mod=nftables
|
||||
setconfig firewall_mod $firewall_mod
|
||||
}
|
||||
|
@ -233,6 +234,14 @@ if [ -n "$profile" ];then
|
|||
echo "export CRASHDIR=\"$CRASHDIR\"" >> ~/.zshrc
|
||||
source ~/.zshrc >/dev/null 2>&1
|
||||
}
|
||||
#在允许的情况下创建/usr/bin/crash文件
|
||||
[ -w /usr/bin ] && {
|
||||
cat > /usr/bin/crash <<EOF
|
||||
#/bin/$shtype
|
||||
$CRASHDIR/menu.sh \$1 \$2 \$3 \$4 \$5
|
||||
EOF
|
||||
chmod +x /usr/bin/crash
|
||||
}
|
||||
else
|
||||
echo -e "\033[33m无法写入环境变量!请检查安装权限!\033[0m"
|
||||
exit 1
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) Juewuy
|
||||
|
||||
CRASHDIR=$(cd $(dirname $0);pwd)
|
||||
CFG_PATH=${CRASHDIR}/configs/ShellCrash.cfg
|
||||
YAMLSDIR=${CRASHDIR}/yamls
|
||||
JSONSDIR=${CRASHDIR}/jsons
|
||||
#加载执行目录,失败则初始化
|
||||
source ${CRASHDIR}/configs/command.env >/dev/null 2>&1
|
||||
source ${CRASHDIR}/configs/command.env 2>/dev/null
|
||||
[ -z "$BINDIR" -o -z "$TMPDIR" -o -z "$COMMAND" ] && source ${CRASHDIR}/init.sh >/dev/null 2>&1
|
||||
[ ! -f ${TMPDIR} ] && mkdir -p ${TMPDIR}
|
||||
[ -n "$(tar --help 2>&1|grep -o 'no-same-owner')" ] && tar_para='--no-same-owner' #tar命令兼容
|
||||
|
@ -25,7 +26,7 @@ ckstatus(){
|
|||
#检查/读取脚本配置文件
|
||||
if [ -f $CFG_PATH ];then
|
||||
[ -n "$(awk 'a[$0]++' $CFG_PATH)" ] && awk '!a[$0]++' $CFG_PATH > $CFG_PATH #检查重复行并去除
|
||||
source $CFG_PATH >/dev/null 2>&1
|
||||
source $CFG_PATH 2>/dev/null
|
||||
else
|
||||
source ${CRASHDIR}/init.sh >/dev/null 2>&1
|
||||
fi
|
||||
|
@ -270,7 +271,7 @@ log_pusher(){ #日志菜单
|
|||
echo -----------------------------------------------
|
||||
read -p "请输入你获取到的API TOKEN > " TOKEN
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[32m请通过Telegram的对话窗口,向该机器人发送任意消息!\033[0m"
|
||||
echo -e "请向\033[32m你申请的机器人\033[31m而不是BotFather\033[0m,发送任意几条消息!"
|
||||
echo -----------------------------------------------
|
||||
read -p "我已经发送完成(1/0) > " res
|
||||
if [ "$res" = 1 ];then
|
||||
|
@ -342,14 +343,6 @@ log_pusher(){ #日志菜单
|
|||
if [ -n "$url" ];then
|
||||
push_bark=$url
|
||||
setconfig push_bark $url
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[32m例: ?group=ShellCrash\033[0m"
|
||||
read -p "请输入你的Bark请求参数(默认回车为空) > " param
|
||||
param=$(echo $param | sed 's/\&/\\\&/g')
|
||||
if [ -n "$param" ];then
|
||||
bark_param=$param
|
||||
setconfig bark_param \'$param\'
|
||||
fi
|
||||
${CRASHDIR}/start.sh logger "已完成Bark日志推送设置!" 32
|
||||
else
|
||||
echo -e "\033[31m输入错误,请重新输入!\033[0m"
|
||||
|
@ -1651,6 +1644,7 @@ uninstall(){
|
|||
rm -rf /usr/lib/systemd/system/shellcrash.service
|
||||
rm -rf /www/clash
|
||||
rm -rf /tmp/ShellCrash
|
||||
rm -rf /usr/bin/crash
|
||||
sed -i '/0:7890/d' /etc/passwd
|
||||
userdel -r shellcrash 2>/dev/null
|
||||
nvram set script_usbmount="" 2>/dev/null
|
||||
|
|
|
@ -80,55 +80,46 @@ logger(){ #日志工具
|
|||
log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1"
|
||||
echo $log_text >> ${TMPDIR}/ShellCrash.log
|
||||
[ "$(wc -l ${TMPDIR}/ShellCrash.log | awk '{print $1}')" -gt 99 ] && sed -i '1,50d' ${TMPDIR}/ShellCrash.log
|
||||
[ -z "$3" ] && {
|
||||
[ -n "$device_name" ] && log_text="$log_text($device_name)"
|
||||
#推送工具
|
||||
webpush(){
|
||||
[ -n "$(pidof CrashCore)" ] && {
|
||||
[ -n "$authentication" ] && auth="$authentication@"
|
||||
export https_proxy="http://${auth}127.0.0.1:$mix_port"
|
||||
}
|
||||
if curl --version >/dev/null 2>&1;then
|
||||
curl -kfsSl -X POST --connect-timeout 3 -H "Content-Type: application/json; charset=utf-8" "$1" -d "$2" >/dev/null 2>&1
|
||||
elif wget --version >/dev/null 2>&1;then
|
||||
wget -Y on -q --timeout=3 -t 1 --method=POST --header="Content-Type: application/json; charset=utf-8" --body-data="$2" "$1"
|
||||
else
|
||||
echo "找不到有效的curl或wget应用,请先安装!"
|
||||
fi
|
||||
}
|
||||
[ -z "$3" ] && {
|
||||
[ -n "$device_name" ] && log_text="$log_text($device_name)"
|
||||
[ -n "$push_TG" ] && {
|
||||
url="https://api.telegram.org/bot${push_TG}/sendMessage"
|
||||
curl_data="-d chat_id=$chat_ID&text=$log_text"
|
||||
wget_data="--post-data=$chat_ID&text=$log_text"
|
||||
if curl --version >/dev/null 2>&1;then
|
||||
curl -kfsSl --connect-timeout 3 -d "chat_id=$chat_ID&text=$log_text" "$url" >/dev/null 2>&1
|
||||
else
|
||||
wget -Y on -q --timeout=3 -t 1 --post-data="chat_id=$chat_ID&text=$log_text" "$url"
|
||||
fi
|
||||
content="{\"chat_id\":\"${chat_ID}\",\"text\":\"$log_text\"}"
|
||||
webpush "$url" "$content" &
|
||||
}
|
||||
[ -n "$push_bark" ] && {
|
||||
url="${push_bark}/${log_text}${bark_param}"
|
||||
if curl --version >/dev/null 2>&1;then
|
||||
curl -kfsSl --connect-timeout 3 "$url" >/dev/null 2>&1
|
||||
else
|
||||
wget -Y on -q --timeout=3 -t 1 "$url"
|
||||
fi
|
||||
url="${push_bark}"
|
||||
content="{\"body\":\"${log_text}\",\"title\":\"ShellCrash日志推送\",\"level\":\"passive\",\"badge\":\"1\"}"
|
||||
webpush "$url" "$content" &
|
||||
}
|
||||
[ -n "$push_Deer" ] && {
|
||||
url="https://api2.pushdeer.com/message/push?pushkey=${push_Deer}"
|
||||
if curl --version >/dev/null 2>&1;then
|
||||
curl -kfsSl --connect-timeout 3 "$url"\&text="$log_text" >/dev/null 2>&1
|
||||
else
|
||||
wget -Y on -q --timeout=3 -t 1 "$url"\&text="$log_text"
|
||||
fi
|
||||
url="https://api2.pushdeer.com/message/push"
|
||||
content="{\"pushkey\":\"${push_Deer}\",\"text\":\"$log_text\"}"
|
||||
webpush "$url" "$content" &
|
||||
}
|
||||
[ -n "$push_Po" ] && {
|
||||
url="https://api.pushover.net/1/messages.json"
|
||||
content="{\"token\":\"${push_Po}\",\"user\":\"${push_Po_key}\",\"title\":\"ShellCrash日志推送\",\"message\":\"$log_text\"}"
|
||||
if curl --version >/dev/null 2>&1;then
|
||||
curl -kfsSl -X POST --connect-timeout 3 -H "Content-Type: application/json" "$url" -d "$content" >/dev/null 2>&1
|
||||
else
|
||||
wget -Y on -q --timeout=3 -t 1 --method=POST --header="Content-Type: application/json" --body-data="$content" "$url"
|
||||
fi
|
||||
webpush "$url" "$content" &
|
||||
}
|
||||
[ -n "$push_PP" ] && {
|
||||
url="http://www.pushplus.plus/send"
|
||||
content="{\"token\":\"${push_PP}\",\"title\":\"ShellCrash日志推送\",\"content\":\"$log_text\"}"
|
||||
if curl --version >/dev/null 2>&1;then
|
||||
curl -sS -X POST --connect-timeout 3 -H "Content-Type: application/json" "$url" -d "$content" >/dev/null 2>&1
|
||||
else
|
||||
wget -Y on -q --timeout=3 -t 1 --method=POST --header="Content-Type: application/json" --body-data="$content" "$url"
|
||||
fi
|
||||
webpush "$url" "$content" &
|
||||
}
|
||||
} &
|
||||
}
|
||||
|
@ -738,12 +729,12 @@ EOF
|
|||
"type": "tun",
|
||||
"tag": "tun-in",
|
||||
"interface_name": "utun",
|
||||
"inet4_address": "198.18.0.0/16",
|
||||
"inet4_address": "172.19.0.1/30",
|
||||
"auto_route": false,
|
||||
"stack": "system",
|
||||
$always_resolve_udp
|
||||
"sniff": true,
|
||||
"sniff_override_destination": true
|
||||
"sniff_override_destination": $sniffer
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -1584,8 +1575,11 @@ singbox_check(){ #singbox启动前检查
|
|||
}
|
||||
bfstart(){ #启动前
|
||||
routing_mark=$((fwmark + 2))
|
||||
#读取ShellCrash配置
|
||||
[ -z "$update_url" ] && update_url=https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master
|
||||
#延迟启动
|
||||
[ ! -f ${TMPDIR}/crash_start_time ] && [ -n "$start_delay" ] && [ "$start_delay" -gt 0 ] && {
|
||||
logger "ShellCrash将延迟$start_delay秒启动" 31 pushoff
|
||||
sleep $start_delay
|
||||
}
|
||||
[ ! -d ${BINDIR}/ui ] && mkdir -p ${BINDIR}/ui
|
||||
[ -z "$crashcore" ] && crashcore=clash
|
||||
#执行条件任务
|
||||
|
@ -1640,11 +1634,6 @@ bfstart(){ #启动前
|
|||
}
|
||||
afstart(){ #启动后
|
||||
[ -z "$firewall_area" ] && firewall_area=1
|
||||
#延迟启动
|
||||
[ ! -f ${TMPDIR}/crash_start_time ] && [ -n "$start_delay" ] && [ "$start_delay" -gt 0 ] && {
|
||||
logger "ShellCrash将延迟$start_delay秒启动" 31 pushoff
|
||||
sleep $start_delay
|
||||
}
|
||||
#设置循环检测面板端口以判定服务启动是否成功
|
||||
i=1
|
||||
while [ -z "$test" -a "$i" -lt 5 ];do
|
||||
|
|
Loading…
Reference in New Issue
Block a user