ShellCrash/scripts/misnap_init.sh
juewuy ce907f5a6d v1.8.5d
~全面适配singbox内核(自定义节点和规则相关功能除外)
  ·增加了singbox专属dns模式-mix模式
  ·增加了singbox数据库文件下载
  ·增加从/tmp导入singbox内核及singbox配置文件的功能
~正式改名为ShellCrash并调整脚本内相关说明
~重写systemd和procd启动脚本,优化启动流程和启动日志
~重写保守模式及本机代理相关功能,适配singbox内核
~增加第三方Geo数据库下载功能
~任务功能优化,增加旧版任务管理,增加可定时系统重启的任务
~保守模式启动优化
~修改部分在线生成服务器以适配singbox配置生成
~自定义clash节点功能提示优化,修复相关bug
~修复推荐任务每10分钟保存节点配置未生效的bug
2024-01-10 22:02:15 +08:00

85 lines
2.9 KiB
Bash

#!/bin/sh
# Copyright (C) Juewuy
CRASHDIR="$(uci get firewall.ShellCrash.path | sed 's/\/misnap_init.sh//')"
profile=/etc/profile
autoSSH(){
#自动开启SSH
[ "`uci -c /usr/share/xiaoqiang get xiaoqiang_version.version.CHANNEL`" != 'stable' ] && {
uci -c /usr/share/xiaoqiang set xiaoqiang_version.version.CHANNEL='stable'
uci -c /usr/share/xiaoqiang commit xiaoqiang_version.version
}
[ -z "$(pidof dropbear)" -o -z "$(netstat -ntul | grep :22)" ] && {
sed -i 's/channel=.*/channel="debug"/g' /etc/init.d/dropbear
/etc/init.d/dropbear restart
mi_autoSSH_pwd=$(grep 'mi_autoSSH_pwd=' $CRASHDIR/configs/ShellCrash.cfg | awk -F "=" '{print $2}')
[ -n "$mi_autoSSH_pwd" ] && echo -e "$mi_autoSSH_pwd\n$mi_autoSSH_pwd" | passwd root
}
#配置nvram
[ "$(nvram get ssh_en)" = 0 ] && nvram set ssh_en=1
[ "$(nvram get telnet_en)" = 0 ] && nvram set telnet_en=1
nvram commit &> /dev/null
#备份还原SSH秘钥
[ -f $CRASHDIR/configs/dropbear_rsa_host_key ] && ln -sf $CRASHDIR/configs/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key
[ -f $CRASHDIR/configs/authorized_keys ] && ln -sf $CRASHDIR/configs/authorized_keys /etc/dropbear/authorized_keys
#自动清理升级备份文件夹
rm -rf /data/etc_bak
}
tunfix(){
ko_dir=$(modinfo ip_tables | grep -Eo '/lib/modules.*/ip_tables.ko' | sed 's|/ip_tables.ko||' )
#在/tmp创建并挂载overlay
mkdir -p /tmp/overlay
mkdir -p /tmp/overlay/upper
mkdir -p /tmp/overlay/work
mount -o noatime,lowerdir=${ko_dir},upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work -t overlay "overlay_mods_only" ${ko_dir}
#将tun.ko链接到lib
ln -sf $CRASHDIR/tools/tun.ko ${ko_dir}/tun.ko
}
tproxyfix(){
sed -i 's/sysctl -w net.bridge.bridge-nf-call-ip/#sysctl -w net.bridge.bridge-nf-call-ip/g' /etc/init.d/qca-nss-ecm
sysctl -w net.bridge.bridge-nf-call-iptables=0
sysctl -w net.bridge.bridge-nf-call-ip6tables=0
}
init(){
#等待启动完成
log_file=$(uci get system.@system[0].log_file)
local i=0
while [ "$i" -lt 20 ]; do
sleep 3
[ -n "$(grep 'init complete' $log_file)" ] && i=20 || i=$((i + 1))
done
#初始化环境变量
sed -i "/alias crash/d" $profile
sed -i "/export CRASHDIR/d" $profile
echo "alias crash=\"sh $CRASHDIR/menu.sh\"" >>$profile
echo "export CRASHDIR=\"$CRASHDIR\"" >>$profile
#软固化功能
autoSSH
#设置init.d服务
cp -f $CRASHDIR/shellcrash.procd /etc/init.d/shellcrash
chmod 755 /etc/init.d/shellcrash
#启动服务
if [ ! -f $CRASHDIR/.dis_startup ]; then
#AX6S/AX6000修复tun功能
[ -f $CRASHDIR/configs/tun.ko ] && tunfix
#小米7000/小米万兆修复tproxy
[ -f /etc/init.d/qca-nss-ecm ] && [ -n "$(grep 'redir_mod=Tproxy' $CRASHDIR/configs/ShellCrash.cfg )" ] && tproxyfix
#启动服务
/etc/init.d/shellcrash start
/etc/init.d/shellcrash enable
fi
}
case "$1" in
tunfix) tunfix ;;
tproxyfix) tproxyfix ;;
init) init ;;
*)
if [ -z $(pidof CrashCore) ];then
init &
fi
;;
esac