From cf560be341d47eac3cab141b8a7d56b20f26c9e8 Mon Sep 17 00:00:00 2001 From: juewuy Date: Tue, 4 Apr 2023 10:23:19 +0800 Subject: [PATCH] =?UTF-8?q?v1.7.4c=20~=E4=BF=AE=E5=A4=8D=E5=B0=8F=E7=B1=B3?= =?UTF-8?q?=E4=B8=87=E5=85=86=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E5=BC=80?= =?UTF-8?q?=E5=90=AF=E5=90=AF=E5=8A=A8=E7=9A=84bug=20~=E5=B0=8F=E7=B1=B3?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E8=BD=AF=E5=9B=BA=E5=8C=96=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E4=BE=9D=E8=B5=96clash=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=20~=E6=9C=AC=E5=9C=B0=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E9=80=82=E9=85=8D=E5=B0=8F=E7=B1=B3=E4=B8=87?= =?UTF-8?q?=E5=85=86=E8=AE=BE=E5=A4=87=20~=E5=B1=8F=E8=94=BDntp=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=9C=8D=E5=8A=A1=E7=9A=84=E6=8A=A5=E9=94=99=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/clash.sh | 1 - scripts/init.sh | 34 ++++++++++++++++++++-------------- scripts/misnap_init.sh | 21 ++++++++++++++++++++- scripts/start.sh | 21 ++------------------- 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/scripts/clash.sh b/scripts/clash.sh index 9735749..7a0735a 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -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=已启用 diff --git a/scripts/init.sh b/scripts/init.sh index 9f66746..547dc8b 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -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 diff --git a/scripts/misnap_init.sh b/scripts/misnap_init.sh index e643a2a..3f86633 100644 --- a/scripts/misnap_init.sh +++ b/scripts/misnap_init.sh @@ -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 diff --git a/scripts/start.sh b/scripts/start.sh index eb1f9e1..464fc68 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -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