~新增了Tun/Redir混合模式
~新增是否支持ipv6的开关
~新增了更新核心时的版本检测
~新增了本地面板重复安装提示
~修复了部分报错提示
~修复了部分设定未及时更新的bug
This commit is contained in:
juewuy
2020-08-09 13:51:37 +08:00
parent 8ce2598ff2
commit 1bb016c063
4 changed files with 658 additions and 559 deletions

Binary file not shown.

View File

@@ -9,7 +9,7 @@ echo "***********************************************"
getconfig(){
#版本号
versionsh_l=0.8.4
versionsh_l=0.8.5
#更新服务器地址
update_url="https://juewuy.xyz/clash"
#文件路径
@@ -24,7 +24,6 @@ EOF
fi
source $ccfg
#获取自启状态
#if [ $auto_start = true ] > /dev/null 2>&1; then
if [ -f /etc/rc.d/*clash ]; then
auto="\033[32m已设置开机启动\033[0m"
auto1="\033[36m禁用\033[0mclash开机启动"
@@ -44,7 +43,7 @@ run="\033[32m正在运行$redir_mod\033[0m"
uid=`ps |grep -w 'clash -d'|grep -v grep|awk '{print $1}'`
VmRSS=`cat /proc/$uid/status|grep -w VmRSS|awk '{print $2,$3}'`
#获取运行时长
if [ "$start_time" > 0 ] > /dev/null 2>&1; then
if [ -n "$start_time" ]; then
time=$((`date +%s`-$start_time))
day=$(($time/86400))
if [[ $day != 0 ]]; then
@@ -174,6 +173,7 @@ elif [[ $num == 3 ]];then
#将对应标记值写入mark
sed -i '/rule_link*/'d $ccfg
sed -i "4i\rule_link="$num"" $ccfg
rule_link=$num
echo -----------------------------------------------
echo -e "\033[32m设置成功返回上级菜单\033[0m"
clashlink
@@ -202,6 +202,7 @@ elif [[ $num == 4 ]];then
#将对应标记值写入mark
sed -i '/server_link*/'d $ccfg
sed -i "4i\server_link="$num"" $ccfg
server_link=$num
echo -----------------------------------------------
echo -e "\033[32m设置成功返回上级菜单\033[0m"
clashlink
@@ -265,40 +266,64 @@ fi
if [ ! -n "$modify_yaml" ]; then
modify_yaml=未开启
fi
if [ ! -n "$ipv6_support" ]; then
ipv6_support=未开启
fi
#
echo -----------------------------------------------
echo -e "\033[33m欢迎使用高级模式菜单\033[0m"
echo -e "\033[32m修改配置后请手动重启clash服务\033[0m"
echo -e " 1 切换运行模式: \033[36m$redir_mod\033[0m"
echo -e " 1 切换Clash运行模式: \033[36m$redir_mod\033[0m"
echo -e " 2 切换DNS运行模式 \033[36m$dns_mod\033[0m"
echo -e " 3 跳过本地证书验证: \033[36m$skip_cert\033[0m ————解决节点证书验证错误"
echo -e " 4 只代理常用端口: \033[36m$common_ports\033[0m ————用于屏蔽P2P流量"
echo -e " 5 不修饰config.yaml: \033[36m$modify_yaml\033[0m ————用于使用自定义配置"
echo -e " 6 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性且不兼容Fake_ip"
echo -e " 9 \033[32m重启\033[0mclash服务"
echo -e " 0 返回上级菜单 \033[0m"
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 $redir_mod \033[0m"
echo -e "当前代理模式为:\033[47;30m $redir_mod \033[0mClash核心为\033[47;30m $clashcore \033[0m"
echo -e "\033[33m切换模式后需要手动重启clash服务以生效\033[0m"
echo " 1 Tun模式 支持UDP转发且延迟低"
echo " CPU及内存占用更高"
echo " 适合外服游戏用户"
echo " 2 Redir模式CPU以及内存占用较低"
echo -e "\033[36mTun及混合模式必须使用clashpre核心\033[0m"
echo " 1 Redir模式CPU及内存占用较低"
echo " 但不支持UDP流量转发"
echo " 日常使用推荐此模式"
echo " 2 Tun模式 支持UDP转发且延迟低"
echo " 但CPU及内存占用更高"
echo " 且不支持redir-host"
echo " 3 混合模式: 仅使用Tun转发UPD流量"
echo " CPU和内存占用较高"
echo " 不推荐使用redir-host"
echo " 0 返回上级菜单"
read -p "请输入对应数字 > " num
if [[ $num == 0 ]]; then
if [ -z $num ]; then
echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字\033[0m"
clashadv
elif [[ $num == 0 ]]; then
clashadv
elif [[ $num == 1 ]]; then
redir_mod=Tun模式
elif [[ $num == 2 ]]; then
redir_mod=Redir模式
elif [[ $num == 2 ]]; then
if [ "$clashcore" = "clash" ] || [ "$clashcore" = "clashr" ];then
echo -----------------------------------------------
echo -e "\033[31m当前核心不支持开启Tun模式请先切换clash核心\033[0m"
clashadv
fi
redir_mod=Tun模式
dns_mod=fake-ip
elif [[ $num == 3 ]]; then
if [ "$clashcore" = "clash" ] || [ "$clashcore" = "clashr" ];then
echo -----------------------------------------------
echo -e "\033[31m当前核心不支持开启Tun模式请先切换clash核心\033[0m"
clashadv
fi
redir_mod=混合模式
else
echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字\033[0m"
@@ -306,8 +331,10 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
fi
sed -i '/redir_mod*/'d $ccfg
sed -i "1i\redir_mod=$redir_mod" $ccfg
sed -i '/dns_mod*/'d $ccfg
sed -i "1i\dns_mod=$dns_mod" $ccfg
echo -----------------------------------------------
echo -e "\033[33m已设为 $redir_mod \033[0m"
echo -e "\033[36m已设为 $redir_mod \033[0m"
clashadv
elif [[ $num == 2 ]]; then
@@ -317,15 +344,20 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo " 1 fake-ip模式 响应速度更快"
echo " 但可能和部分软件有冲突"
echo " 2 redir_host模式使用稳定兼容性好"
echo " 响应速度略慢"
echo " 不支持Tun模式"
echo " 0 返回上级菜单"
read -p "请输入对应数字 > " num
if [[ $num == 0 ]]; then
if [ -z $num ]; then
echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字\033[0m"
clashadv
elif [[ $num == 0 ]]; then
clashadv
elif [[ $num == 1 ]]; then
dns_mod='fake-ip'
dns_mod=fake-ip
elif [[ $num == 2 ]]; then
dns_mod='redir_host'
dns_mod=redir_host
redir_mod=Redir模式
else
echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字\033[0m"
@@ -333,8 +365,10 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
fi
sed -i '/dns_mod*/'d $ccfg
sed -i "1i\dns_mod=$dns_mod" $ccfg
sed -i '/redir_mod*/'d $ccfg
sed -i "1i\redir_mod=$redir_mod" $ccfg
echo -----------------------------------------------
echo -e "\033[33m已设为 $dns_mod 模式!!\033[0m"
echo -e "\033[36m已设为 $dns_mod 模式!!\033[0m"
clashadv
elif [[ $num == 3 ]]; then
@@ -384,6 +418,22 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
fi
clashadv
elif [[ $num == 6 ]]; then
sed -i '/ipv6_support*/'d $ccfg
echo -----------------------------------------------
if [ "$ipv6_support" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\ipv6_support=已开启" $ccfg
echo -e "\033[33m已开启对ipv6协议的支持\033[0m"
echo -e "Clash对ipv6的支持并不友好如不能使用请静等修复"
ipv6_support=已开启
else
/etc/init.d/clash enable
sed -i "1i\ipv6_support=未开启" $ccfg
echo -e "\033[32m已禁用对ipv6协议的支持\033[0m"
ipv6_support=未开启
fi
clashadv
elif [[ $num == 9 ]]; then
if [ $status -gt 0 ];then
echo -----------------------------------------------
@@ -531,7 +581,9 @@ echo -e "\033[36m正在施工中敬请期待\033[0m"
elif [[ $num == 8 ]]; then
echo -----------------------------------------------
echo -e "\033[31m这里是测试命令菜单\033[0m"
echo -e "\033[36m这里是测试命令菜单\033[0m"
echo -e "\033[33m如遇问题尽量运行相应命令后截图发群\033[0m"
echo -----------------------------------------------
echo " 1 查看clash运行时的报错信息"
echo " 2 查看系统DNS端口(:53)占用 "
echo " 3 测试ssl加密aes-128-gcm跑分"
@@ -540,7 +592,11 @@ echo -e "\033[36m正在施工中敬请期待\033[0m"
echo " 6 测试代理服务器连通性google.tw)"
echo " 0 返回上级目录!"
read -p "请输入对应数字 > " num
if [[ $num == 0 ]]; then
if [ -z $num ]; then
echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字\033[0m"
clashsh
elif [[ $num == 0 ]]; then
clashsh
elif [[ $num == 1 ]]; then
etc/init.d/clash stop

View File

@@ -19,6 +19,7 @@ EOF
common_ports=未开启
dns_mod=redir-host
modify_yaml=未开启
ipv6_support=未开启
fi
source $ccfg #加载配置文件
#是否代理常用端口
@@ -30,21 +31,25 @@ if [ "$common_ports" = "已开启" ];then
ports='-m multiport --dports 22,53,587,465,995,993,143,80,443 '
fi
}
modifyyaml(){
modify_yaml(){
##########需要变更的配置###########
mix='mixed-port: 7890'
redir='redir-port: 7892'
lan='allow-lan: true'
mode='mode: Rule'
log='log-level: info'
if [ "$ipv6_support" = "已开启" ];then
ipv6='ipv6: true'
else
ipv6='ipv6: false'
fi
external='external-controller: 0.0.0.0:9999'
if [ "$dns_mod" = "fake-ip" ];then
dns='dns: {enable: true, listen: 0.0.0.0:1053, fake-ip-range: 198.18.0.1/16, enhanced-mode: fake-ip, nameserver: [114.114.114.114, 127.0.0.1:53], fallback: [tcp://1.0.0.1, 8.8.4.4]}'
else
dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:1053, enhanced-mode: redir-host, nameserver: [114.114.114.114, 127.0.0.1:53], fallback: [1.0.0.1, 8.8.4.4]}'
fi
if [ "$redir_mod" = "Tun模式" ];then
if [ "$redir_mod" != "Redir模式" ];then
tun='tun: {enable: true, stack: system}'
else
tun='tun: {enable: false}'
@@ -91,28 +96,35 @@ start_redir(){
iptables -t nat -A clash -d 240.0.0.0/4 -j RETURN
iptables -t nat -A clash -p tcp $ports-j REDIRECT --to-ports 7892
iptables -t nat -A PREROUTING -p tcp -j clash
#ip6tables -t nat -A PREROUTING -p tcp $ports-j REDIRECT --to-ports 7892
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
if [ "$ipv6_support" = "已开启" ];then
ip6tables -t nat -N clashv6
ip6tables -t nat -A clashv6 -p tcp $ports-j REDIRECT --to-ports 7892
ip6tables -t nat -A PREROUTING -p tcp -j clashv6
fi
}
stop_redir(){
stop_iptables(){
#重置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
#ip6tables -t nat -A PREROUTING -p tcp $ports-j REDIRECT --to-ports 7892 > /dev/null 2>&1
ip6tables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1
ip6tables -t nat -D PREROUTING -p tcp -j clashv6 > /dev/null 2>&1
ip6tables -t nat -F clashv6 > /dev/null 2>&1
ip6tables -t nat -X clashv6 > /dev/null 2>&1
}
start_tun(){
start_dns(){
#允许tun网卡接受流量
iptables -I FORWARD -o utun -j ACCEPT
#设置dns转发
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}
start_service() {
getconfig
#使用内置规则强行覆盖config配置文件
if [ "$modify_yaml" != "已开启" ];then
modifyyaml
modify_yaml
fi
#创建clash后台进程
procd_open_instance
@@ -122,11 +134,13 @@ start_service() {
procd_set_param command $clashdir/clash -d $clashdir
procd_close_instance
#修改iptables规则使流量进入clash
stop_redir
start_tun
stop_iptables
start_dns
if [ "$redir_mod" != "Tun模式" ];then
start_redir
fi
mark_time
}
stop_service() {
stop_redir
stop_iptables
}

View File

@@ -159,6 +159,7 @@ read -p "请输入第"$i"个链接 > " url
echo -e "\033[31m请输入正确的订阅/分享链接!!!\033[0m"
fi
done
####
echo -----------------------------------------------
echo 输入太多啦,可能会导致订阅失败!
echo "多个较短的链接请尽量用“|”分隔以一次性输入!"
@@ -218,7 +219,7 @@ getsh(){
echo -----------------------------------------------
echo -e "\033[33m正在检查更新\033[0m"
result=$(curl -w %{http_code} -skLo /tmp/clashversion $update_url/bin/version)
[ "$result" != "200" ] && echo "无法连接到服务器" && exit 1
[ "$result" != "200" ] && echo "检查更新失败" && exit 1
source /tmp/clashversion
echo -----------------------------------------------
echo -e "当前脚本版本为:\033[33m $versionsh_l \033[0m"
@@ -262,17 +263,13 @@ source $ccfg
#获取核心及版本信息
if [ ! -f $clashdir/clash ]; then
clashcore=没有安装核心!
version=''
else
if [ -n $clashcore ]; then
clashcore=clashpre
version=1.0.0
fi
clashv=''
fi
cpucore=armv7
clashcore_n=$clashcore
echo -----------------------------------------------
echo -e "当前clash核心\033[47;30m $clashcore \033[46;30m$version\033[0m"
echo -e "当前clash核心\033[47;30m $clashcore \033[46;30m$clashv\033[0m"
echo -e "\033[32m请选择需要下载的核心版本\033[0m"
echo
echo "1 clash 运行稳定,内存占用小"
@@ -286,7 +283,11 @@ echo "(高级预览版) 内存占用高不支持chacha20加密"
echo
echo 0 返回上级菜单
read -p "请输入对应数字 > " num
if [[ $num == 0 ]]; then
if [ -z $num ]; then
echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字\033[0m"
update
elif [[ $num == 0 ]]; then
update
elif [[ $num == 1 ]]; then
clashcore=clash
@@ -295,12 +296,25 @@ read -p "请输入对应数字 > " num
elif [[ $num == 3 ]]; then
clashcore=clashpre
else
echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字\033[0m"
update
exit;
fi
#生成链接
corelink="$update_url/bin/$clashcore/clash-linux-$cpucore"
versionlink="$update_url/bin/$clashcore/version"
#检测版本
echo -----------------------------------------------
echo -e "\033[33m正在检查更新\033[0m"
result=$(curl -w %{http_code} -skLo /tmp/clashversion $versionlink)
[ "$result" != "200" ] && echo "检查更新失败!" && exit 1
source /tmp/clashversion
echo -----------------------------------------------
echo -e "当前clash核心\033[0m $clashcore_n \033[33m$clashv\033[0m"
echo -e "最新clash核心\033[32m $clashcore \033[36m$version\033[0m"
echo -----------------------------------------------
read -p "是否更新?[1/0] > " res
if [ "$res" = '1' ]; then
echo -----------------------------------------------
echo 正在连接服务器获取clash核心文件…………链接地址为
echo -e "\033[4;32m$corelink\033[0m"
@@ -321,15 +335,18 @@ result=$(curl -w %{http_code} -kLo /tmp/clash.new $corelink)
echo -e "\033[32m$clashcore核心下载成功,正在替换!\033[0m"
mv /tmp/clash.new $clashdir/clash
chmod 777 $clashdir/clash #授予权限
sed -i '/clashcore*/'d $ccfg
sed -i '/clashcore=*/'d $ccfg
sed -i "1i\clashcore=$clashcore" $ccfg
#sed -i '/version*/'d $ccfg
#sed -i "1i\version=$version" $ccfg
sed -i '/clashv=*/'d $ccfg
sed -i "1i\clashv=$version" $ccfg
rm -rf /tmp/clashversion
echo -----------------------------------------------
echo -e "\033[32m$clashcore核心替换成功请手动启动clash服务\033[0m"
clashsh
fi
else
getcore
fi
}
getgeo(){
echo -----------------------------------------------
@@ -376,8 +393,21 @@ echo -e "\033[32m打开管理面板的速度更快且更稳定"
echo -e "\033[33m需要占用约500kb的本地空间(目录:/www/clash)\033[0m"
echo -e "\033[36m可以使用\033[32;4mhttp://$host/clash\033[0;36m访问面板\033[0m"
echo -----------------------------------------------
read -p "是否安装/更新安装本地面板?[1/0] > " res
read -p "是否安装本地面板?[1/0] > " res
if [ "$res" = '1' ]; then
if [ -d /www/clash ];then
echo -----------------------------------------------
echo -e "\033[31m检测到您已经安装过本地面板了\033[0m"
echo -----------------------------------------------
read -p "是否覆盖安装?[1/0] > " res
if [ -z "$res" ]; then
update
elif [ "$res" = 1 ]; then
rm -rf /www/clash
else
update
fi
fi
dblink="$update_url/bin/clashdb.tar.gz"
echo -----------------------------------------------
echo 正在连接服务器获取安装文件…………
@@ -401,4 +431,3 @@ read -p "是否安装/更新安装本地面板?[1/0] > " res
fi
update
}