2022-03-16 15:00:11 +08:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright (C) Juewuy
|
|
|
|
|
2023-04-04 10:23:19 +08:00
|
|
|
clashdir="$(uci get firewall.ShellClash.path | sed 's/\/misnap_init.sh//')"
|
2022-03-16 15:00:11 +08:00
|
|
|
profile=/etc/profile
|
|
|
|
|
2023-04-04 10:23:19 +08:00
|
|
|
autoSSH(){
|
|
|
|
#自动开启SSH
|
|
|
|
[ "$(nvram get ssh_en)" = 0 ] && nvram set ssh_en=1 && nvram commit
|
|
|
|
[ "`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=' $clashdir/mark | awk -F "=" '{print $2}')
|
|
|
|
[ -n "$mi_autoSSH_pwd" ] && echo -e "$mi_autoSSH_pwd\n$mi_autoSSH_pwd" | passwd root
|
|
|
|
}
|
|
|
|
#备份还原SSH秘钥
|
|
|
|
[ -f $clashdir/dropbear_rsa_host_key ] && ln -sf $clashdir/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key
|
|
|
|
[ -f $clashdir/authorized_keys ] && ln -sf $clashdir/authorized_keys /etc/dropbear/authorized_keys
|
|
|
|
}
|
2023-03-01 14:06:53 +08:00
|
|
|
tunfix(){
|
|
|
|
#在/tmp创建并挂载overlay
|
2023-03-17 23:32:30 +08:00
|
|
|
mkdir -p /tmp/overlay
|
|
|
|
mkdir -p /tmp/overlay/upper
|
|
|
|
mkdir -p /tmp/overlay/work
|
|
|
|
mount -o noatime,lowerdir=/lib/modules/4.4.198,upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work -t overlay "overlay_mods_only" /lib/modules/4.4.198
|
2023-03-01 14:06:53 +08:00
|
|
|
#将tun.ko链接到lib
|
2023-03-17 23:32:30 +08:00
|
|
|
ln -s $clashdir/tun.ko /lib/modules/4.4.198/tun.ko
|
2023-03-01 14:06:53 +08:00
|
|
|
}
|
|
|
|
init(){
|
2023-01-16 17:35:06 +08:00
|
|
|
#初始化环境变量
|
|
|
|
sed -i "/alias clash/d" $profile
|
|
|
|
sed -i "/export clashdir/d" $profile
|
|
|
|
echo "alias clash=\"$clashdir/clash.sh\"" >>$profile
|
|
|
|
echo "export clashdir=\"$clashdir\"" >>$profile
|
2023-04-04 10:23:19 +08:00
|
|
|
#软固化功能
|
|
|
|
[ "$(grep 'mi_autoSSH=' $clashdir/mark | awk -F "=" '{print $2}')" = "已启用" ] && autoSSH
|
2023-03-01 14:06:53 +08:00
|
|
|
#设置init.d服务
|
2023-01-25 16:27:11 +08:00
|
|
|
cp -f $clashdir/clashservice /etc/init.d/clash
|
2023-01-16 17:35:06 +08:00
|
|
|
chmod 755 /etc/init.d/clash
|
2023-03-01 14:06:53 +08:00
|
|
|
#启动服务
|
2023-01-16 17:35:06 +08:00
|
|
|
if [ ! -f $clashdir/.dis_startup ]; then
|
|
|
|
log_file=$(uci get system.@system[0].log_file)
|
|
|
|
while [ "$i" -lt 10 ]; do
|
|
|
|
sleep 5
|
|
|
|
[ -n "$(grep 'init complete' $log_file)" ] && i=10 || i=$((i + 1))
|
|
|
|
done
|
2023-03-01 14:06:53 +08:00
|
|
|
#AX6S/AX6000修复tun功能
|
2023-03-17 23:32:30 +08:00
|
|
|
[ -f $clashdir/tun.ko -a ! -f /lib/modules/4.4.198/tun.ko ] && tunfix && sleep 10
|
2023-03-01 14:06:53 +08:00
|
|
|
#
|
2023-01-16 17:35:06 +08:00
|
|
|
/etc/init.d/clash start
|
|
|
|
/etc/init.d/clash enable
|
|
|
|
fi
|
2023-03-01 14:06:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
tunfix) tunfix ;;
|
|
|
|
init) init ;;
|
|
|
|
*)
|
|
|
|
if [ -z $(pidof clash) ];then
|
|
|
|
init
|
|
|
|
else
|
|
|
|
sleep 10
|
|
|
|
$clashdir/start.sh restart
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|