v1.0.0beta7

~大幅度优化更新机制
~重写启动脚本,全面兼容debian及centos
~支持以systemd方式启动及守护进程
~优化安装脚本,修复cdn更新延迟
~修改定时任务机制,增加稳定性
~增加配置本机代理功能
This commit is contained in:
juewuy
2020-09-19 16:32:50 +08:00
parent 230fcb6649
commit d9003e50eb
5 changed files with 59 additions and 46 deletions

Binary file not shown.

View File

@@ -1,2 +1,2 @@
GeoIP_v=20200917 GeoIP_v=20200917
versionsh=1223 versionsh=1.0.0beta7

View File

@@ -5,8 +5,6 @@ getconfig(){
#系统类型 #系统类型
systype=$(cat /proc/version | grep -io openwrt) systype=$(cat /proc/version | grep -io openwrt)
if [ -n "$systype" ];then if [ -n "$systype" ];then
ps_type=ps
sh_type=sh
host=$(ubus call network.interface.lan status | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';) host=$(ubus call network.interface.lan status | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
if [ -f /etc/rc.d/*clash ];then if [ -f /etc/rc.d/*clash ];then
autostart=enable_rc autostart=enable_rc
@@ -14,8 +12,7 @@ if [ -n "$systype" ];then
autostart=disable_rc autostart=disable_rc
fi fi
else else
ps_type='ps aux' cron_user='root '
sh_type=bash
host=$(ip a|grep -w 'inet'|grep 'global'|grep -E '192.|10.'|sed 's/.*inet.//g'|sed 's/\/[0-9][0-9].*$//g') host=$(ip a|grep -w 'inet'|grep 'global'|grep -E '192.|10.'|sed 's/.*inet.//g'|sed 's/\/[0-9][0-9].*$//g')
[ -z $host ] && host=127.0.0.1 [ -z $host ] && host=127.0.0.1
if [ -n "$(systemctl list-unit-files clash.service | grep -o enable)" ];then if [ -n "$(systemctl list-unit-files clash.service | grep -o enable)" ];then
@@ -109,14 +106,14 @@ clashstart(){
fi fi
if [ -n "$PID" ];then if [ -n "$PID" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$sh_type $clashdir/start.sh stop $clashdir/start.sh stop
echo -e "\033[31mClash服务已停止\033[0m" echo -e "\033[31mClash服务已停止\033[0m"
fi fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$sh_type $clashdir/start.sh start $clashdir/start.sh start
sleep 1 sleep 1
status=`$ps_type |grep -w 'clash'|grep -v grep|grep -v clash.sh` PID=$(pidof clash)
if [ -z "$status" ];then if [ -z "$PID" ];then
echo -e "\033[31mclash启动失败\033[0m" echo -e "\033[31mclash启动失败\033[0m"
exit exit
fi fi
@@ -359,7 +356,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -e "\033[33m切换模式后需要手动重启clash服务以生效\033[0m" echo -e "\033[33m切换模式后需要手动重启clash服务以生效\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
echo " 1 fake-ip模式 响应速度更快" echo " 1 fake-ip模式 响应速度更快"
echo " 但可能和部分软件有冲突" echo " 不兼容部分软件"
echo " 2 redir_host模式使用稳定兼容性好" echo " 2 redir_host模式使用稳定兼容性好"
echo " 不支持Tun模式" echo " 不支持Tun模式"
echo " 0 返回上级菜单" echo " 0 返回上级菜单"
@@ -515,6 +512,7 @@ clashadv(){
[ -z "$modify_yaml" ] && modify_yaml=未开启 [ -z "$modify_yaml" ] && modify_yaml=未开启
[ -z "$ipv6_support" ] && ipv6_support=未开启 [ -z "$ipv6_support" ] && ipv6_support=未开启
[ -z "$start_old" ] && start_old=未开启 [ -z "$start_old" ] && start_old=未开启
[ -z "$local_proxy" ] && local_proxy=未开启
# #
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m欢迎使用进阶模式菜单\033[0m" echo -e "\033[30;47m欢迎使用进阶模式菜单\033[0m"
@@ -524,6 +522,7 @@ echo -----------------------------------------------
echo -e " 1 不修饰config.yaml: \033[36m$modify_yaml\033[0m ————用于使用自定义配置" echo -e " 1 不修饰config.yaml: \033[36m$modify_yaml\033[0m ————用于使用自定义配置"
echo -e " 2 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性且不兼容Fake_ip" echo -e " 2 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性且不兼容Fake_ip"
echo -e " 3 使用保守方式启动: \033[36m$start_old\033[0m ————切换时会停止clash服务" echo -e " 3 使用保守方式启动: \033[36m$start_old\033[0m ————切换时会停止clash服务"
echo -e " 4 代理本机流量: \033[36m$local_proxy\033[0m ————配置本机代理环境变量"
echo ----------------------------------------------- echo -----------------------------------------------
echo -e " 8 \033[31m重置\033[0m配置文件" echo -e " 8 \033[31m重置\033[0m配置文件"
echo -e " 9 \033[32m重启\033[0mclash服务" echo -e " 9 \033[32m重启\033[0mclash服务"
@@ -575,16 +574,36 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -e "\033[33m改为使用保守方式启动clash服务\033[0m" echo -e "\033[33m改为使用保守方式启动clash服务\033[0m"
echo -e "\033[36m此模式兼容性更好但无法禁用开机启动\033[0m" echo -e "\033[36m此模式兼容性更好但无法禁用开机启动\033[0m"
start_old=已开启 start_old=已开启
$sh_type $clashdir/start.sh stop > /dev/null 2>&1 $clashdir/start.sh stop > /dev/null 2>&1
sleep 2 sleep 2
else else
sed -i "1i\start_old=未开启" $ccfg sed -i "1i\start_old=未开启" $ccfg
echo -e "\033[32m改为使用默认方式启动clash服务\033[0m" echo -e "\033[32m改为使用默认方式启动clash服务\033[0m"
start_old=未开启 start_old=未开启
$sh_type $clashdir/start.sh stop > /dev/null 2>&1 $clashdir/start.sh stop > /dev/null 2>&1
fi fi
clashadv clashadv
elif [[ $num == 4 ]]; then
sed -i '/local_proxy*/'d $ccfg
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$local_proxy" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\local_proxy=已开启" $ccfg
local_proxy=已开启
echo 'export http_proxy=http://127.0.0.1:7890' >> /etc/profile
echo 'export https_proxy=http://127.0.0.1:7890' >> /etc/profile
echo -e "\033[32m已经将代理参数写入环境变量~\033[0m"
echo -e "\033[36m如未生效请重新登录或者重启设备\033[0m"
sleep 1
else
sed -i "1i\local_proxy=未开启" $ccfg
echo -e "\033[33m已经将代理参数从环境变量移除\033[0m"
local_proxy=未开启
sed -i '/http*_proxy/'d /etc/profile
fi
source /etc/profile > /dev/null 2>&1
clashadv
elif [[ $num == 8 ]]; then elif [[ $num == 8 ]]; then
read -p "确认重置配置文件?(1/0) > " res read -p "确认重置配置文件?(1/0) > " res
if [ "$res" = "1" ];then if [ "$res" = "1" ];then
@@ -768,7 +787,7 @@ clashcron(){
read -p "是否确认添加定时任务?(1/0) > " res read -p "是否确认添加定时任务?(1/0) > " res
if [ "$res" = '1' ]; then if [ "$res" = '1' ]; then
sed -i /$cronname/d $cronpath sed -i /$cronname/d $cronpath
echo "$min $hour * * $week $cronset >/dev/null 2>&1 #$week1的$hour点$min分$cronname" >> $cronpath echo "$min $hour * * $week $cron_user$cronset >/dev/null 2>&1 #$week1的$hour点$min分$cronname" >> $cronpath
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m定时任务已添加\033[0m" echo -e "\033[31m定时任务已添加\033[0m"
fi fi
@@ -861,7 +880,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
clashcfg clashcfg
elif [[ $num == 3 ]]; then elif [[ $num == 3 ]]; then
$sh_type $clashdir/start.sh stop $clashdir/start.sh stop
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31mClash服务已停止\033[0m" echo -e "\033[31mClash服务已停止\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -881,10 +900,10 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
/etc/init.d/clash enable /etc/init.d/clash enable
echo -e "\033[32m已设置Clash开机启动\033[0m" echo -e "\033[32m已设置Clash开机启动\033[0m"
elif [ "$autostart" = "enable_sys" ]; then elif [ "$autostart" = "enable_sys" ]; then
systemctl disable clash.service systemctl disable clash.service > /dev/null 2>&1
echo -e "\033[33m已禁止Clash开机启动\033[0m" echo -e "\033[33m已禁止Clash开机启动\033[0m"
elif [ "$autostart" = "disable_sys" ]; then elif [ "$autostart" = "disable_sys" ]; then
systemctl enable clash.service systemctl enable clash.service > /dev/null 2>&1
echo -e "\033[32m已设置Clash开机启动\033[0m" echo -e "\033[32m已设置Clash开机启动\033[0m"
else else
echo -e "\033[32m当前系统不支持设置开启启动\033[0m" echo -e "\033[32m当前系统不支持设置开启启动\033[0m"
@@ -923,7 +942,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
elif [[ $num == 0 ]]; then elif [[ $num == 0 ]]; then
clashsh clashsh
elif [[ $num == 1 ]]; then elif [[ $num == 1 ]]; then
$sh_type $clashdir/start.sh stop $clashdir/start.sh stop
echo ----------------------------------------------- echo -----------------------------------------------
$clashdir/clash -d $clashdir & { sleep 3 ; kill $! & } $clashdir/clash -d $clashdir & { sleep 3 ; kill $! & }
echo ----------------------------------------------- echo -----------------------------------------------
@@ -964,15 +983,6 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -e "\033[31m连接超时请重试或检查节点配置\033[0m" echo -e "\033[31m连接超时请重试或检查节点配置\033[0m"
fi fi
clashsh clashsh
elif [[ $num == 7 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for PID in $($ps_type|awk '{print $1}');do
[ -f "/proc/$PID/status" ] && vmrss=$(cat /proc/$PID/status|grep -w VmRSS|awk '{print $2}')
[ -n "$vmrss" ] && echo $vmrss $(cat /proc/$PID/status|grep -w Name|awk '{print $2}')
done
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit;
else else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m" echo -e "\033[31m请输入正确的数字\033[0m"

View File

@@ -109,7 +109,7 @@ if [ -n $Url ];then
sed -i "6i\Url=\'$Url\'" $ccfg sed -i "6i\Url=\'$Url\'" $ccfg
Https="" Https=""
#获取在线yaml文件 #获取在线yaml文件
$sh_type $clashdir/start.sh getyaml $clashdir/start.sh getyaml
elif [ "$num" = '2' ]; then elif [ "$num" = '2' ]; then
linkfilter linkfilter
linkset linkset
@@ -212,7 +212,7 @@ if [ -n $Https ];then
sed -i '/Https=*/'d $ccfg sed -i '/Https=*/'d $ccfg
sed -i "6i\Https=\'$Https\'" $ccfg sed -i "6i\Https=\'$Https\'" $ccfg
#获取在线yaml文件 #获取在线yaml文件
$sh_type $clashdir/start.sh getyaml $clashdir/start.sh getyaml
fi fi
clashlink clashlink
fi fi

View File

@@ -214,7 +214,7 @@ mark_time(){
sed -i "1i\start_time=$start_time" $clashdir/mark sed -i "1i\start_time=$start_time" $clashdir/mark
} }
start_redir(){ start_redir(){
#修改iptables规则使流量进入clash #流量过滤规则
iptables -t nat -N clash iptables -t nat -N clash
iptables -t nat -A clash -d 0.0.0.0/8 -j RETURN iptables -t nat -A clash -d 0.0.0.0/8 -j RETURN
iptables -t nat -A clash -d 10.0.0.0/8 -j RETURN iptables -t nat -A clash -d 10.0.0.0/8 -j RETURN
@@ -227,9 +227,10 @@ start_redir(){
for mac in $(cat $clashdir/mac); do for mac in $(cat $clashdir/mac); do
iptables -t nat -A clash -m mac --mac-source $mac -j RETURN iptables -t nat -A clash -m mac --mac-source $mac -j RETURN
done done
#设置防火墙流量转发
iptables -t nat -A clash -p tcp $ports-j REDIRECT --to-ports 7892 iptables -t nat -A clash -p tcp $ports-j REDIRECT --to-ports 7892
iptables -t nat -A PREROUTING -p tcp -j clash iptables -t nat -A PREROUTING -p tcp -j clash
#设置ipv6转发
if [ "$ipv6_support" = "已开启" ];then if [ "$ipv6_support" = "已开启" ];then
ip6tables -t nat -N clash ip6tables -t nat -N clash
for mac in $(cat $clashdir/mac); do for mac in $(cat $clashdir/mac); do
@@ -266,19 +267,21 @@ start_dns(){
done done
iptables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to 1053 iptables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to 1053
iptables -t nat -A PREROUTING -p udp -j clash_dns iptables -t nat -A PREROUTING -p udp -j clash_dns
#ipv6DNS #ipv6DNS
if [ "$ipv6_support" = "已开启" ];then
ip6tables -t nat -N clash_dns > /dev/null 2>&1 ip6tables -t nat -N clash_dns > /dev/null 2>&1
for mac in $(cat $clashdir/mac); do for mac in $(cat $clashdir/mac); do
ip6tables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN > /dev/null 2>&1 ip6tables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN > /dev/null 2>&1
done done
ip6tables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1 ip6tables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1
ip6tables -t nat -A PREROUTING -p udp -j clash_dns > /dev/null 2>&1 ip6tables -t nat -A PREROUTING -p udp -j clash_dns > /dev/null 2>&1
fi
} }
daemon_old(){ daemon_old(){
#守护进程状态 #守护进程状态
status=$(ps |grep -w 'clash'|grep -v grep|grep -v clash.sh) PID=$(pidof clash)
[ -z $status ] && status=$(ps aux |grep -w 'clash'|grep -v grep|grep -v clash.sh) if [ -z "$PID" ];then
if [ -z $status ];then
$clashdir/clash -d $clashdir > /dev/null & $clashdir/clash -d $clashdir > /dev/null &
mark_time mark_time
fi fi
@@ -316,7 +319,7 @@ start)
[ "$modify_yaml" != "已开启" ] && modify_yaml [ "$modify_yaml" != "已开启" ] && modify_yaml
#使用不同方式启动clash服务 #使用不同方式启动clash服务
if [ "$start_old" = "已开启" ];then if [ "$start_old" = "已开启" ];then
$clashdir/clash -d $clashdir> /dev/null & $clashdir/clash -d $clashdir >/dev/null 2>&1 &
afstart afstart
elif [ -f /etc/rc.common ];then elif [ -f /etc/rc.common ];then
/etc/init.d/clash start /etc/init.d/clash start
@@ -327,14 +330,14 @@ start)
stop) stop)
#删除守护 #删除守护
checkcron checkcron
sed -i /start.sh/d $cronpath sed -i /start.sh/d $cronpath >/dev/null 2>&1
#多种方式结束进程 #多种方式结束进程
if [ -f /etc/rc.common ];then if [ -f /etc/rc.common ];then
/etc/init.d/clash stop &> /dev/null /etc/init.d/clash stop >/dev/null 2>&1
else else
systemctl stop clash.service &> /dev/null systemctl stop clash.service >/dev/null 2>&1
fi fi
killall -9 clash &> /dev/null killall -9 clash >/dev/null 2>&1
#清理iptables #清理iptables
stop_iptables stop_iptables
;; ;;