2020-09-18 21:09:06 +08:00
|
|
|
|
#!/bin/sh
|
2020-08-22 20:08:23 +08:00
|
|
|
|
# Copyright (C) Juewuy
|
|
|
|
|
|
2020-10-30 16:21:09 +08:00
|
|
|
|
#脚本内部工具
|
2020-08-22 20:08:23 +08:00
|
|
|
|
getconfig(){
|
2020-10-23 19:08:35 +08:00
|
|
|
|
#加载配置文件
|
2021-06-05 19:17:26 +08:00
|
|
|
|
[ -d "/etc/storage/clash" ] && clashdir=/etc/storage/clash
|
|
|
|
|
[ -d "/jffs/clash" ] && clashdir=/jffs/clash
|
2020-12-08 23:21:50 +08:00
|
|
|
|
[ -z "$clashdir" ] && clashdir=$(cat /etc/profile | grep clashdir | awk -F "\"" '{print $2}')
|
|
|
|
|
[ -z "$clashdir" ] && clashdir=$(cat ~/.bashrc | grep clashdir | awk -F "\"" '{print $2}')
|
2020-10-23 19:08:35 +08:00
|
|
|
|
ccfg=$clashdir/mark
|
|
|
|
|
[ -f $ccfg ] && source $ccfg
|
|
|
|
|
#默认设置
|
2020-10-30 16:21:09 +08:00
|
|
|
|
[ -z "$bindir" ] && bindir=$clashdir
|
2020-10-27 09:40:58 +08:00
|
|
|
|
[ -z "$redir_mod" ] && [ "$USER" = "root" -o "$USER" = "admin" ] && redir_mod=Redir模式
|
2020-12-08 23:21:50 +08:00
|
|
|
|
[ -z "$redir_mod" ] && redir_mod=Redir模式
|
2020-10-23 19:08:35 +08:00
|
|
|
|
[ -z "$skip_cert" ] && skip_cert=已开启
|
|
|
|
|
[ -z "$common_ports" ] && common_ports=已开启
|
|
|
|
|
[ -z "$dns_mod" ] && dns_mod=redir_host
|
|
|
|
|
[ -z "$dns_over" ] && dns_over=已开启
|
|
|
|
|
[ -z "$modify_yaml" ] && modify_yaml=未开启
|
|
|
|
|
[ -z "$ipv6_support" ] && ipv6_support=未开启
|
|
|
|
|
[ -z "$start_old" ] && start_old=未开启
|
|
|
|
|
[ -z "$local_proxy" ] && local_proxy=未开启
|
|
|
|
|
[ -z "$mix_port" ] && mix_port=7890
|
|
|
|
|
[ -z "$redir_port" ] && redir_port=7892
|
|
|
|
|
[ -z "$db_port" ] && db_port=9999
|
|
|
|
|
[ -z "$dns_port" ] && dns_port=1053
|
2021-06-13 19:12:57 +08:00
|
|
|
|
[ -z "$cn_ip_route" ] && cn_ip_route=未开启
|
2020-10-23 19:08:35 +08:00
|
|
|
|
[ -z "$dns_nameserver" ] && dns_nameserver='114.114.114.114, 223.5.5.5'
|
|
|
|
|
[ -z "$dns_fallback" ] && dns_fallback='1.0.0.1, 8.8.4.4'
|
2021-04-09 14:34:01 +08:00
|
|
|
|
[ -z "$multiport" ] && multiport='22,53,587,465,995,993,143,80,443,8080'
|
2020-10-23 19:08:35 +08:00
|
|
|
|
#是否代理常用端口
|
2020-12-08 20:37:49 +08:00
|
|
|
|
[ "$common_ports" = "已开启" ] && ports="-m multiport --dports $multiport"
|
2020-10-23 19:08:35 +08:00
|
|
|
|
}
|
2020-10-30 16:21:09 +08:00
|
|
|
|
setconfig(){
|
|
|
|
|
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
|
|
|
|
[ -z "$3" ] && configpath=$clashdir/mark || configpath=$3
|
2020-12-14 16:38:14 +08:00
|
|
|
|
[ -n "$(grep ${1} $configpath)" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath
|
2020-10-30 16:21:09 +08:00
|
|
|
|
}
|
2020-11-07 12:08:31 +08:00
|
|
|
|
compare(){
|
2020-12-13 16:40:19 +08:00
|
|
|
|
if [ ! -f $1 -o ! -f $2 ];then
|
|
|
|
|
return 1
|
|
|
|
|
elif command -v cmp >/dev/null 2>&1;then
|
2020-11-07 12:08:31 +08:00
|
|
|
|
cmp -s $1 $2
|
|
|
|
|
else
|
|
|
|
|
[ "$(cat $1)" = "$(cat $2)" ] && return 0 || return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
2020-10-30 16:21:09 +08:00
|
|
|
|
webget(){
|
2020-12-14 16:38:14 +08:00
|
|
|
|
[ -n "$(pidof clash)" ] && export all_proxy="http://$authentication@127.0.0.1:$mix_port" #设置临时http代理
|
2020-10-30 16:21:09 +08:00
|
|
|
|
#参数【$1】代表下载目录,【$2】代表在线地址
|
|
|
|
|
#参数【$3】代表输出显示,【$4】不启用重定向
|
2021-06-06 14:47:18 +08:00
|
|
|
|
#参数【$5】代表验证证书,【$6】使用clash文件头
|
2020-10-30 16:21:09 +08:00
|
|
|
|
if curl --version > /dev/null 2>&1;then
|
|
|
|
|
[ "$3" = "echooff" ] && progress='-s' || progress='-#'
|
2020-12-14 16:38:14 +08:00
|
|
|
|
[ "$4" = "rediroff" ] && redirect='' || redirect='-L'
|
|
|
|
|
[ "$5" = "skipceroff" ] && certificate='' || certificate='-k'
|
2021-06-06 14:47:18 +08:00
|
|
|
|
[ -n "$6" ] && agent='-A "clash"'
|
|
|
|
|
result=$(curl $agent -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o $1 $2)
|
2020-12-14 16:38:14 +08:00
|
|
|
|
[ "$result" != "200" ] && export all_proxy="" && result=$(curl -w %{http_code} --connect-timeout 3 $progress $redirect $certificate -o $1 $2)
|
2020-10-30 16:21:09 +08:00
|
|
|
|
else
|
|
|
|
|
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
|
|
|
|
|
[ "$3" = "echoon" ] && progress=''
|
2020-12-14 16:38:14 +08:00
|
|
|
|
[ "$4" = "rediroff" ] && redirect='--max-redirect=0' || redirect=''
|
|
|
|
|
[ "$5" = "skipceroff" ] && certificate='' || certificate='--no-check-certificate'
|
2021-06-06 14:47:18 +08:00
|
|
|
|
[ -n "$6" ] && agent='--user-agent="clash"'
|
|
|
|
|
wget -Y on $agent $progress $redirect $certificate --timeout=3 -O $1 $2
|
2020-12-14 16:38:14 +08:00
|
|
|
|
if [ "$?" != "0" ];then
|
2021-06-06 14:47:18 +08:00
|
|
|
|
wget $agent $progress $redirect $certificate --timeout=3 -O $1 $2
|
2020-12-14 16:38:14 +08:00
|
|
|
|
[ "$?" = "0" ] && result="200"
|
|
|
|
|
else
|
|
|
|
|
result="200"
|
|
|
|
|
fi
|
2020-10-30 16:21:09 +08:00
|
|
|
|
fi
|
2020-12-11 22:17:29 +08:00
|
|
|
|
export all_proxy=""
|
2020-10-30 16:21:09 +08:00
|
|
|
|
}
|
2020-10-24 09:54:14 +08:00
|
|
|
|
logger(){
|
2020-10-30 16:21:09 +08:00
|
|
|
|
[ -n "$2" ] && echo -e "\033[$2m$1\033[0m"
|
2020-10-24 09:54:14 +08:00
|
|
|
|
echo `date "+%G-%m-%d %H:%M:%S"` $1 >> $clashdir/log
|
2020-10-27 16:36:01 +08:00
|
|
|
|
[ "$(wc -l $clashdir/log | awk '{print $1}')" -gt 30 ] && sed -i '1,5d' $clashdir/log
|
2020-10-24 09:54:14 +08:00
|
|
|
|
}
|
2020-10-27 09:40:58 +08:00
|
|
|
|
cronset(){
|
|
|
|
|
# 参数1代表要移除的关键字,参数2代表要添加的任务语句
|
2020-10-28 13:49:45 +08:00
|
|
|
|
crondir=/tmp/cron_$USER
|
2021-06-12 13:16:54 +08:00
|
|
|
|
crontab -l > $crondir 2>/dev/null
|
2020-10-28 13:49:45 +08:00
|
|
|
|
sed -i "/$1/d" $crondir
|
2021-04-09 14:34:01 +08:00
|
|
|
|
sed -i '/^$/d' $crondir
|
2020-10-28 13:49:45 +08:00
|
|
|
|
echo "$2" >> $crondir
|
|
|
|
|
crontab $crondir
|
|
|
|
|
rm -f $crondir
|
2020-10-27 09:40:58 +08:00
|
|
|
|
}
|
2020-10-28 11:09:26 +08:00
|
|
|
|
mark_time(){
|
|
|
|
|
start_time=`date +%s`
|
|
|
|
|
sed -i '/start_time*/'d $clashdir/mark
|
|
|
|
|
echo start_time=$start_time >> $clashdir/mark
|
|
|
|
|
}
|
2021-01-05 19:38:48 +08:00
|
|
|
|
gethost(){
|
2021-03-19 17:55:20 +08:00
|
|
|
|
[ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
|
2021-03-13 19:28:32 +08:00
|
|
|
|
[ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E '\ 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1)
|
|
|
|
|
[ -n "$host" ] && lanhost="-s $(echo $host | grep -oE '^1(92|0|72)\.')0.0.0/8"
|
2021-01-05 19:38:48 +08:00
|
|
|
|
}
|
2020-10-28 11:09:26 +08:00
|
|
|
|
#配置文件相关
|
2020-09-18 21:09:06 +08:00
|
|
|
|
getyaml(){
|
2020-10-27 09:40:58 +08:00
|
|
|
|
[ -z "$rule_link" ] && rule_link=1
|
|
|
|
|
[ -z "$server_link" ] && server_link=1
|
2020-10-23 19:08:35 +08:00
|
|
|
|
#前后端订阅服务器地址索引,可在此处添加!
|
|
|
|
|
Server=`sed -n ""$server_link"p"<<EOF
|
2020-10-24 09:54:14 +08:00
|
|
|
|
subcon.dlj.tf
|
|
|
|
|
api.dler.io
|
|
|
|
|
api.wcc.best
|
2021-04-19 12:10:09 +08:00
|
|
|
|
api2.tsutsu.cc
|
|
|
|
|
api.v1.mk
|
2020-10-24 09:54:14 +08:00
|
|
|
|
EOF`
|
2020-10-23 19:08:35 +08:00
|
|
|
|
Config=`sed -n ""$rule_link"p"<<EOF
|
2020-10-24 09:54:14 +08:00
|
|
|
|
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_NoReject.ini
|
|
|
|
|
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiMode.ini
|
|
|
|
|
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_AdblockPlus.ini
|
|
|
|
|
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_AdblockPlus.ini
|
|
|
|
|
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_Netflix.ini
|
|
|
|
|
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_AdblockPlus.ini
|
|
|
|
|
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_clash.ini
|
|
|
|
|
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_dler.ini
|
|
|
|
|
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/connershua_pro.ini
|
|
|
|
|
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/connershua_backtocn.ini
|
|
|
|
|
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/dlercloud_lige_platinum.ini
|
|
|
|
|
https://subconverter.oss-ap-southeast-1.aliyuncs.com/Rules/RemoteConfig/special/basic.ini
|
|
|
|
|
https://subconverter.oss-ap-southeast-1.aliyuncs.com/Rules/RemoteConfig/special/netease.ini
|
2021-02-08 16:01:22 +08:00
|
|
|
|
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_Google.ini
|
2021-04-19 12:10:09 +08:00
|
|
|
|
https://github.com/juewuy/ShellClash/raw/master/rules/ACL4SSR_Online_Games.ini
|
|
|
|
|
https://github.com/juewuy/ShellClash/raw/master/rules/ACL4SSR_Online_Mini_Games.ini
|
|
|
|
|
https://github.com/juewuy/ShellClash/raw/master/rules/ACL4SSR_Online_Full_Games.ini
|
2020-10-24 09:54:14 +08:00
|
|
|
|
EOF`
|
2020-10-23 19:08:35 +08:00
|
|
|
|
#如果传来的是Url链接则合成Https链接,否则直接使用Https链接
|
|
|
|
|
if [ -z "$Https" ];then
|
2021-06-06 14:47:18 +08:00
|
|
|
|
[ -n "$(echo $Url | grep -o 'https://dler')" ] && Server='api.dler.io'
|
2020-10-23 19:08:35 +08:00
|
|
|
|
Https="https://$Server/sub?target=clash&insert=true&new_name=true&scv=true&exclude=$exclude&include=$include&url=$Url&config=$Config"
|
|
|
|
|
markhttp=1
|
|
|
|
|
fi
|
2020-10-24 09:54:14 +08:00
|
|
|
|
#输出
|
2020-10-27 16:36:01 +08:00
|
|
|
|
echo -----------------------------------------------
|
2020-10-23 19:08:35 +08:00
|
|
|
|
echo 正在连接服务器获取配置文件…………链接地址为:
|
|
|
|
|
echo -e "\033[4;32m$Https\033[0m"
|
|
|
|
|
echo 可以手动复制该链接到浏览器打开并查看数据是否正常!
|
|
|
|
|
#获取在线yaml文件
|
|
|
|
|
yaml=$clashdir/config.yaml
|
2020-10-28 13:49:45 +08:00
|
|
|
|
yamlnew=/tmp/clash_config_$USER.yaml
|
2020-10-24 09:54:14 +08:00
|
|
|
|
rm -rf $yamlnew
|
2021-06-06 14:47:18 +08:00
|
|
|
|
webget $yamlnew $Https 0 0 0 1
|
2020-10-23 19:08:35 +08:00
|
|
|
|
if [ "$result" != "200" ];then
|
|
|
|
|
if [ -z "$markhttp" ];then
|
2020-10-24 09:54:14 +08:00
|
|
|
|
echo -----------------------------------------------
|
2020-10-30 16:21:09 +08:00
|
|
|
|
logger "配置文件获取失败!" 31
|
2021-05-31 16:03:30 +08:00
|
|
|
|
echo -e "\033[31m请尝试使用【在线生成配置文件】功能!\033[0m"
|
2020-10-24 09:54:14 +08:00
|
|
|
|
echo -----------------------------------------------
|
2020-10-10 17:02:53 +08:00
|
|
|
|
exit 1
|
|
|
|
|
else
|
2020-10-23 19:08:35 +08:00
|
|
|
|
if [ "$retry" -ge 5 ];then
|
2020-10-30 16:21:09 +08:00
|
|
|
|
logger "无法获取配置文件,请检查链接格式以及网络连接状态!" 31
|
2020-10-23 19:08:35 +08:00
|
|
|
|
exit 1
|
|
|
|
|
else
|
|
|
|
|
retry=$((retry+1))
|
2020-10-30 16:21:09 +08:00
|
|
|
|
logger "配置文件获取失败!" 31
|
2020-10-23 19:08:35 +08:00
|
|
|
|
echo -e "\033[32m尝试使用其他服务器获取配置!\033[0m"
|
2020-10-30 16:21:09 +08:00
|
|
|
|
logger "正在重试第$retry次/共5次!" 32
|
2020-10-23 19:08:35 +08:00
|
|
|
|
sed -i '/server_link=*/'d $ccfg
|
|
|
|
|
if [ "$server_link" -ge 5 ]; then
|
|
|
|
|
server_link=0
|
|
|
|
|
fi
|
|
|
|
|
server_link=$((server_link+1))
|
2020-10-27 09:40:58 +08:00
|
|
|
|
echo server_link=$server_link >> $ccfg
|
2020-10-23 19:08:35 +08:00
|
|
|
|
Https=""
|
|
|
|
|
getyaml
|
2020-09-18 21:09:06 +08:00
|
|
|
|
fi
|
|
|
|
|
fi
|
2020-10-23 19:08:35 +08:00
|
|
|
|
else
|
|
|
|
|
Https=""
|
2020-11-15 13:01:29 +08:00
|
|
|
|
#检测节点或providers
|
2021-05-29 16:50:55 +08:00
|
|
|
|
if [ -z "$(cat $yamlnew | grep -E 'server|proxy-providers' | grep -v 'nameserver' | head -n 1)" ];then
|
2020-10-27 16:36:01 +08:00
|
|
|
|
echo -----------------------------------------------
|
2020-10-30 16:21:09 +08:00
|
|
|
|
logger "获取到了配置文件,但似乎并不包含正确的节点信息!" 31
|
2020-10-23 19:08:35 +08:00
|
|
|
|
echo -----------------------------------------------
|
|
|
|
|
sed -n '1,30p' $yamlnew
|
|
|
|
|
echo -----------------------------------------------
|
|
|
|
|
echo -e "\033[33m请检查如上配置文件信息:\033[0m"
|
2020-10-27 16:36:01 +08:00
|
|
|
|
echo -----------------------------------------------
|
2020-10-23 19:08:35 +08:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
#检测旧格式
|
|
|
|
|
if cat $yamlnew | grep 'Proxy Group:' >/dev/null;then
|
2020-10-27 16:36:01 +08:00
|
|
|
|
echo -----------------------------------------------
|
2020-10-30 16:21:09 +08:00
|
|
|
|
logger "已经停止对旧格式配置文件的支持!!!" 31
|
2020-10-23 19:08:35 +08:00
|
|
|
|
echo -e "请使用新格式或者使用【导入节点/链接】功能!"
|
2020-10-27 16:36:01 +08:00
|
|
|
|
echo -----------------------------------------------
|
2020-10-23 19:08:35 +08:00
|
|
|
|
exit 1
|
2020-10-01 18:45:26 +08:00
|
|
|
|
fi
|
2020-10-23 19:08:35 +08:00
|
|
|
|
#检测不支持的加密协议
|
|
|
|
|
if cat $yamlnew | grep 'cipher: chacha20,' >/dev/null;then
|
2020-10-27 16:36:01 +08:00
|
|
|
|
echo -----------------------------------------------
|
2020-12-11 22:17:29 +08:00
|
|
|
|
logger "已停止支持chacha20加密,请更换更安全的节点加密协议!" 31
|
2020-10-27 16:36:01 +08:00
|
|
|
|
echo -----------------------------------------------
|
2020-10-23 19:08:35 +08:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2020-12-18 12:58:41 +08:00
|
|
|
|
#检测是否存在高级版规则
|
|
|
|
|
if [ "$clashcore" = "clash" -a -n "$(cat $yamlnew | grep -E '^script:|proxy-providers|rule-providers')" ];then
|
|
|
|
|
echo -----------------------------------------------
|
|
|
|
|
logger "检测到高级版核心专属规则!将改为使用premium核心启动!" 33
|
|
|
|
|
rm -rf $bindir/clash
|
|
|
|
|
setconfig clashcore clashpre
|
|
|
|
|
echo -----------------------------------------------
|
|
|
|
|
fi
|
2020-12-11 22:17:29 +08:00
|
|
|
|
#使用核心内置test功能检测
|
|
|
|
|
if [ -x $bindir/clash ];then
|
|
|
|
|
$bindir/clash -t -d $bindir -f $yamlnew >/dev/null
|
|
|
|
|
if [ "$?" != "0" ];then
|
|
|
|
|
logger "配置文件加载失败!请查看报错信息!" 31
|
|
|
|
|
$bindir/clash -t -d $bindir -f $yamlnew
|
|
|
|
|
echo "$($bindir/clash -t -d $bindir -f $yamlnew)" >> $clashdir/log
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2020-10-27 16:36:01 +08:00
|
|
|
|
#如果不同则备份并替换文件
|
|
|
|
|
if [ -f $yaml ];then
|
2020-11-07 12:08:31 +08:00
|
|
|
|
compare $yamlnew $yaml
|
2020-12-11 22:17:29 +08:00
|
|
|
|
[ "$?" = 0 ] || mv -f $yaml $yaml.bak && mv -f $yamlnew $yaml
|
2020-10-27 16:36:01 +08:00
|
|
|
|
else
|
|
|
|
|
mv -f $yamlnew $yaml
|
|
|
|
|
fi
|
2020-12-11 22:17:29 +08:00
|
|
|
|
echo -e "\033[32m已成功获取配置文件!\033[0m"
|
|
|
|
|
rm -rf $yamlnew
|
|
|
|
|
exit 0
|
2020-09-18 21:09:06 +08:00
|
|
|
|
fi
|
|
|
|
|
}
|
2020-08-22 20:08:23 +08:00
|
|
|
|
modify_yaml(){
|
|
|
|
|
##########需要变更的配置###########
|
2020-10-23 19:08:35 +08:00
|
|
|
|
lan='allow-lan: true'
|
|
|
|
|
mode='mode: Rule'
|
|
|
|
|
log='log-level: info'
|
|
|
|
|
[ "$ipv6_support" = "已开启" ] && ipv6='ipv6: true' || ipv6='ipv6: false'
|
|
|
|
|
external="external-controller: 0.0.0.0:$db_port"
|
|
|
|
|
[ -d $clashdir/ui ] && db_ui=ui
|
|
|
|
|
[ "$redir_mod" != "Redir模式" ] && tun='tun: {enable: true, stack: system}' || tun='tun: {enable: false}'
|
|
|
|
|
exper='experimental: {ignore-resolve-fail: true, interface-name: en0}'
|
|
|
|
|
#dns配置
|
|
|
|
|
if [ "$dns_mod" = "fake-ip" ];then
|
2021-06-12 13:16:54 +08:00
|
|
|
|
dns='dns: {enable: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, fake-ip-range: 198.18.0.1/16, enhanced-mode: fake-ip, fake-ip-filter: ["*.lan", "time.windows.com", "time.nist.gov", "time.apple.com", "time.asia.apple.com", "*.ntp.org.cn", "*.openwrt.pool.ntp.org", "time1.cloud.tencent.com", "time.ustc.edu.cn", "pool.ntp.org", "ntp.ubuntu.com", "ntp.aliyun.com", "ntp1.aliyun.com", "ntp2.aliyun.com", "ntp3.aliyun.com", "ntp4.aliyun.com", "ntp5.aliyun.com", "ntp6.aliyun.com", "ntp7.aliyun.com", "time1.aliyun.com", "time2.aliyun.com", "time3.aliyun.com", "time4.aliyun.com", "time5.aliyun.com", "time6.aliyun.com", "time7.aliyun.com", "*.time.edu.cn", "time1.apple.com", "time2.apple.com", "time3.apple.com", "time4.apple.com", "time5.apple.com", "time6.apple.com", "time7.apple.com", "time1.google.com", "time2.google.com", "time3.google.com", "time4.google.com", "music.163.com", "*.music.163.com", "*.126.net", "musicapi.taihe.com", "music.taihe.com", "songsearch.kugou.com", "trackercdn.kugou.com", "*.kuwo.cn", "api-jooxtt.sanook.com", "api.joox.com", "joox.com", "y.qq.com", "*.y.qq.com", "streamoc.music.tc.qq.com", "mobileoc.music.tc.qq.com", "isure.stream.qqmusic.qq.com", "dl.stream.qqmusic.qq.com", "aqqmusic.tc.qq.com", "amobile.music.tc.qq.com", "*.xiami.com", "*.music.migu.cn", "music.migu.cn", "*.msftconnecttest.com", "*.msftncsi.com", "localhost.ptlogin2.qq.com", "*.*.*.srv.nintendo.net", "*.*.stun.playstation.net", "xbox.*.*.microsoft.com", "*.*.xboxlive.com", "proxy.golang.org","*.sgcc.com.cn","*.alicdn.com","*.aliyuncs.com"], nameserver: ['$dns_nameserver', 127.0.0.1:53], fallback: ['$dns_fallback'], fallback-filter: {geoip: true}}'
|
2020-10-23 19:08:35 +08:00
|
|
|
|
else
|
|
|
|
|
dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, enhanced-mode: redir-host, nameserver: ['$dns_nameserver$dns_local'], fallback: ['$dns_fallback'], fallback-filter: {geoip: true}}'
|
|
|
|
|
fi
|
2020-10-30 16:21:09 +08:00
|
|
|
|
#设置目录
|
2020-10-06 17:56:17 +08:00
|
|
|
|
yaml=$clashdir/config.yaml
|
2020-10-30 16:21:09 +08:00
|
|
|
|
tmpdir=/tmp/clash_$USER
|
2020-08-22 20:08:23 +08:00
|
|
|
|
#预删除需要添加的项目
|
2020-10-21 10:53:20 +08:00
|
|
|
|
a=$(grep -n "port:" $yaml | head -1 | cut -d ":" -f 1)
|
|
|
|
|
b=$(grep -n "^prox" $yaml | head -1 | cut -d ":" -f 1)
|
|
|
|
|
b=$((b-1))
|
2020-10-30 16:21:09 +08:00
|
|
|
|
mkdir -p $tmpdir > /dev/null
|
2021-03-26 15:29:30 +08:00
|
|
|
|
[ "$b" != "0" ] && sed "${a},${b}d" $yaml > $tmpdir/proxy.yaml
|
2020-08-22 20:08:23 +08:00
|
|
|
|
#跳过本地tls证书验证
|
2021-05-29 16:50:55 +08:00
|
|
|
|
[ "$skip_cert" = "已开启" ] && sed -i '1,99s/skip-cert-verify: false/skip-cert-verify: true/' $tmpdir/proxy.yaml
|
2021-04-19 12:10:09 +08:00
|
|
|
|
#检测是否使用script规则
|
|
|
|
|
[ -n "$(cat $yaml | grep -E '^script:')" ] && mode='mode: Script'
|
2020-10-27 09:40:58 +08:00
|
|
|
|
#添加配置
|
2020-11-05 20:53:05 +08:00
|
|
|
|
###################################
|
2020-10-30 16:21:09 +08:00
|
|
|
|
cat > $tmpdir/set.yaml <<EOF
|
2020-10-27 09:40:58 +08:00
|
|
|
|
mixed-port: $mix_port
|
|
|
|
|
redir-port: $redir_port
|
|
|
|
|
authentication: ["$authentication"]
|
|
|
|
|
$lan
|
|
|
|
|
$mode
|
|
|
|
|
$log
|
|
|
|
|
$ipv6
|
|
|
|
|
external-controller: :$db_port
|
|
|
|
|
external-ui: $db_ui
|
|
|
|
|
secret: $secret
|
|
|
|
|
$tun
|
|
|
|
|
$exper
|
|
|
|
|
$dns
|
2021-03-19 21:30:53 +08:00
|
|
|
|
store-selected: false
|
2020-10-27 09:40:58 +08:00
|
|
|
|
EOF
|
2020-11-05 20:53:05 +08:00
|
|
|
|
###################################
|
2020-11-03 16:41:41 +08:00
|
|
|
|
[ -f $clashdir/user.yaml ] && yaml_user=$clashdir/user.yaml
|
2020-11-05 14:54:52 +08:00
|
|
|
|
#合并文件
|
2020-11-05 22:14:14 +08:00
|
|
|
|
cut -c 1- $tmpdir/set.yaml $yaml_user $tmpdir/proxy.yaml > $tmpdir/config.yaml
|
2020-11-05 14:54:52 +08:00
|
|
|
|
#插入自定义规则
|
2021-03-13 18:06:38 +08:00
|
|
|
|
sed -i "/#自定义规则/d" $tmpdir/config.yaml
|
2020-11-05 14:54:52 +08:00
|
|
|
|
if [ -f $clashdir/rules.yaml ];then
|
|
|
|
|
while read line;do
|
2021-03-13 18:06:38 +08:00
|
|
|
|
[ -z "$(echo "$line " | grep '#')" ] && \
|
2020-11-07 12:08:31 +08:00
|
|
|
|
[ -n "$(echo "$line" | grep '\-\ ')" ] && \
|
2021-02-18 19:00:31 +08:00
|
|
|
|
line=$(echo "$line" | sed 's#/#\\/#') && \
|
2021-03-13 18:06:38 +08:00
|
|
|
|
sed -i "/^rules:/a\ $line #自定义规则" $tmpdir/config.yaml
|
2020-11-05 14:54:52 +08:00
|
|
|
|
done < $clashdir/rules.yaml
|
|
|
|
|
fi
|
|
|
|
|
#如果没有使用小闪存模式
|
|
|
|
|
if [ "$tmpdir" != "$bindir" ];then
|
2020-11-07 12:08:31 +08:00
|
|
|
|
compare $tmpdir/config.yaml $yaml
|
2020-10-30 16:21:09 +08:00
|
|
|
|
[ "$?" != 0 ] && mv -f $tmpdir/config.yaml $yaml || rm -f $tmpdir/config.yaml
|
|
|
|
|
fi
|
|
|
|
|
rm -f $tmpdir/set.yaml
|
2020-11-03 16:50:10 +08:00
|
|
|
|
rm -f $tmpdir/proxy.yaml
|
2020-08-22 20:08:23 +08:00
|
|
|
|
}
|
2020-10-28 11:09:26 +08:00
|
|
|
|
#设置路由规则
|
2021-06-13 19:12:57 +08:00
|
|
|
|
cn_ip_route(){
|
2021-06-13 19:32:43 +08:00
|
|
|
|
if [ ! -f $bindir/cn_ip.txt ];then
|
|
|
|
|
if [ -f $clashdir/cn_ip.txt ];then
|
|
|
|
|
mv $clashdir/cn_ip.txt $bindir/cn_ip.txt
|
|
|
|
|
else
|
|
|
|
|
logger "未找到cn_ip列表,正在下载!" 33
|
|
|
|
|
webget $bindir/cn_ip.txt "$update_url/bin/china_ip_list.txt"
|
|
|
|
|
[ "$result" != 200 ] && rm -rf $bindir/cn_ip.txt && logger "列表下载失败,已退出!" 31 && exit 1
|
|
|
|
|
fi
|
2021-06-13 19:12:57 +08:00
|
|
|
|
fi
|
2021-06-13 19:32:43 +08:00
|
|
|
|
if [ -f $bindir/cn_ip.txt ];then
|
2021-06-13 19:12:57 +08:00
|
|
|
|
echo "create cn_ip hash:net family inet hashsize 1024 maxelem 65536" > /tmp/cn_$USER.ipset
|
2021-06-13 19:32:43 +08:00
|
|
|
|
awk '!/^$/&&!/^#/{printf("add cn_ip %s'" "'\n",$0)}' $bindir/cn_ip.txt >> /tmp/cn_$USER.ipset
|
2021-06-13 19:42:06 +08:00
|
|
|
|
ipset -! flush cn_ip 2>/dev/null
|
|
|
|
|
ipset -! restore < /tmp/cn_$USER.ipset
|
2021-06-13 19:12:57 +08:00
|
|
|
|
rm -rf cn_$USER.ipset
|
|
|
|
|
fi
|
|
|
|
|
}
|
2020-08-22 20:08:23 +08:00
|
|
|
|
start_redir(){
|
2021-01-05 19:38:48 +08:00
|
|
|
|
#获取本地局域网地址段
|
|
|
|
|
gethost
|
2020-09-19 16:32:50 +08:00
|
|
|
|
#流量过滤规则
|
2020-08-22 20:08:23 +08:00
|
|
|
|
iptables -t nat -N clash
|
2020-09-12 16:42:57 +08:00
|
|
|
|
iptables -t nat -A clash -d 0.0.0.0/8 -j RETURN
|
2020-08-22 20:08:23 +08:00
|
|
|
|
iptables -t nat -A clash -d 10.0.0.0/8 -j RETURN
|
|
|
|
|
iptables -t nat -A clash -d 127.0.0.0/8 -j RETURN
|
|
|
|
|
iptables -t nat -A clash -d 169.254.0.0/16 -j RETURN
|
|
|
|
|
iptables -t nat -A clash -d 172.16.0.0/12 -j RETURN
|
|
|
|
|
iptables -t nat -A clash -d 192.168.0.0/16 -j RETURN
|
|
|
|
|
iptables -t nat -A clash -d 224.0.0.0/4 -j RETURN
|
|
|
|
|
iptables -t nat -A clash -d 240.0.0.0/4 -j RETURN
|
2021-06-13 19:42:06 +08:00
|
|
|
|
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && iptables -t nat -A clash -m set --match-set cn_ip dst -j RETURN >/dev/null 2>&1 #绕过大陆IP
|
2020-11-03 23:10:57 +08:00
|
|
|
|
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
|
|
|
|
|
#mac白名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
2020-11-05 14:54:52 +08:00
|
|
|
|
iptables -t nat -A clash -p tcp $ports -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port
|
2020-11-03 23:10:57 +08:00
|
|
|
|
done
|
|
|
|
|
else
|
|
|
|
|
#mac黑名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
|
|
|
|
iptables -t nat -A clash -m mac --mac-source $mac -j RETURN
|
|
|
|
|
done
|
2020-11-05 14:54:52 +08:00
|
|
|
|
iptables -t nat -A clash -p tcp $ports -j REDIRECT --to-ports $redir_port
|
2020-11-03 23:10:57 +08:00
|
|
|
|
fi
|
2021-01-05 19:38:48 +08:00
|
|
|
|
iptables -t nat -A PREROUTING -p tcp $lanhost -j clash
|
2021-06-12 13:16:54 +08:00
|
|
|
|
#Google home DNS特殊处理
|
|
|
|
|
iptables -t nat -I PREROUTING -p tcp -d 8.8.8.8 -j clash
|
|
|
|
|
iptables -t nat -I PREROUTING -p tcp -d 8.8.4.4 -j clash
|
2020-09-19 16:32:50 +08:00
|
|
|
|
#设置ipv6转发
|
2020-11-05 20:53:05 +08:00
|
|
|
|
ip6_nat=$(ip6tables -t nat -L 2>&1 | grep -o 'Chain')
|
|
|
|
|
if [ -n "$ip6_nat" -a "$ipv6_support" = "已开启" ];then
|
2020-10-01 18:45:26 +08:00
|
|
|
|
ip6tables -t nat -N clashv6
|
2020-11-03 23:10:57 +08:00
|
|
|
|
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
|
|
|
|
|
#mac白名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
2020-11-05 14:54:52 +08:00
|
|
|
|
ip6tables -t nat -A clashv6 -p tcp $ports -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port
|
2020-11-03 23:10:57 +08:00
|
|
|
|
done
|
|
|
|
|
else
|
|
|
|
|
#mac黑名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
|
|
|
|
ip6tables -t nat -A clashv6 -m mac --mac-source $mac -j RETURN
|
|
|
|
|
done
|
2020-11-05 14:54:52 +08:00
|
|
|
|
ip6tables -t nat -A clashv6 -p tcp $ports -j REDIRECT --to-ports $redir_port
|
2020-11-03 23:10:57 +08:00
|
|
|
|
fi
|
2020-11-05 20:58:17 +08:00
|
|
|
|
ip6tables -t nat -A PREROUTING -p tcp -j clashv6
|
2020-08-22 20:08:23 +08:00
|
|
|
|
fi
|
|
|
|
|
}
|
2020-10-28 11:09:26 +08:00
|
|
|
|
start_dns(){
|
|
|
|
|
#允许tun网卡接受流量
|
|
|
|
|
if [ "$redir_mod" = "Tun模式" -o "$redir_mod" = "混合模式" ];then
|
|
|
|
|
iptables -I FORWARD -o utun -j ACCEPT
|
|
|
|
|
[ "$ipv6_support" = "已开启" ] && ip6tables -I FORWARD -o utun -j ACCEPT > /dev/null 2>&1
|
|
|
|
|
fi
|
|
|
|
|
#设置dns转发
|
|
|
|
|
iptables -t nat -N clash_dns
|
2020-11-03 23:10:57 +08:00
|
|
|
|
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
|
|
|
|
|
#mac白名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
|
|
|
|
iptables -t nat -A clash_dns -p udp --dport 53 -m mac --mac-source $mac -j REDIRECT --to $dns_port
|
|
|
|
|
iptables -t nat -A clash_dns -p tcp --dport 53 -m mac --mac-source $mac -j REDIRECT --to $dns_port
|
|
|
|
|
done
|
|
|
|
|
else
|
|
|
|
|
#mac黑名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
|
|
|
|
iptables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN
|
|
|
|
|
done
|
|
|
|
|
iptables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to $dns_port
|
|
|
|
|
iptables -t nat -A clash_dns -p tcp --dport 53 -j REDIRECT --to $dns_port
|
|
|
|
|
fi
|
2020-10-28 11:09:26 +08:00
|
|
|
|
iptables -t nat -A PREROUTING -p udp -j clash_dns
|
|
|
|
|
#ipv6DNS
|
2020-11-05 20:53:05 +08:00
|
|
|
|
ip6_nat=$(ip6tables -t nat -L 2>&1 | grep -o 'Chain')
|
|
|
|
|
if [ -n "$ip6_nat" ];then
|
2020-10-28 11:09:26 +08:00
|
|
|
|
ip6tables -t nat -N clashv6_dns > /dev/null 2>&1
|
2020-11-03 23:10:57 +08:00
|
|
|
|
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
|
|
|
|
|
#mac白名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
|
|
|
|
ip6tables -t nat -A clashv6_dns -p udp --dport 53 -m mac --mac-source $mac -j REDIRECT --to $dns_port
|
|
|
|
|
ip6tables -t nat -A clashv6_dns -p tcp --dport 53 -m mac --mac-source $mac -j REDIRECT --to $dns_port
|
|
|
|
|
done
|
|
|
|
|
else
|
|
|
|
|
#mac黑名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
|
|
|
|
ip6tables -t nat -A clashv6_dns -m mac --mac-source $mac -j RETURN
|
|
|
|
|
done
|
|
|
|
|
ip6tables -t nat -A clashv6_dns -p udp --dport 53 -j REDIRECT --to $dns_port
|
|
|
|
|
ip6tables -t nat -A clashv6_dns -p tcp --dport 53 -j REDIRECT --to $dns_port
|
|
|
|
|
fi
|
2020-11-05 14:54:52 +08:00
|
|
|
|
ip6tables -t nat -A PREROUTING -p udp -j clashv6_dns
|
2020-10-28 11:09:26 +08:00
|
|
|
|
else
|
2020-11-05 14:54:52 +08:00
|
|
|
|
ip6tables -I INPUT -p tcp --dport 53 -j REJECT > /dev/null 2>&1
|
|
|
|
|
ip6tables -I INPUT -p udp --dport 53 -j REJECT > /dev/null 2>&1
|
2020-10-28 11:09:26 +08:00
|
|
|
|
fi
|
|
|
|
|
}
|
2020-10-25 10:01:58 +08:00
|
|
|
|
start_udp(){
|
2021-01-05 19:38:48 +08:00
|
|
|
|
gethost #获取本地局域网地址段
|
2020-10-25 10:01:58 +08:00
|
|
|
|
ip rule add fwmark 1 table 100
|
|
|
|
|
ip route add local default dev lo table 100
|
|
|
|
|
iptables -t mangle -N clash
|
|
|
|
|
iptables -t mangle -A clash -d 0.0.0.0/8 -j RETURN
|
|
|
|
|
iptables -t mangle -A clash -d 10.0.0.0/8 -j RETURN
|
|
|
|
|
iptables -t mangle -A clash -d 127.0.0.0/8 -j RETURN
|
|
|
|
|
iptables -t mangle -A clash -d 169.254.0.0/16 -j RETURN
|
|
|
|
|
iptables -t mangle -A clash -d 172.16.0.0/12 -j RETURN
|
|
|
|
|
iptables -t mangle -A clash -d 192.168.0.0/16 -j RETURN
|
|
|
|
|
iptables -t mangle -A clash -d 224.0.0.0/4 -j RETURN
|
|
|
|
|
iptables -t mangle -A clash -d 240.0.0.0/4 -j RETURN
|
2021-06-13 19:42:06 +08:00
|
|
|
|
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && iptables -t mangle -A clash -m set --match-set cn_ip dst -j RETURN >/dev/null 2>&1 #绕过大陆IP
|
2020-11-05 20:53:05 +08:00
|
|
|
|
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
|
|
|
|
|
#mac白名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
|
|
|
|
iptables -t mangle -A clash -p udp -m mac --mac-source $mac -j TPROXY --on-port $redir_port --tproxy-mark 1
|
|
|
|
|
done
|
|
|
|
|
else
|
|
|
|
|
#mac黑名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
|
|
|
|
iptables -t mangle -A clash -m mac --mac-source $mac -j RETURN
|
|
|
|
|
done
|
|
|
|
|
iptables -t mangle -A clash -p udp -j TPROXY --on-port $redir_port --tproxy-mark 1
|
|
|
|
|
fi
|
2021-01-05 19:38:48 +08:00
|
|
|
|
iptables -t mangle -A PREROUTING -p udp $lanhost -j clash
|
2020-10-25 10:01:58 +08:00
|
|
|
|
}
|
2021-05-15 16:25:18 +08:00
|
|
|
|
start_output(){
|
|
|
|
|
#流量过滤规则
|
|
|
|
|
iptables -t nat -N clash_out
|
2021-05-16 22:28:28 +08:00
|
|
|
|
iptables -t nat -A clash_out -m owner --gid-owner 7890 -j RETURN
|
2021-05-15 16:25:18 +08:00
|
|
|
|
iptables -t nat -A clash_out -d 0.0.0.0/8 -j RETURN
|
|
|
|
|
iptables -t nat -A clash_out -d 10.0.0.0/8 -j RETURN
|
|
|
|
|
iptables -t nat -A clash_out -d 127.0.0.0/8 -j RETURN
|
|
|
|
|
iptables -t nat -A clash_out -d 169.254.0.0/16 -j RETURN
|
|
|
|
|
iptables -t nat -A clash_out -d 172.16.0.0/12 -j RETURN
|
|
|
|
|
iptables -t nat -A clash_out -d 192.168.0.0/16 -j RETURN
|
|
|
|
|
iptables -t nat -A clash_out -d 224.0.0.0/4 -j RETURN
|
|
|
|
|
iptables -t nat -A clash_out -d 240.0.0.0/4 -j RETURN
|
2021-06-13 19:42:06 +08:00
|
|
|
|
[ "$dns_mod" = "redir_host" -a "$cn_ip_route" = "已开启" ] && iptables -t nat -A clash_out -m set --match-set cn_ip dst -j RETURN >/dev/null 2>&1 #绕过大陆IP
|
2021-05-15 16:25:18 +08:00
|
|
|
|
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
|
|
|
|
|
#mac白名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
|
|
|
|
iptables -t nat -A clash_out -p tcp $ports -m mac --mac-source $mac -j REDIRECT --to-ports $redir_port
|
|
|
|
|
done
|
|
|
|
|
else
|
|
|
|
|
#mac黑名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
|
|
|
|
iptables -t nat -A clash_out -m mac --mac-source $mac -j RETURN
|
|
|
|
|
done
|
|
|
|
|
iptables -t nat -A clash_out -p tcp $ports -j REDIRECT --to-ports $redir_port
|
|
|
|
|
fi
|
|
|
|
|
iptables -t nat -A OUTPUT -p tcp -j clash_out
|
|
|
|
|
#设置dns转发
|
|
|
|
|
iptables -t nat -N clash_dns_out
|
2021-05-16 22:28:28 +08:00
|
|
|
|
iptables -t nat -A clash_dns_out -m owner --gid-owner 7890 -j RETURN
|
2021-05-15 16:25:18 +08:00
|
|
|
|
if [ "$macfilter_type" = "白名单" -a -n "$(cat $clashdir/mac)" ];then
|
|
|
|
|
#mac白名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
|
|
|
|
iptables -t nat -A clash_dns_out -p udp --dport 53 -m mac --mac-source $mac -j REDIRECT --to $dns_port
|
|
|
|
|
iptables -t nat -A clash_dns_out -p tcp --dport 53 -m mac --mac-source $mac -j REDIRECT --to $dns_port
|
|
|
|
|
done
|
|
|
|
|
else
|
|
|
|
|
#mac黑名单
|
|
|
|
|
for mac in $(cat $clashdir/mac); do
|
|
|
|
|
iptables -t nat -A clash_dns_out -m mac --mac-source $mac -j RETURN
|
|
|
|
|
done
|
|
|
|
|
iptables -t nat -A clash_dns_out -p udp --dport 53 -j REDIRECT --to $dns_port
|
|
|
|
|
iptables -t nat -A clash_dns_out -p tcp --dport 53 -j REDIRECT --to $dns_port
|
|
|
|
|
fi
|
|
|
|
|
iptables -t nat -A OUTPUT -p udp -j clash_dns_out
|
|
|
|
|
}
|
2020-08-22 20:08:23 +08:00
|
|
|
|
stop_iptables(){
|
2021-01-05 19:38:48 +08:00
|
|
|
|
gethost #获取本地局域网地址段
|
2020-08-22 20:08:23 +08:00
|
|
|
|
#重置iptables规则
|
2020-12-13 22:12:52 +08:00
|
|
|
|
ip rule del fwmark 1 table 100 2> /dev/null
|
|
|
|
|
ip route del local default dev lo table 100 2> /dev/null
|
2021-01-05 19:38:48 +08:00
|
|
|
|
iptables -t nat -D PREROUTING -p tcp $lanhost -j clash 2> /dev/null
|
2020-12-13 22:12:52 +08:00
|
|
|
|
iptables -t nat -D PREROUTING -p udp -j clash_dns 2> /dev/null
|
2021-06-13 19:48:33 +08:00
|
|
|
|
iptables -t nat -D PREROUTING -p tcp -d 8.8.8.8 -j clash 2> /dev/null
|
|
|
|
|
iptables -t nat -D PREROUTING -p tcp -d 8.8.4.4 -j clash 2> /dev/null
|
2020-12-13 22:12:52 +08:00
|
|
|
|
iptables -t nat -F clash 2> /dev/null
|
|
|
|
|
iptables -t nat -X clash 2> /dev/null
|
|
|
|
|
iptables -t nat -F clash_dns 2> /dev/null
|
|
|
|
|
iptables -t nat -X clash_dns 2> /dev/null
|
|
|
|
|
iptables -D FORWARD -o utun -j ACCEPT 2> /dev/null
|
2021-05-15 16:25:18 +08:00
|
|
|
|
#重置output规则
|
|
|
|
|
iptables -t nat -D OUTPUT -p tcp -j clash_out 2> /dev/null
|
|
|
|
|
iptables -t nat -F clash_out 2> /dev/null
|
|
|
|
|
iptables -t nat -X clash_out 2> /dev/null
|
|
|
|
|
iptables -t nat -D OUTPUT -p udp -j clash_dns_out 2> /dev/null
|
|
|
|
|
iptables -t nat -F clash_dns_out 2> /dev/null
|
|
|
|
|
iptables -t nat -X clash_dns_out 2> /dev/null
|
2020-10-25 10:01:58 +08:00
|
|
|
|
#重置udp规则
|
2021-01-05 19:38:48 +08:00
|
|
|
|
iptables -t mangle -D PREROUTING -p udp $lanhost -j clash 2> /dev/null
|
2020-12-13 22:12:52 +08:00
|
|
|
|
iptables -t mangle -F clash 2> /dev/null
|
|
|
|
|
iptables -t mangle -X clash 2> /dev/null
|
2020-08-22 20:08:23 +08:00
|
|
|
|
#重置ipv6规则
|
2020-12-13 22:12:52 +08:00
|
|
|
|
ip6tables -t nat -D PREROUTING -p tcp -j clashv6 2> /dev/null
|
|
|
|
|
ip6tables -t nat -D PREROUTING -p udp -j clashv6_dns 2> /dev/null
|
|
|
|
|
ip6tables -t nat -F clashv6 2> /dev/null
|
|
|
|
|
ip6tables -t nat -X clashv6 2> /dev/null
|
|
|
|
|
ip6tables -t nat -F clashv6_dns 2> /dev/null
|
|
|
|
|
ip6tables -t nat -X clashv6_dns 2> /dev/null
|
|
|
|
|
ip6tables -D FORWARD -o utun -j ACCEPT 2> /dev/null
|
2021-06-13 19:12:57 +08:00
|
|
|
|
#清理ipset规则
|
|
|
|
|
ipset destroy cn_ip >/dev/null 2>&1
|
2020-08-22 20:08:23 +08:00
|
|
|
|
}
|
2020-10-28 11:09:26 +08:00
|
|
|
|
#面板配置保存相关
|
2020-10-10 17:02:53 +08:00
|
|
|
|
web_save(){
|
2020-10-24 20:09:49 +08:00
|
|
|
|
get_save(){
|
|
|
|
|
if curl --version > /dev/null 2>&1;then
|
|
|
|
|
curl -s -H "Authorization: Bearer ${secret}" -H "Content-Type:application/json" "$1"
|
|
|
|
|
elif [ -n "$(wget --help 2>&1|grep '\-\-method')" ];then
|
|
|
|
|
wget -q --header="Authorization: Bearer ${secret}" --header="Content-Type:application/json" -O - "$1"
|
|
|
|
|
else
|
2020-10-30 16:21:09 +08:00
|
|
|
|
logger 当前系统未安装curl且wget的版本太低,无法保存节点配置! 31
|
2020-10-24 20:09:49 +08:00
|
|
|
|
getconfig
|
2020-10-27 09:40:58 +08:00
|
|
|
|
cronset '保存节点配置'
|
2020-10-24 20:09:49 +08:00
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
#使用get_save获取面板节点设置
|
2020-12-13 13:57:37 +08:00
|
|
|
|
get_save http://localhost:${db_port}/proxies | awk -F "{" '{for(i=1;i<=NF;i++) print $i}' | grep -E '^"all".*"Selector"' > /tmp/clash_web_check_$USER
|
|
|
|
|
while read line ;do
|
2021-02-25 21:16:36 +08:00
|
|
|
|
def=$(echo $line | awk -F "[[,]" '{print $2}')
|
2020-12-13 13:57:37 +08:00
|
|
|
|
now=$(echo $line | grep -oE '"now".*",' | sed 's/"now"://g'| sed 's/,//g')
|
|
|
|
|
[ "$def" != "$now" ] && echo $line | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g'| sed 's/"//g' >> /tmp/clash_web_save_$USER
|
|
|
|
|
done < /tmp/clash_web_check_$USER
|
2020-12-14 16:38:14 +08:00
|
|
|
|
rm -rf /tmp/clash_web_check_$USER
|
2020-11-07 12:08:31 +08:00
|
|
|
|
#对比文件,如果有变动且不为空则写入磁盘,否则清除缓存
|
2020-12-13 21:22:41 +08:00
|
|
|
|
if [ -s /tmp/clash_web_save_$USER ];then
|
|
|
|
|
compare /tmp/clash_web_save_$USER $clashdir/web_save
|
|
|
|
|
[ "$?" = 0 ] && rm -rf /tmp/clash_web_save_$USER || mv -f /tmp/clash_web_save_$USER $clashdir/web_save
|
|
|
|
|
fi
|
2020-10-10 17:02:53 +08:00
|
|
|
|
}
|
|
|
|
|
web_restore(){
|
2020-10-24 20:09:49 +08:00
|
|
|
|
put_save(){
|
|
|
|
|
if curl --version > /dev/null 2>&1;then
|
|
|
|
|
curl -sS -X PUT -H "Authorization: Bearer ${secret}" -H "Content-Type:application/json" "$1" -d "$2" >/dev/null
|
|
|
|
|
else
|
2020-10-27 09:40:58 +08:00
|
|
|
|
wget -q --method=PUT --header="Authorization: Bearer ${secret}" --header="Content-Type:application/json" --body-data="$2" "$1" >/dev/null
|
2020-10-24 20:09:49 +08:00
|
|
|
|
fi
|
|
|
|
|
}
|
2020-10-10 17:02:53 +08:00
|
|
|
|
#设置循环检测clash面板端口
|
|
|
|
|
i=1
|
2020-12-08 20:37:49 +08:00
|
|
|
|
while [ $i -lt 10 ];do
|
2020-10-10 17:02:53 +08:00
|
|
|
|
sleep 1
|
2020-10-24 20:09:49 +08:00
|
|
|
|
if curl --version > /dev/null 2>&1;then
|
|
|
|
|
test=$(curl -s http://localhost:${db_port})
|
|
|
|
|
else
|
|
|
|
|
test=$(wget -q -O - http://localhost:${db_port})
|
|
|
|
|
fi
|
|
|
|
|
[ -n "$test" ] && i=10
|
2020-10-10 17:02:53 +08:00
|
|
|
|
done
|
|
|
|
|
#发送数据
|
|
|
|
|
num=$(cat $clashdir/web_save | wc -l)
|
|
|
|
|
for i in `seq $num`;
|
|
|
|
|
do
|
|
|
|
|
group_name=$(awk -F ',' 'NR=="'${i}'" {print $1}' $clashdir/web_save | sed 's/ /%20/g')
|
|
|
|
|
now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' $clashdir/web_save)
|
2020-10-24 20:09:49 +08:00
|
|
|
|
put_save http://localhost:${db_port}/proxies/${group_name} "{\"name\":\"${now_name}\"}"
|
2020-10-10 17:02:53 +08:00
|
|
|
|
done
|
|
|
|
|
}
|
2020-10-28 11:09:26 +08:00
|
|
|
|
#启动相关
|
2020-10-30 16:21:09 +08:00
|
|
|
|
catpac(){
|
2021-01-05 19:38:48 +08:00
|
|
|
|
gethost
|
2020-10-30 16:21:09 +08:00
|
|
|
|
cat > /tmp/clash_pac <<EOF
|
|
|
|
|
function FindProxyForURL(url, host) {
|
|
|
|
|
if (
|
|
|
|
|
isInNet(host, "0.0.0.0", "255.0.0.0")||
|
|
|
|
|
isInNet(host, "10.0.0.0", "255.0.0.0")||
|
|
|
|
|
isInNet(host, "127.0.0.0", "255.0.0.0")||
|
|
|
|
|
isInNet(host, "224.0.0.0", "224.0.0.0")||
|
|
|
|
|
isInNet(host, "240.0.0.0", "240.0.0.0")||
|
|
|
|
|
isInNet(host, "172.16.0.0", "255.240.0.0")||
|
|
|
|
|
isInNet(host, "192.168.0.0", "255.255.0.0")||
|
|
|
|
|
isInNet(host, "169.254.0.0", "255.255.0.0")
|
|
|
|
|
)
|
|
|
|
|
return "DIRECT";
|
|
|
|
|
else
|
2021-01-05 19:38:48 +08:00
|
|
|
|
return "PROXY $host:$mix_port; DIRECT; SOCKS5 $host:$mix_port"
|
2020-10-30 16:21:09 +08:00
|
|
|
|
}
|
|
|
|
|
EOF
|
2020-11-07 12:08:31 +08:00
|
|
|
|
compare /tmp/clash_pac $bindir/ui/pac
|
2020-10-30 16:21:09 +08:00
|
|
|
|
[ "$?" = 0 ] && rm -rf /tmp/clash_pac || mv -f /tmp/clash_pac $bindir/ui/pac
|
|
|
|
|
}
|
|
|
|
|
bfstart(){
|
2020-11-01 20:15:11 +08:00
|
|
|
|
#读取配置文件
|
|
|
|
|
getconfig
|
2020-10-30 16:21:09 +08:00
|
|
|
|
[ ! -d $bindir/ui ] && mkdir -p $bindir/ui
|
2020-11-01 11:38:26 +08:00
|
|
|
|
[ -z "$update_url" ] && update_url=https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master
|
2020-10-30 16:21:09 +08:00
|
|
|
|
#检查clash核心
|
|
|
|
|
if [ ! -f $bindir/clash ];then
|
|
|
|
|
if [ -f $clashdir/clash ];then
|
2020-11-15 13:01:29 +08:00
|
|
|
|
mv $clashdir/clash $bindir/clash && chmod +x $bindir/clash
|
2020-10-30 16:21:09 +08:00
|
|
|
|
else
|
|
|
|
|
logger "未找到clash核心,正在下载!" 33
|
2020-12-11 22:17:29 +08:00
|
|
|
|
if [ -z "$clashcore" ];then
|
|
|
|
|
[ "$redir_mod" = "混合模式" -o "$redir_mod" = "Tun模式" ] && clashcore=clashpre || clashcore=clash
|
|
|
|
|
fi
|
2020-10-30 16:21:09 +08:00
|
|
|
|
[ -z "$cpucore" ] && source $clashdir/getdate.sh && getcpucore
|
2020-11-01 11:38:26 +08:00
|
|
|
|
[ -z "$cpucore" ] && logger 找不到设备的CPU信息,请手动指定处理器架构类型! 31 && setcpucore
|
2020-10-30 16:21:09 +08:00
|
|
|
|
webget $bindir/clash "$update_url/bin/$clashcore/clash-linux-$cpucore"
|
2021-06-13 19:12:57 +08:00
|
|
|
|
[ "$result" != 200 ] && rm -rf $bindir/clash && logger "核心下载失败,已退出!" 31 && exit 1
|
2020-11-01 11:38:26 +08:00
|
|
|
|
[ ! -x $bindir/clash ] && chmod +x $bindir/clash #检测可执行权限
|
|
|
|
|
clashv=$($bindir/clash -v | awk '{print $2}')
|
|
|
|
|
setconfig clashv $clashv
|
2020-10-30 16:21:09 +08:00
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
#检查数据库文件
|
|
|
|
|
if [ ! -f $bindir/Country.mmdb ];then
|
|
|
|
|
if [ -f $clashdir/Country.mmdb ];then
|
|
|
|
|
mv $clashdir/Country.mmdb $bindir/Country.mmdb
|
|
|
|
|
else
|
|
|
|
|
logger "未找到GeoIP数据库,正在下载!" 33
|
2020-12-11 22:17:29 +08:00
|
|
|
|
[ -z "$geotype" ] && geotype=cn_mini.mmdb
|
|
|
|
|
webget $bindir/Country.mmdb $update_url/bin/$geotype
|
2021-06-13 19:12:57 +08:00
|
|
|
|
[ "$result" != 200 ] && rm -rf $bindir/Country.mmdb && logger "数据库下载失败,已退出!" 31 && exit 1
|
2020-12-11 22:17:29 +08:00
|
|
|
|
Geo_v=$(date +"%Y%m%d")
|
|
|
|
|
setconfig Geo_v $Geo_v
|
2020-10-30 16:21:09 +08:00
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
#检查dashboard文件
|
|
|
|
|
if [ -f $clashdir/ui/index.html -a ! -f $bindir/ui/index.html ];then
|
|
|
|
|
cp -rf $clashdir/ui $bindir
|
|
|
|
|
fi
|
|
|
|
|
catpac #生成pac文件
|
|
|
|
|
#检查yaml配置文件
|
|
|
|
|
if [ ! -f $clashdir/config.yaml ];then
|
|
|
|
|
if [ -n "$Url" -o -n "$Https" ];then
|
|
|
|
|
logger "未找到配置文件,正在下载!" 33
|
|
|
|
|
getyaml
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
|
|
|
|
logger "未找到配置文件链接,请先导入配置文件!" 31
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
2020-09-18 21:09:06 +08:00
|
|
|
|
afstart(){
|
2020-12-08 23:21:50 +08:00
|
|
|
|
|
2020-10-28 11:09:26 +08:00
|
|
|
|
#读取配置文件
|
|
|
|
|
getconfig
|
2020-10-30 16:21:09 +08:00
|
|
|
|
$bindir/clash -t -d $bindir >/dev/null
|
2020-10-27 16:36:01 +08:00
|
|
|
|
if [ "$?" = 0 ];then
|
2020-12-08 23:21:50 +08:00
|
|
|
|
#设置iptables转发规则
|
2021-06-13 19:12:57 +08:00
|
|
|
|
[ "$dns_mod" = "redir_host" ] && [ "$cn_ip_route" = "已开启" ] && cn_ip_route
|
2020-12-08 23:21:50 +08:00
|
|
|
|
[ "$redir_mod" != "纯净模式" ] && [ "$dns_no" != "已禁用" ] && start_dns
|
|
|
|
|
[ "$redir_mod" != "纯净模式" ] && [ "$redir_mod" != "Tun模式" ] && start_redir
|
|
|
|
|
[ "$redir_mod" = "Redir模式" ] && [ "$tproxy_mod" = "已开启" ] && start_udp
|
2020-10-27 16:36:01 +08:00
|
|
|
|
#标记启动时间
|
|
|
|
|
mark_time
|
|
|
|
|
#设置本机代理
|
|
|
|
|
[ "$local_proxy" = "已开启" ] && $0 set_proxy $mix_port $db_port
|
2021-06-05 19:27:28 +08:00
|
|
|
|
#加载定时任务
|
|
|
|
|
[ -f $clashdir/cron ] && crontab $clashdir/cron
|
2020-10-27 16:36:01 +08:00
|
|
|
|
#启用面板配置自动保存
|
2021-06-05 19:17:26 +08:00
|
|
|
|
cronset '#每10分钟保存节点配置' "*/10 * * * * test -n \"\$(pidof clash)\" && $clashdir/start.sh web_save #每10分钟保存节点配置"
|
2020-10-27 16:36:01 +08:00
|
|
|
|
[ -f $clashdir/web_save ] && web_restore & #后台还原面板配置
|
|
|
|
|
else
|
2020-10-30 16:21:09 +08:00
|
|
|
|
logger "clash服务启动失败!请查看报错信息!" 31
|
2020-12-11 22:17:29 +08:00
|
|
|
|
$bindir/clash -t -d $bindir
|
|
|
|
|
echo "$($bindir/clash -t -d $bindir)" >> $clashdir/log
|
2020-11-01 20:15:11 +08:00
|
|
|
|
$0 stop
|
2020-10-27 16:36:01 +08:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2020-08-22 20:08:23 +08:00
|
|
|
|
}
|
2020-10-27 09:40:58 +08:00
|
|
|
|
start_old(){
|
2020-10-30 16:21:09 +08:00
|
|
|
|
#使用传统后台执行二进制文件的方式执行
|
|
|
|
|
$bindir/clash -d $bindir >/dev/null &
|
2020-10-27 09:40:58 +08:00
|
|
|
|
afstart
|
2020-11-06 16:59:49 +08:00
|
|
|
|
$0 daemon
|
2020-10-27 09:40:58 +08:00
|
|
|
|
}
|
2020-09-18 21:09:06 +08:00
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
|
|
2020-10-30 16:21:09 +08:00
|
|
|
|
bfstart)
|
|
|
|
|
bfstart
|
|
|
|
|
;;
|
2020-09-18 21:09:06 +08:00
|
|
|
|
afstart)
|
|
|
|
|
afstart
|
|
|
|
|
;;
|
|
|
|
|
start)
|
2020-10-27 16:36:01 +08:00
|
|
|
|
[ -n "$(pidof clash)" ] && $0 stop #禁止多实例
|
2020-09-18 21:09:06 +08:00
|
|
|
|
getconfig
|
2020-10-30 16:21:09 +08:00
|
|
|
|
#检测必须文件并下载
|
|
|
|
|
bfstart
|
2020-11-06 16:59:49 +08:00
|
|
|
|
stop_iptables #清理iptables
|
2020-10-27 09:40:58 +08:00
|
|
|
|
#使用内置规则强行覆盖config配置文件
|
|
|
|
|
[ "$modify_yaml" != "已开启" ] && modify_yaml
|
2020-09-18 21:09:06 +08:00
|
|
|
|
#使用不同方式启动clash服务
|
|
|
|
|
if [ "$start_old" = "已开启" ];then
|
2020-10-27 09:40:58 +08:00
|
|
|
|
start_old
|
2020-09-18 21:09:06 +08:00
|
|
|
|
elif [ -f /etc/rc.common ];then
|
|
|
|
|
/etc/init.d/clash start
|
2020-10-27 09:40:58 +08:00
|
|
|
|
elif [ "$USER" = "root" ];then
|
2020-09-18 21:09:06 +08:00
|
|
|
|
systemctl start clash.service
|
2020-10-27 09:40:58 +08:00
|
|
|
|
else
|
|
|
|
|
start_old
|
2020-09-18 21:09:06 +08:00
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
stop)
|
2020-10-06 17:56:17 +08:00
|
|
|
|
getconfig
|
2020-11-06 16:59:49 +08:00
|
|
|
|
[ -n "$(pidof clash)" ] && web_save #保存面板配置
|
2020-10-10 17:02:53 +08:00
|
|
|
|
#删除守护进程&面板配置自动保存
|
2020-10-27 09:40:58 +08:00
|
|
|
|
cronset "clash保守模式守护进程"
|
|
|
|
|
cronset "保存节点配置"
|
2020-09-18 21:09:06 +08:00
|
|
|
|
#多种方式结束进程
|
|
|
|
|
if [ -f /etc/rc.common ];then
|
2020-09-19 16:32:50 +08:00
|
|
|
|
/etc/init.d/clash stop >/dev/null 2>&1
|
2020-10-27 09:40:58 +08:00
|
|
|
|
elif [ "$USER" = "root" ];then
|
2020-09-19 16:32:50 +08:00
|
|
|
|
systemctl stop clash.service >/dev/null 2>&1
|
2020-09-18 21:09:06 +08:00
|
|
|
|
fi
|
2020-10-27 16:36:01 +08:00
|
|
|
|
PID=$(pidof clash) && [ -n "$PID" ] && kill -9 $PID >/dev/null 2>&1
|
2020-10-25 15:42:23 +08:00
|
|
|
|
stop_iptables #清理iptables
|
|
|
|
|
[ "$local_proxy" = "已开启" ] && $0 unset_proxy #禁用本机代理
|
2020-09-18 21:09:06 +08:00
|
|
|
|
;;
|
|
|
|
|
restart)
|
|
|
|
|
$0 stop
|
|
|
|
|
$0 start
|
|
|
|
|
;;
|
2021-06-05 12:53:20 +08:00
|
|
|
|
init)
|
2021-06-05 19:17:26 +08:00
|
|
|
|
[ -d "/etc/storage/clash" ] && clashdir=/etc/storage/clash && profile=/opt/etc/profile
|
|
|
|
|
[ -d "/jffs/clash" ] && clashdir=/jffs/clash && profile=/jffs/configs/profile.add
|
|
|
|
|
echo "alias clash=\"$clashdir/clash.sh\"" >> $profile
|
|
|
|
|
echo "export clashdir=\"$clashdir\"" >> $profile
|
2021-06-05 12:53:20 +08:00
|
|
|
|
$0 start
|
|
|
|
|
;;
|
2020-09-18 21:09:06 +08:00
|
|
|
|
getyaml)
|
|
|
|
|
getconfig
|
|
|
|
|
getyaml
|
|
|
|
|
;;
|
2020-12-12 12:20:22 +08:00
|
|
|
|
updateyaml)
|
|
|
|
|
$0 getyaml
|
|
|
|
|
$0 restart
|
|
|
|
|
;;
|
2020-10-30 16:21:09 +08:00
|
|
|
|
webget)
|
2021-06-06 14:47:18 +08:00
|
|
|
|
webget $2 $3 $4 $5 $6
|
2020-10-30 16:21:09 +08:00
|
|
|
|
;;
|
2020-10-10 17:02:53 +08:00
|
|
|
|
web_save)
|
|
|
|
|
getconfig
|
|
|
|
|
web_save
|
|
|
|
|
;;
|
2021-01-29 15:11:35 +08:00
|
|
|
|
web_restore)
|
|
|
|
|
getconfig
|
|
|
|
|
web_restore
|
|
|
|
|
;;
|
2020-10-27 16:36:01 +08:00
|
|
|
|
daemon)
|
|
|
|
|
getconfig
|
2021-06-05 19:17:26 +08:00
|
|
|
|
cronset '#clash保守模式守护进程' "*/1 * * * * test -z \"\$(pidof clash)\" && $clashdir/start.sh restart #clash保守模式守护进程"
|
2020-10-27 16:36:01 +08:00
|
|
|
|
;;
|
2020-12-21 11:55:43 +08:00
|
|
|
|
cronset)
|
|
|
|
|
cronset $2 $3
|
|
|
|
|
;;
|
2020-10-11 21:30:20 +08:00
|
|
|
|
set_proxy)
|
2020-10-28 11:09:26 +08:00
|
|
|
|
getconfig
|
2021-05-15 16:25:18 +08:00
|
|
|
|
#iptables增强模式
|
|
|
|
|
if [ "$local_proxy_type" = "iptables增强模式" ];then
|
|
|
|
|
start_output
|
2020-10-23 07:23:38 +08:00
|
|
|
|
#环境变量方式
|
2020-10-28 11:09:26 +08:00
|
|
|
|
else
|
2020-10-24 21:13:06 +08:00
|
|
|
|
[ -w ~/.bashrc ] && profile=~/.bashrc
|
|
|
|
|
[ -w /etc/profile ] && profile=/etc/profile
|
2020-10-28 11:09:26 +08:00
|
|
|
|
echo 'export all_proxy=http://127.0.0.1:'"$mix_port" >> $profile
|
2020-10-24 21:13:06 +08:00
|
|
|
|
echo 'export ALL_PROXY=$all_proxy' >> $profile
|
2020-10-23 07:23:38 +08:00
|
|
|
|
fi
|
2020-10-11 21:30:20 +08:00
|
|
|
|
;;
|
2021-05-15 16:25:18 +08:00
|
|
|
|
unset_proxy)
|
2020-10-28 11:09:26 +08:00
|
|
|
|
[ -w ~/.bashrc ] && profile=~/.bashrc
|
|
|
|
|
[ -w /etc/profile ] && profile=/etc/profile
|
|
|
|
|
sed -i '/all_proxy/'d $profile
|
|
|
|
|
sed -i '/ALL_PROXY/'d $profile
|
2020-10-10 17:02:53 +08:00
|
|
|
|
;;
|
2020-09-18 21:09:06 +08:00
|
|
|
|
esac
|
2020-10-09 19:21:28 +08:00
|
|
|
|
|
|
|
|
|
exit 0
|