1.合并Tun和Redir模式为一套文件,可以通过管理脚本直接切换

2.同步官方最新premium版核心,支持SSR
3.优化脚本可用性,增加了部分实用功能
This commit is contained in:
juewuy 2020-07-26 21:21:47 +08:00
parent 52f33c9c6e
commit e7858e8b63
14 changed files with 265 additions and 1837 deletions

BIN
bin/clash-linux-armv7 Normal file

Binary file not shown.

BIN
bin/clash-linux-armv8 Normal file

Binary file not shown.

View File

@ -4,20 +4,7 @@
USE_PROCD=1
START=99
start_service() {
#创建clash后台进程
procd_open_instance
procd_set_param respawn
procd_set_param stderr 1
procd_set_param stdout 1
procd_set_param command /etc/clash/clash -d /etc/clash
procd_close_instance
#重置iptables规则
iptables -t nat -D PREROUTING -p tcp -j clash > /dev/null 2>&1
iptables -t nat -F clash > /dev/null 2>&1
iptables -t nat -X clash > /dev/null 2>&1
iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1
start_redir(){
#修改iptables规则使流量进入clash
iptables -t nat -N clash
iptables -t nat -A clash -d 0.0.0.0/8 -j RETURN
@ -32,10 +19,46 @@ start_service() {
iptables -t nat -A PREROUTING -p tcp -j clash
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}
stop_service() {
stop_redir(){
#重置iptables规则
iptables -t nat -D PREROUTING -p tcp -j clash
iptables -t nat -F clash
iptables -t nat -X clash
iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
iptables -t nat -D PREROUTING -p tcp -j clash > /dev/null 2>&1
iptables -t nat -F clash > /dev/null 2>&1
iptables -t nat -X clash > /dev/null 2>&1
iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1
}
start_tun(){
#修改iptables规则使流量进入clash
iptables -I FORWARD -o utun -j ACCEPT
iptables -t nat -I PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}
stop_tun(){
iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1
}
start_service() {
#创建clash后台进程
procd_open_instance
procd_set_param respawn
procd_set_param stderr 1
procd_set_param stdout 1
procd_set_param command /etc/clash/clash -d /etc/clash
procd_close_instance
#修改iptables规则使流量进入clash
Mod=`cat /bin/clash | grep 'Mark3=' -m1`
result=$(echo $Mod | grep "Tun模式")
if [[ "$result" != "" ]];then
stop_tun
start_tun
else
stop_redir
start_redir
fi
}
stop_service() {
Mod=`cat /bin/clash | grep 'Mark3=' -m1`
result=$(echo $Mod | grep "Tun模式")
if [[ "$result" != "" ]];then
stop_tun
else
stop_redir
fi
}

223
clash/clashsh Normal file
View File

@ -0,0 +1,223 @@
#!/bin/sh
# Copyright (C) Juewuy
echo "***********************************************"
echo "** 欢迎使用 **"
echo "** Clash for Miwifi **"
echo "** by Juewuy **"
echo "***********************************************"
Mark1=""
Mark2="\033[31m未设置开机启动\033[0m"
Mark3="Tun模式"
clashlink(){
exit;
}
clashadv(){
echo -----------------------------------------------
echo -e "\033[33m欢迎使用高级模式菜单\033[0m"
echo 1 切换代理模式Tun/Redir
echo 2 更新clash核心文件施工中
echo 3 更新GeoIP数据库施工中
echo 4 更新管理脚本(施工中)
echo 9 卸载clash
echo 0 返回上级菜单
read -p "请输入对应数字 > " num
if [[ $num -le 9 ]] > /dev/null 2>&1; then
if [[ $num == 0 ]]; then
clashsh
elif [[ $num == 1 ]]; then
echo -----------------------------------------------
echo -e "当前代理模式为:\033[47;30m $Mark3 \033[0m"
echo -e "\033[33m切换模式时会重启clash服务可能会导致短时间的网络中断\033[0m"
echo "1 Tun模式 支持UDP转发且延迟低"
echo " 但CPU及内存占用更高"
echo " 适合外服游戏用户"
echo "2 Redir模式CPU以及内存占用较低"
echo " 但不支持UDP流量转发"
echo " 日常使用推荐此模式"
echo 0 返回上级菜单
read -p "请输入对应数字 > " num
if [[ $num == 0 ]]; then
clashadv
elif [[ $num == 1 ]]; then
if [[ $Mark3 = "Redir模式" ]]; then
sed -i '1,20s/Redir模式/Tun模式/' /bin/clash #修改Mark3标记
if [ $Number1 -gt 0 ];then
echo -----------------------------------------------
echo -e "\033[33m正在重启clash进程……\033[0m"
/etc/init.d/clash stop > /dev/null 2>&1
fi
/etc/init.d/clash start
Number2=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l`
if [ $Number2 -gt 0 ];then
echo -----------------------------------------------
echo -e "\033[32mclash服务已启动\033[0m"
echo -e "\033[33mclash已成功切换为\033[47;34m Tun模式! \033[0m"
echo -e 可以使用 "\033[32mhttp://clash.razord.top\033[0m"IP为网关IP端口为9999管理clash内置规则
Mark3="Tun模式"
clashsh
else
echo -----------------------------------------------
echo -e "\033[31mclash服务启动失败请检查配置文件\033[0m"
clashsh
fi
else
echo -----------------------------------------------
echo -e "\033[33m当前已经处于Tun模式无需重复设置\033[0m"
clashadv
fi
elif [[ $num == 2 ]]; then
if [[ $Mark3 = "Tun模式" ]]; then
sed -i '1,20s/Tun模式/Redir模式/' /bin/clash #修改Mark3标记
if [ $Number1 -gt 0 ];then
echo -----------------------------------------------
echo -e "\033[33m正在重启clash进程……\033[0m"
/etc/init.d/clash stop > /dev/null 2>&1
fi
/etc/init.d/clash start
Number2=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l`
if [ $Number2 -gt 0 ];then
echo -----------------------------------------------
echo -e "\033[32mclash服务已启动\033[0m"
echo -e "\033[33mclash已成功切换为\033[47;34m Redir模式! \033[0m"
echo -e 可以使用 "\033[32mhttp://clash.razord.top\033[0m"IP为网关IP端口为9999管理clash内置规则
Mark3="Redir模式"
clashsh
else
echo -----------------------------------------------
echo -e "\033[31mclash服务启动失败请检查配置文件\033[0m"
clashsh
fi
else
echo -----------------------------------------------
echo -e "\033[33m当前已经处于Redir模式无需重复设置\033[0m"
clashadv
fi
else
echo -e "\033[31m请输入正确的数字\033[0m"
clashadv
fi
elif [[ $num == 9 ]]; then
read -p "确认卸载clash警告该操作不可逆[1/0] " res
if [ "$res" = '1' ]; then
/etc/init.d/clash disable
/etc/init.d/clash stop
rm -rf /etc/clash
rm /etc/init.d/clash
rm /bin/clash
echo 已卸载clash相关文件
fi
exit;
else
echo -e "\033[31m暂未支持的选项\033[0m"
clashadv
fi
else
echo -e "\033[31m请输入正确的数字\033[0m"
clashsh
fi
exit;
}
clashsh(){
Number1=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l`
if [ $Number1 -gt 0 ];then
Mark1="\033[32m正在运行$Mark3\033[0m"
else
Mark1="\033[31m没有运行$Mark3\033[0m"
fi
echo -----------------------------------------------
echo -e "Clash服务$Mark1,$Mark2"
echo 1 启动/重启clash服务
echo 2 测试代理服务器连通性
echo 3 停止clash服务
echo 4 允许clash开机启动
echo 5 禁止clash开机启动
echo 6 使用链接导入节点/订阅
echo 7 高级设置
echo 0 退出脚本
read -p "请输入对应数字 > " num
if [[ $num -le 7 ]] > /dev/null 2>&1; then
if [[ $num == 0 ]]; then
exit;
elif [[ $num == 1 ]]; then
if [ $Number1 -gt 0 ];then
echo -----------------------------------------------
/etc/init.d/clash stop > /dev/null 2>&1
echo -e "\033[31mClash服务已停止\033[0m"
sleep 1
fi
/etc/init.d/clash start
Number2=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l`
if [ $Number2 -gt 0 ];then
echo -----------------------------------------------
echo -e "\033[32mclash服务已启动\033[0m"
echo 可以使用 http://clash.razord.top IP为网关IP端口为9999管理clash内置规则
clashsh
else
echo -----------------------------------------------
echo -e "\033[31mclash服务启动失败请检查配置文件\033[0m"
clashsh
fi
exit;
elif [[ $num == 2 ]]; then
echo 注意连续多次测试可能会导致IP暂时被GitHub封禁
delay=`curl -kx socks5://127.0.0.1:7891 -o /dev/null -s -w '%{time_total}' 'https://github.com' & { sleep 3 ; kill $! & }` > /dev/null 2>&1
delay0=`expr length x$delay`
#echo $delay
if [ $delay0 == 1 ];then
echo ----------------------------------------------
echo '连接超时(>3s请检查节点信息'
clashsh
else
echo -----------------------------------------------
echo 连接成功!响应时间为:$delay秒
clashsh
fi
elif [[ $num == 3 ]]; then
/etc/init.d/clash stop > /dev/null 2>&1
echo -----------------------------------------------
echo -e "\033[31mClash服务已停止\033[0m"
echo -----------------------------------------------
exit;
elif [[ $num == 4 ]]; then
/etc/init.d/clash enable
sed -i '1,20s/1m未/2m已/' /bin/clash
echo -----------------------------------------------
echo -e "\033[32m已设置Clash开机启动\033[0m"
Mark2="\033[32m已设置开机启动\033[0m"
clashsh
elif [[ $num == 5 ]]; then
/etc/init.d/clash disable
sed -i '1,20s/2m已/1m未/' /bin/clash
echo -----------------------------------------------
echo -e "\033[33m已禁止Clash开机启动\033[0m"
Mark2="\033[31m未设置开机启动\033[0m"
clashsh
elif [[ $num == 6 ]]; then
clashlink
elif [[ $num == 7 ]]; then
clashadv
else
echo -e "\033[31m请输入正确的数字\033[0m"
fi
exit 1
else
echo -e "\033[31m请输入正确的数字\033[0m"
fi
exit 1
}
clashsh

Binary file not shown.

View File

@ -1,115 +0,0 @@
#!/bin/sh
# Copyright (C) 2006-2011 OpenWrt.org
echo "***********************************************"
echo "** 欢迎使用 **"
echo "** Clash for MiwifiRedir模式 **"
echo "** by Juewuy **"
echo "***********************************************"
Number1=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l`
if [ $Number1 -gt 0 ];then
Mark1="\033[32m正在运行\033[0m"
else
Mark1="\033[31m没有运行\033[0m"
fi
Mark2="\033[31m未设置开机启动\033[0m"
echo -e "Clash服务$Mark1,$Mark2"
clashsh(){
echo -----------------------------------------------
echo 1 启动clash服务
echo 2 重启clash服务
echo 3 停止clash服务
echo 4 设置clash开机启动
echo 5 禁止clash开机启动
echo 6 卸载clash相关文件
echo 0 退出脚本
read -p "请输入对应数字>" num
if [[ $num -le 6 ]] > /dev/null 2>&1; then
if [[ $num == 0 ]]; then
exit;
elif [[ $num == 1 ]]; then
if [ $Number1 -gt 0 ];then
echo -----------------------------------------------
echo -e "\033[31mclash服务运行中请勿重复启动\033[0m"
clashsh
exit;
else
/etc/init.d/clash start
Number2=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l`
if [ $Number2 -gt 0 ];then
echo -----------------------------------------------
echo -e "\033[32mclash服务已启动\033[0m"
echo 可以使用 http://clash.razord.top IP为网关IP端口为9999管理clash内置规则
clashsh
else
echo -----------------------------------------------
echo -e "\033[31mclash服务启动失败请检查配置文件\033[0m"
clashsh
fi
exit;
fi
exit;
elif [[ $num == 2 ]]; then
/etc/init.d/clash stop > /dev/null 2>&1
/etc/init.d/clash start
Number2=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l`
if [ $Number2 -gt 0 ];then
echo -----------------------------------------------
echo -e "\033[32mclash服务已启动\033[0m"
echo 可以使用 http://clash.razord.top IP为网关IP端口为9999管理clash内置规则
clashsh
else
echo -----------------------------------------------
echo -e "\033[31mclash服务启动失败请检查配置文件\033[0m"
clashsh
fi
exit;
elif [[ $num == 3 ]]; then
/etc/init.d/clash stop > /dev/null 2>&1
echo -----------------------------------------------
echo -e "\033[31mClash服务已停止\033[0m"
echo -----------------------------------------------
exit;
elif [[ $num == 4 ]]; then
/etc/init.d/clash enable
sed -i '2,30s/1m未/2m已/g' /bin/clash
echo -----------------------------------------------
echo -e "\033[32m已设置Clash开机启动\033[0m"
clashsh
exit;
elif [[ $num == 5 ]]; then
/etc/init.d/clash disable
sed -i '2,30s/2m已/1m未/g' /bin/clash
echo -----------------------------------------------
echo -e "\033[33m已禁止Clash开机启动\033[0m"
clashsh
exit;
elif [[ $num == 6 ]]; then
read -p "确认卸载clash[1/0] " res
if [ "$res" = '1' ]; then
/etc/init.d/clash disable
/etc/init.d/clash stop
rm -rf /etc/clash
rm /etc/init.d/clash
rm /bin/clash
echo 已卸载clash相关文件
fi
exit;
else
echo -e "\033[31m请输入正确的数字\033[0m"
fi
exit 1
else
echo -e "\033[31m请输入正确的数字\033[0m"
fi
exit 1
}
clashsh

Binary file not shown.

View File

@ -1,22 +0,0 @@
#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007 OpenWrt.org
USE_PROCD=1
START=99
start_service() {
#创建clash后台进程
procd_open_instance
procd_set_param respawn
procd_set_param stderr 1
procd_set_param stdout 1
procd_set_param command /etc/clash/clash -d /etc/clash
procd_close_instance
#修改iptables规则使流量进入clash
iptables -I FORWARD -o utun -j ACCEPT
iptables -t nat -I PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}
stop_service() {
iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}

View File

@ -1,115 +0,0 @@
#!/bin/sh
# Copyright (C) 2006-2011 OpenWrt.org
echo "***********************************************"
echo "** 欢迎使用 **"
echo "** Clash for MiwifiTun模式 **"
echo "** by Juewuy **"
echo "***********************************************"
Number1=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l`
if [ $Number1 -gt 0 ];then
Mark1="\033[32m正在运行\033[0m"
else
Mark1="\033[31m没有运行\033[0m"
fi
Mark2="\033[31m未设置开机启动\033[0m"
echo -e "Clash服务$Mark1,$Mark2"
clashsh(){
echo -----------------------------------------------
echo 1 启动clash服务
echo 2 重启clash服务
echo 3 停止clash服务
echo 4 设置clash开机启动
echo 5 禁止clash开机启动
echo 6 卸载clash相关文件
echo 0 退出脚本
read -p "请输入对应数字>" num
if [[ $num -le 6 ]] > /dev/null 2>&1; then
if [[ $num == 0 ]]; then
exit;
elif [[ $num == 1 ]]; then
if [ $Number1 -gt 0 ];then
echo -----------------------------------------------
echo -e "\033[31mclash服务运行中请勿重复启动\033[0m"
clashsh
exit;
else
/etc/init.d/clash start
Number2=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l`
if [ $Number2 -gt 0 ];then
echo -----------------------------------------------
echo -e "\033[32mclash服务已启动\033[0m"
echo 可以使用 http://clash.razord.top IP为网关IP端口为9999管理clash内置规则
clashsh
else
echo -----------------------------------------------
echo -e "\033[31mclash服务启动失败请检查配置文件\033[0m"
clashsh
fi
exit;
fi
exit;
elif [[ $num == 2 ]]; then
/etc/init.d/clash stop > /dev/null 2>&1
/etc/init.d/clash start
Number2=`ps |grep -w /etc/clash/clash|grep -v grep|wc -l`
if [ $Number2 -gt 0 ];then
echo -----------------------------------------------
echo -e "\033[32mclash服务已启动\033[0m"
echo 可以使用 http://clash.razord.top IP为网关IP端口为9999管理clash内置规则
clashsh
else
echo -----------------------------------------------
echo -e "\033[31mclash服务启动失败请检查配置文件\033[0m"
clashsh
fi
exit;
elif [[ $num == 3 ]]; then
/etc/init.d/clash stop > /dev/null 2>&1
echo -----------------------------------------------
echo -e "\033[31mClash服务已停止\033[0m"
echo -----------------------------------------------
exit;
elif [[ $num == 4 ]]; then
/etc/init.d/clash enable
sed -i '2,30s/1m未/2m已/g' /bin/clash
echo -----------------------------------------------
echo -e "\033[32m已设置Clash开机启动\033[0m"
clashsh
exit;
elif [[ $num == 5 ]]; then
/etc/init.d/clash disable
sed -i '2,30s/2m已/1m未/g' /bin/clash
echo -----------------------------------------------
echo -e "\033[33m已禁止Clash开机启动\033[0m"
clashsh
exit;
elif [[ $num == 6 ]]; then
read -p "确认卸载clash[1/0] " res
if [ "$res" = '1' ]; then
/etc/init.d/clash disable
/etc/init.d/clash stop
rm -rf /etc/clash
rm /etc/init.d/clash
rm /bin/clash
echo 已卸载clash相关文件
fi
exit;
else
echo -e "\033[31m请输入正确的数字\033[0m"
fi
exit 1
else
echo -e "\033[31m请输入正确的数字\033[0m"
fi
exit 1
}
clashsh

File diff suppressed because it is too large Load Diff

Binary file not shown.