diff --git a/bin/clashfm.tar.gz b/bin/clashfm.tar.gz index b1cb18d..d3db424 100644 Binary files a/bin/clashfm.tar.gz and b/bin/clashfm.tar.gz differ diff --git a/bin/version b/bin/version index 2d89ca6..f73a2eb 100644 --- a/bin/version +++ b/bin/version @@ -3,4 +3,4 @@ GeoIP_v=202201280303 clashpre_v=2021.09.15 clash_v=v1.7.1 meta_v=develop-76dcceb -versionsh=1.5.3 +versionsh=1.5.4 diff --git a/scripts/clash.sh b/scripts/clash.sh index 01f34a0..18e5183 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -525,8 +525,8 @@ localproxy(){ echo -e "\033[33m当前本机代理配置方式为:\033[32m$local_type\033[0m" echo ----------------------------------------------- echo -e " 1 \033[36m$proxy_set本机代理\033[0m" - echo -e " 2 使用\033[32m环境变量\033[0m方式配置" - echo -e " 3 使用\033[32miptables增强模式\033[0m配置(仅支持Linux系统)" + echo -e " 2 使用\033[32m环境变量\033[0m方式配置(部分应用可能无法使用)" + echo -e " 3 使用\033[32miptables增强模式\033[0m配置(仅支持Linux系统)" echo -e " 0 返回上级菜单" echo ----------------------------------------------- read -p "请输入对应数字 > " num @@ -813,7 +813,7 @@ clashadv(){ echo -e "\033[30;47m欢迎使用进阶模式菜单:\033[0m" echo -e "\033[33m如您并不了解clash的运行机制,请勿更改本页面功能!\033[0m" echo ----------------------------------------------- - echo -e " 1 使用保守方式启动: \033[36m$start_old\033[0m ————切换时会停止clash服务" + echo -e " 1 使用保守模式启动: \033[36m$start_old\033[0m ————切换时会停止clash服务" echo -e " 2 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性功能,可能不稳定" echo -e " 3 Redir模式udp转发: \033[36m$tproxy_mod\033[0m ————依赖iptables-mod-tproxy" echo -e " 4 启用小闪存模式: \033[36m$mini_clash\033[0m ————不保存核心及数据库文件" @@ -857,9 +857,11 @@ clashadv(){ else if [ -f /etc/init.d/clash -o -w /etc/systemd/system -o -w /usr/lib/systemd/system ];then echo -e "\033[32m改为使用默认方式启动clash服务!!\033[0m" + $clashdir/start.sh cronset "ShellClash初始化" start_old=未开启 setconfig start_old $start_old $clashdir/start.sh stop + else echo -e "\033[31m当前设备不支持以其他模式启动!!\033[0m" sleep 1 @@ -1158,6 +1160,7 @@ tools(){ } #获取设置默认显示 [ -n "$(cat /etc/crontabs/root 2>1| grep otapredownload)" ] && mi_update=禁用 || mi_update=启用 + [ "$mi_autoSSH" = "禁用" ] && mi_autoSSH=启用 || mi_autoSSH=禁用 # echo ----------------------------------------------- echo -e "\033[30;47m欢迎使用其他工具菜单:\033[0m" @@ -1166,10 +1169,11 @@ tools(){ du -sh $clashdir echo ----------------------------------------------- echo -e " 1 ShellClash测试菜单" - [ -f "/etc/firewall.user" ] && echo -e " 2 \033[32m配置\033[0m外网访问SSH" - [ -f "/etc/config/ddns" -a -d "/etc/ddns" ] && echo -e " 3 配置DDNS服务(需下载相关脚本)" + [ -f /etc/firewall.user ] && echo -e " 2 \033[32m配置\033[0m外网访问SSH" + [ -f /etc/config/ddns -a -d "/etc/ddns" ] && echo -e " 3 配置DDNS服务(需下载相关脚本)" echo -e " 4 \033[32m流媒体预解析\033[0m————用于解决DNS解锁在TV应用上失效的问题" - [ -x /usr/sbin/otapredownload ] && echo -e " 5 \033[33m$mi_update\033[0m小米系统自动更新" + [ -x /usr/sbin/otapredownload ] && echo -e " 5 \033[33m$mi_update\033[0m小米系统自动更新\n \ + 6 \033[33m$mi_autoSSH\033[0m小米设备自动启用SSH(依赖clash服务)" echo ----------------------------------------------- echo -e " 0 返回上级菜单 \033[0m" echo ----------------------------------------------- @@ -1204,13 +1208,6 @@ tools(){ sleep 1 tools - elif [ -x /usr/sbin/otapredownload ] && [ "$num" = 5 ]; then - [ "$mi_update" = "禁用" ] && sed -i "/otapredownload/d" /etc/crontabs/root || echo "15 3,4,5 * * * /usr/sbin/otapredownload >/dev/null 2>&1" >> /etc/crontabs/root - echo ----------------------------------------------- - echo -e "已\033[33m$mi_update\033[0m小米路由器的自动启动,如未生效,请在官方APP中同步设置!" - sleep 1 - tools - elif [ "$num" = 4 ]; then nslookup baidu.com > /dev/null 2>&1 if [ "$?" = 0 ];then @@ -1229,6 +1226,21 @@ tools(){ fi tools + elif [ -x /usr/sbin/otapredownload ] && [ "$num" = 5 ]; then + [ "$mi_update" = "禁用" ] && sed -i "/otapredownload/d" /etc/crontabs/root || echo "15 3,4,5 * * * /usr/sbin/otapredownload >/dev/null 2>&1" >> /etc/crontabs/root + echo ----------------------------------------------- + echo -e "已\033[33m$mi_update\033[0m小米路由器的自动启动,如未生效,请在官方APP中同步设置!" + sleep 1 + tools + + elif [ -x /usr/sbin/otapredownload ] && [ "$num" = 6 ]; then + [ "$mi_autoSSH" = "禁用" ] && mi_autoSSH=启用 || mi_autoSSH=禁用 + setconfig mi_autoSSH $mi_autoSSH + echo ----------------------------------------------- + echo -e "\033[32m本功能仅对已固化设备生效!未固化设备请先自行固化SSH!\033[0m" + echo -e "已\033[33m$mi_autoSSH\033[0m小米路由相关设备升级后自动启用SSH功能!" + sleep 1 + tools else errornum fi @@ -1511,6 +1523,7 @@ case "$1" in rm -rf /etc/systemd/system/clash.service rm -rf /usr/lib/systemd/system/clash.service rm -rf /www/clash + rm -rf /tmp/clash_$USER sed -Ei s/0:7890/7890:7890/g /etc/passwd userdel -r shellclash 2>/dev/null echo ----------------------------------------------- diff --git a/scripts/getdate.sh b/scripts/getdate.sh index 23419d5..42343db 100644 --- a/scripts/getdate.sh +++ b/scripts/getdate.sh @@ -399,7 +399,7 @@ getsh(){ getcpucore(){ cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]') [ -n "$(echo $cputype | grep -E "linux.*armv.*")" ] && cpucore="armv5" - [ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && cpucore="armv7" + [ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && [ ! -d /jffs/clash ] && cpucore="armv7" [ -n "$(echo $cputype | grep -E "linux.*aarch64.*|linux.*armv8.*")" ] && cpucore="armv8" [ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="386" [ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="amd64" @@ -715,6 +715,7 @@ setserver(){ saveserver(){ #写入mark文件 setconfig update_url \'$update_url\' + setconfig release_url \'$release_url\' echo ----------------------------------------------- echo -e "\033[32m源地址更新成功!\033[0m" release_new="" @@ -723,29 +724,41 @@ setserver(){ echo -e "\033[30;47m切换ShellClash版本及更新源地址\033[0m" echo -e "当前源地址:\033[4;32m$update_url\033[0m" echo ----------------------------------------------- - echo -e " 1 \033[32m正式版\033[0m&Jsdelivr-CDN源(推荐)" - echo -e " 2 \033[36m测试版\033[0m&Jsdelivr-CDN源" - echo -e " 3 \033[36m测试版\033[0m&Github源(需开启clash服务)" - [ -z "$(curl -V 2>/dev/null)" ] && [ -n "$(wget -V 2>&1 | grep BusyBox)" ] && echo -e " 4 \033[33mHttp专用源\033[0m" - echo -e " 5 自定义源地址(用于本地源或自建源)" - echo -e " 6 \033[31m版本回退\033[0m" + echo -e " 1 \033[32m正式版\033[0m&Github源(ghproxy.com加速)" + echo -e " 2 \033[32m正式版\033[0m&Jsdelivr-CDN源" + echo -e " 3 \033[36m测试版\033[0m&Github源(本机clash服务加速)" + echo -e " 4 \033[36m测试版\033[0m&Github源(ghproxy.com加速)" + echo -e " 5 \033[36m测试版\033[0m&Github源(githubusercontents加速)" + [ -z "$(curl -V 2>/dev/null)" ] && [ -n "$(wget -V 2>&1 | grep BusyBox)" ] && echo -e " 6 \033[33mHttp专用源\033[0m" + echo -e " 7 自定义源地址(用于本地源或自建源)" + echo -e " 8 \033[31m版本回退\033[0m" echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num if [ -z "$num" ]; then errornum elif [ "$num" = 1 ]; then - update_url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash' + release_url='https://ghproxy.com/https://raw.githubusercontent.com/juewuy/ShellClash' saveserver elif [ "$num" = 2 ]; then - update_url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master' + release_url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash' saveserver elif [ "$num" = 3 ]; then update_url='https://raw.githubusercontent.com/juewuy/ShellClash/master' + release_url='' saveserver elif [ "$num" = 4 ]; then - update_url='http://shellclash.ga' + update_url='https://ghproxy.com/https://raw.githubusercontent.com/juewuy/ShellClash/master' + release_url='' saveserver elif [ "$num" = 5 ]; then + update_url='https://raw.githubusercontents.com/juewuy/ShellClash/master' + release_url='' + saveserver + elif [ "$num" = 6 ]; then + update_url='http://shellclash.ga' + release_url='' + saveserver + elif [ "$num" = 7 ]; then echo ----------------------------------------------- read -p "请输入个人源路径 > " update_url if [ -z "$update_url" ];then @@ -753,8 +766,9 @@ setserver(){ echo -e "\033[31m取消输入,返回上级菜单\033[0m" else saveserver + release_url='' fi - elif [ "$num" = 6 ]; then + elif [ "$num" = 8 ]; then echo ----------------------------------------------- $clashdir/start.sh webget /tmp/clashrelease https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master/bin/release_version echooff rediroff 2>/tmp/clashrelease echo -e "\033[31m请选择想要回退至的release版本:\033[0m" @@ -767,27 +781,30 @@ setserver(){ release_version=$(cat /tmp/clashrelease | awk '{print $1}' | sed -n "$num"p) update_url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash@$release_version" saveserver + release_url='' else echo ----------------------------------------------- echo -e "\033[31m输入有误,请重新输入!\033[0m" fi - - elif [ "$num" = 9 ]; then - update_url='http://192.168.123.90:8080/ShellClash' else errornum fi } checkupdate(){ if [ -z "$release_new" ];then - if [ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ];then - $clashdir/start.sh webget /tmp/clashversion $update_url@master/bin/release_version echoon rediroff 2>/tmp/clashrelease - [ "$?" = "0" ] && release_new=$(cat /tmp/clashversion | head -1) - update_url=$update_url@$release_new + if [ -n "$release_url" ];then + [ "$release_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ] && check_url=$release_url@master || check_url=$release_url/master + $clashdir/start.sh webget /tmp/clashversion $check_url/bin/release_version echoon rediroff 2>/tmp/clashversion + release_new=$(cat /tmp/clashversion | head -1) + [ "$release_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ] && update_url=$release_url@$release_new || update_url=$release_url/$release_new + setconfig update_url \'$update_url\' + release_type=正式版 + else + release_type=测试版 fi $clashdir/start.sh webget /tmp/clashversion $update_url/bin/version echooff [ "$?" = "0" ] && release_new=$(cat /tmp/clashversion | grep versionsh | awk -F'=' '{ print $2 }') - [ -n "$release_new" ] &&source /tmp/clashversion || echo -e "\033[31m检查更新失败!请检查网络连接或切换安装源!\033[0m" + [ -n "$release_new" ] && source /tmp/clashversion || echo -e "\033[31m检查更新失败!请检查网络连接或切换安装源!\033[0m" rm -rf /tmp/clashversion fi } @@ -803,7 +820,7 @@ update(){ [ -z "$clash_v" ] && clash_v=$clashv echo -e "\033[30;47m欢迎使用更新功能:\033[0m" echo ----------------------------------------------- - echo -e " 1 更新\033[36m管理脚本 \033[33m$versionsh_l\033[0m > \033[32m$versionsh\033[0m" + echo -e " 1 更新\033[36m管理脚本 \033[33m$versionsh_l\033[0m > \033[32m$versionsh$release_type\033[0m" echo -e " 2 切换\033[33mclash核心 \033[33m$clash_v\033[0m > \033[32m$clash_n\033[0m" echo -e " 3 更新\033[32mGeoIP/CN-IP \033[33m$Geo_v\033[0m > \033[32m$GeoIP_v\033[0m" echo -e " 4 安装本地\033[35mDashboard\033[0m面板" @@ -875,7 +892,7 @@ userguide(){ echo ----------------------------------------------- echo -e "\033[33m是否需要代理UDP流量(主要用于连接外服游戏)? \033[0m" echo ----------------------------------------------- - echo -e " 1 \033[33m不代理UDP流量\033[0m(推荐)" + echo -e " 1 \033[33m不代理UDP流量(推荐)\033[0m" ip tuntap >/dev/null 2>&1 && [ "$?" = 0 ] && \ echo -e " 2 \033[32m使用Tun虚拟网卡\033[0m代理UDP流量" || \ echo -e " - \033[0m使用Tun模式(你的设备不支持此模式,如为虚拟机运行请调整虚拟网卡设置)\033[0m" @@ -905,8 +922,8 @@ userguide(){ echo -e "\033[33m请先选择你的使用环境: \033[0m" echo -e "\033[0m(你之后依然可以在设置中更改各种配置)\033[0m" echo ----------------------------------------------- - echo -e " 1 \033[32m主路由或旁路由\033[0m" - echo -e " 2 \033[36mLinux本机代理\033[0m" + echo -e " 1 \033[32m路由设备配置局域网透明代理\033[0m" + echo -e " 2 \033[36mLinux设备仅配置本机代理\033[0m" [ -f "$ccfg.bak" ] && echo -e " 3 \033[33m还原之前备份的设置\033[0m" echo ----------------------------------------------- read -p "请输入对应数字 > " num @@ -998,16 +1015,16 @@ userguide(){ echo -e "注意当前设备必须有公网IP才能从公网正常访问" echo -e "\033[31m此功能会增加暴露风险请谨慎使用!\033[0m" echo -e "vps设备可能还需要额外在服务商后台开启相关端口(默认为7890与9999)" - echo -e "启用后会自动设置面板访问秘钥(shellclash)以及Socks密码(shell:clash)" read -p "现在开启?(1/0) > " res if [ "$res" = 1 ];then + read -p "请先设置面板访问秘钥 > " secret + read -p "请先设置Socks服务密码(账号默认为clash) > " sec + [ -z "$sec" ] && authentication=clash:$sec host=$(curl ip.sb 2>/dev/null | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') if [ -z "$host" ];then sethost fi public_support=已开启 - authentication=shell:clash - secret=shellclash setconfig secret $secret setconfig host $host setconfig public_support $public_support @@ -1035,9 +1052,9 @@ testcommand(){ echo -e "\033[30;47m这里是测试命令菜单\033[0m" echo -e "\033[33m如遇问题尽量运行相应命令后截图发群\033[0m" echo ----------------------------------------------- - echo " 1 查看clash运行时的报错信息" + echo " 1 查看Clash运行时的报错信息(会停止clash服务)" echo " 2 查看系统DNS端口(:53)占用 " - echo " 3 测试ssl加密(aes-128-gcm)跑分" + echo " 3 测试ssl加密(aes-128-gcm)跑分" echo " 4 查看iptables端口转发详情" echo " 5 查看config.yaml前40行" echo " 6 测试代理服务器连通性(google.tw)" diff --git a/scripts/start.sh b/scripts/start.sh index ee31299..6f20444 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -22,6 +22,7 @@ getconfig(){ [ -z "$mix_port" ] && mix_port=7890 [ -z "$redir_port" ] && redir_port=7892 [ -z "$db_port" ] && db_port=9999 + [ -z "$restore" ] && restore=false [ -z "$dns_port" ] && dns_port=1053 [ -z "$stearming_int" ] && stearming_int=24 [ -z "$dns_nameserver" ] && dns_nameserver='114.114.114.114, 223.5.5.5' @@ -81,6 +82,15 @@ mark_time(){ sed -i '/start_time*/'d $clashdir/mark echo start_time=$start_time >> $clashdir/mark } +autoSSH(){ + #自动开启SSH + nvram set telnet_en=1 + nvram set uart_en=1 + nvram set ssh_en=1 + nvram commit + sed -i 's/channel=.*/channel="debug"/g' /etc/init.d/dropbear + /etc/init.d/dropbear start +} #配置文件相关 getyaml(){ [ -z "$rule_link" ] && rule_link=1 @@ -255,7 +265,7 @@ modify_yaml(){ b=$(grep -n "^prox" $yaml | head -1 | cut -d ":" -f 1) b=$((b-1)) mkdir -p $tmpdir > /dev/null - [ "$b" != "0" ] && sed "${a},${b}d" $yaml > $tmpdir/proxy.yaml + [ "$b" -gt 0 ] && sed "${a},${b}d" $yaml > $tmpdir/proxy.yaml || cp -f $yaml $tmpdir/proxy.yaml #跳过本地tls证书验证 [ "$skip_cert" = "已开启" ] && sed -i '1,99s/skip-cert-verify: false/skip-cert-verify: true/' $tmpdir/proxy.yaml #添加配置 @@ -639,7 +649,7 @@ bfstart(){ #读取配置文件 getconfig [ ! -d $bindir/ui ] && mkdir -p $bindir/ui - [ -z "$update_url" ] || [ -n "$(echo $update_url | grep 'github')" ] && update_url=https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master + update_url=https://ghproxy.com/https://raw.githubusercontent.com/juewuy/ShellClash/master #检查clash核心 if [ ! -f $bindir/clash ];then if [ -f $clashdir/clash ];then @@ -747,15 +757,15 @@ afstart(){ #加载定时任务 [ -f $clashdir/cron ] && croncmd $clashdir/cron #流媒体预解析 - if [ "$netflix_pre" = "已开启" -o "$disneyp_pre" = "已开启" ];then + if [ "$netflix_pre" = "已开启" -o "$disneyP_pre" = "已开启" ];then cronset '#ShellClash流媒体预解析' "* */$stearming_int * * * $clashdir/start.sh steaming #ShellClash流媒体预解析" $0 steaming & #后台执行流媒体预解析进程 fi #启用面板配置自动保存 - if [ "$restore" = false ];then - cronset '#每10分钟保存节点配置' "*/10 * * * * test -n \"\$(pidof clash)\" && $clashdir/start.sh web_save #每10分钟保存节点配置" - [ -f $clashdir/web_save ] && web_restore & #后台还原面板配置 - fi + cronset '#每10分钟保存节点配置' "*/10 * * * * test -n \"\$(pidof clash)\" && $clashdir/start.sh web_save #每10分钟保存节点配置" + [ -f $clashdir/web_save ] && web_restore & #后台还原面板配置 + #自动开启SSH + [ "$autoSSH" = "禁用" ] && [ -z "$(pidof sshd)" -o -z "$(netstat -ntul | grep :22)" ] && autoSSH 2>/dev/null else logger "clash服务启动失败!请查看报错信息!" 31 $bindir/clash -t -d $bindir @@ -840,12 +850,7 @@ init) clashdir=/data/clash profile=/etc/profile #开启SSH - nvram set telnet_en=1 - nvram set uart_en=1 - nvram set ssh_en=1 - nvram commit - sed -i 's/channel=.*/channel="debug"/g' /etc/init.d/dropbear - /etc/init.d/dropbear start + autoSSH 2>/dev/null fi echo "alias clash=\"$clashdir/clash.sh\"" >> $profile echo "export clashdir=\"$clashdir\"" >> $profile @@ -925,10 +930,16 @@ unset_proxy) steaming) getconfig #设置循环检测clashDNS端口 + ns_type=$(nslookup -version 2>&1 | grep -io busybox) + ns_lookup(){ + [ -n "$ns_type" ] && \ + nslookup $1 127.0.0.1:${dns_port} > /dev/null 2>&1 || \ + nslookup -port=${dns_port} $1 127.0.0.1 > /dev/null 2>&1 + } while [ "$i" != 0 ];do [ "$j" = 60 ] && exit 1 - sleep 1 - nslookup baidu.com 127.0.0.1:${dns_port} > /dev/null 2>&1 + sleep 1 + ns_lookup baidu.com i=$? j=$((j+1)) done @@ -942,7 +953,7 @@ steaming) fi if [ -f "$steaming_dir" ];then for line in $(cat $steaming_dir);do - [ -n "$line" ] && nslookup "$line" 127.0.0.1:${dns_port} + [ -n "$line" ] && ns_lookup "$line" done >/dev/null 2>&1 echo "$steaming_type域名预解析完成!" fi