~修复小米万兆无法正常开启启动的bug
~小米设备软固化功能不再依赖clash服务启动
~本地安装脚本适配小米万兆设备
~屏蔽ntp同步服务的报错提示
This commit is contained in:
juewuy
2023-04-04 10:23:19 +08:00
parent e4546476aa
commit cf560be341
4 changed files with 42 additions and 35 deletions

View File

@@ -1604,7 +1604,6 @@ tools(){
if [ "$systype" = "mi_snapshot" ];then
echo -----------------------------------------------
echo -e "\033[33m本功能使用软件命令进行固化不保证100%成功!\033[0m"
echo -e "本功能需依赖clash服务请确保clash为开机启动状态"
echo -e "\033[33m如有问题请加群反馈\033[36;4mhttps://t.me/ShellClash\033[0m"
read -p "请输入需要还原的SSH密码(不影响当前密码,回车可跳过) > " mi_autoSSH_pwd
mi_autoSSH=已启用

View File

@@ -17,15 +17,26 @@ setdir(){
set_usb_dir
fi
}
set_cust_dir(){
echo -----------------------------------------------
echo '可用路径 剩余空间:'
df -h | awk '{print $6,$4}'| sed 1d
echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!'
read -p "请输入自定义路径 > " dir
if [ "$(dir_avail $dir)" = 0 ];then
echo "\033[31m路径错误请重新设置\033[0m"
set_cust_dir
fi
}
echo -----------------------------------------------
if [ -n "$systype" ];then
[ "$systype" = "Padavan" ] && dir=/etc/storage
[ "$systype" = "mi_snapshot" ] && {
echo -e "\033[33m检测到当前设备为小米官方系统请选择安装位置\033[0m"
echo -e " 1 安装到/data目录(推荐,支持软固化功能)"
echo -e " 2 安装到USB设备(支持软固化功能)"
[ "$(dir_avail /etc)" != 0 ] && echo -e " 3 安装到/etc目录(不推荐)"
echo -e " 0 退出安装"
[ "$(dir_avail /data)" != 0 ] && echo " 1 安装到 /data 目录(推荐,支持软固化功能)"
[ "$(dir_avail /userdisk)" != 0 ] && echo " 2 安装到 /userdisk 目录(推荐,支持软固化功能)"
echo " 3 安装自定义目录(不推荐,不明勿用!)"
echo " 0 退出安装"
echo -----------------------------------------------
read -p "请输入相应数字 > " num
case "$num" in
@@ -33,15 +44,10 @@ if [ -n "$systype" ];then
dir=/data
;;
2)
set_usb_dir ;;
dir=/userdisk
;;
3)
if [ "$(dir_avail /etc)" != 0 ];then
dir=/etc
systype=""
else
echo -e "\033[31m你的设备不支持安装到/etc目录已改为安装到/data\033[0m"
dir=data
fi
set_cust_dir
;;
*)
exit 1 ;;
@@ -181,7 +187,7 @@ if [ -n "$profile" ];then
echo "alias clash=\"$shtype $clashdir/clash.sh\"" >> $profile #设置快捷命令环境变量
sed -i '/export clashdir=*/'d $profile
echo "export clashdir=\"$clashdir\"" >> $profile #设置clash路径环境变量
source $profile &>/dev/null
source $profile &>/dev/null || echo 运行错误请使用bash而不是dash运行安装命令
#适配zsh环境变量
[ -n "$(ls -l /bin/sh|grep -oE 'zsh')" ] && [ -z "$(cat ~/.zshrc 2>/dev/null|grep clashdir)" ] && {
echo "alias clash=\"$shtype $clashdir/clash.sh\"" >> ~/.zshrc
@@ -205,7 +211,7 @@ if [ "$systype" = "mi_snapshot" ];then
chmod 755 $clashdir/misnap_init.sh
uci set firewall.ShellClash=include
uci set firewall.ShellClash.type='script'
uci set firewall.ShellClash.path='/data/clash/misnap_init.sh'
uci set firewall.ShellClash.path="$clashdir/misnap_init.sh"
uci set firewall.ShellClash.enabled='1'
uci commit firewall
setconfig systype $systype

View File

@@ -1,9 +1,26 @@
#!/bin/sh
# Copyright (C) Juewuy
clashdir=/data/clash
clashdir="$(uci get firewall.ShellClash.path | sed 's/\/misnap_init.sh//')"
profile=/etc/profile
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
}
tunfix(){
#在/tmp创建并挂载overlay
mkdir -p /tmp/overlay
@@ -19,6 +36,8 @@ init(){
sed -i "/export clashdir/d" $profile
echo "alias clash=\"$clashdir/clash.sh\"" >>$profile
echo "export clashdir=\"$clashdir\"" >>$profile
#软固化功能
[ "$(grep 'mi_autoSSH=' $clashdir/mark | awk -F "=" '{print $2}')" = "已启用" ] && autoSSH
#设置init.d服务
cp -f $clashdir/clashservice /etc/init.d/clash
chmod 755 /etc/init.d/clash

View File

@@ -125,22 +125,6 @@ put_save(){
mark_time(){
echo `date +%s` > /tmp/clash_start_time
}
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
[ -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
}
getlanip(){
host_ipv4=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'br' | grep -v 'iot' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/br.*$//g' ) #ipv4局域网网段
host_ipv6=$(ip a 2>&1 | grep -w 'inet6' | grep -E 'global' | sed 's/.*inet6.//g' | sed 's/scope.*$//g' ) #ipv6公网地址段
@@ -1250,7 +1234,7 @@ afstart(){
}
ckcmd iptables && start_wan
#同步本机时间
ckcmd ntpd && ntpd -n -q -p 203.107.6.88 &
ckcmd ntpd && ntpd -n -q -p 203.107.6.88 &>/dev/null &
#标记启动时间
mark_time
#加载定时任务
@@ -1258,8 +1242,7 @@ afstart(){
#启用面板配置自动保存
cronset '#每10分钟保存节点配置' "*/10 * * * * test -n \"\$(pidof clash)\" && $clashdir/start.sh web_save #每10分钟保存节点配置"
[ -f $clashdir/web_save ] && web_restore & #后台还原面板配置
#自动开启SSH
[ "$mi_autoSSH" = "已启用" ] && autoSSH 2>/dev/null &
#推送日志
{ sleep 30;logger Clash服务已启动;} &
else
logger "Clash服务启动失败请查看报错信息" 31