20 Commits

Author SHA1 Message Date
juewuy
4079d1525f v1.0.0beta15
~新增对使用mips-softfloat核心设备的适配
~新增手动指定核心架构的菜单
~增加了按照关键字白名单筛选节点的功能
~新增了帮助:-h,测试:-t脚本运行参数
~优化节点保存方式,现在每10分钟检测一次,仅在检测到文件变动后方进行保存
~修复部分ssr节点不可用的bug
~mac过滤功能增加移除单个设备以及添加全部设备功能
~修复设置本机代理时直接跳出的bug
~优化安装脚本,增加root用户检测
~优化ipv6dns拦截方式
~回滚对循环计算的方式
2020-10-14 17:22:13 +08:00
juewuy
0219fcd94e v1.0.0beta14fix5
~新增对使用mips-softfloat核心设备的适配
~优化节点保存方式,现在每10分钟检测一次,仅在检测到文件变动后方进行保存
~修复部分ssr节点不可用的bug
~mac过滤功能增加移除单个设备以及添加全部设备功能
~修复设置本机代理时直接跳出的bug
~优化安装脚本,增加root用户检测
~优化ipv6dns拦截方式
~回滚对循环计算的方式
2020-10-14 16:19:44 +08:00
juewuy
30b3a34d8e v1.0.0beta14fix4
~优化节点保存方式,现在每10分钟检测一次,仅在检测到文件变动后方进行保存
~修复部分ssr节点不可用的bug
~mac过滤功能增加移除单个设备以及添加全部设备功能
~修复设置本机代理时直接跳出的bug
~优化安装脚本,增加root用户检测
~优化ipv6dns拦截方式
~回滚对循环计算的方式
2020-10-14 09:39:42 +08:00
juewuy
8dc3c3fdc2 v1.0.0beta14fix5
~优化节点保存方式,现在每10分钟检测一次,仅在检测到文件变动后方进行保存
~修复部分ssr节点不可用的bug
~mac过滤功能增加移除单个设备以及添加全部设备功能
~修复设置本机代理时直接跳出的bug
~优化安装脚本,增加root用户检测
~优化ipv6dns拦截方式
~回滚对循环计算的方式
2020-10-14 09:12:23 +08:00
juewuy
68e7519fdf v1.0.0beta14fix4
~优化节点保存方式,现在每10分钟检测一次,仅在检测到文件变动后方进行保存
~修复部分ssr节点不可用的bug
~mac过滤功能增加移除单个设备以及添加全部设备功能
~修复设置本机代理时直接跳出的bug
~优化安装脚本,增加root用户检测
~优化ipv6dns拦截方式
~修复部分设备开机启动显示不正常的bug
~修复部分设备时间显示不正常的bug
2020-10-13 17:25:04 +08:00
juewuy
fd267e6316 v1.0.0beta14fix4
~优化节点保存方式,现在每10分钟检测一次,仅在检测到文件变动后方进行保存
~修复部分ssr节点不可用的bug
~mac过滤功能增加移除单个设备以及添加全部设备功能
~修复设置本机代理时直接跳出的bug
~优化安装脚本,增加root用户检测
~优化ipv6dns拦截方式
~修复部分设备开机启动显示不正常的bug
~修复部分设备时间显示不正常的bug
2020-10-13 17:24:29 +08:00
juewuy
c1ac05fd36 v1.0.0beta14fix4
~修复部分ssr节点不可用的bug
~mac过滤功能增加移除单个设备以及添加全部设备功能
~修复设置本机代理时直接跳出的bug
~优化安装脚本,增加root用户检测
~优化ipv6dns拦截方式
~修复部分设备开机启动显示不正常的bug
~修复部分设备时间显示不正常的bug
2020-10-13 17:06:21 +08:00
juewuy
fc5dc18348 v1.0.0beta14fix4
~修复部分ssr节点不可用的bug
~mac过滤功能增加移除单个设备以及添加全部设备功能
~修复设置本机代理时直接跳出的bug
~优化安装脚本,增加root用户检测
~优化ipv6dns拦截方式
~修复部分设备开机启动显示不正常的bug
~修复部分设备时间显示不正常的bug
2020-10-12 17:17:30 +08:00
juewuy
94c0ed99ef v1.0.0beta14fix4
~修复部分ssr节点不可用的bug
~mac过滤功能增加移除单个设备以及添加全部设备功能
~修复设置本机代理时直接跳出的bug
~优化安装脚本,增加root用户检测
~优化ipv6dns拦截方式
2020-10-12 16:48:30 +08:00
juewuy
5598809f57 Update README.md 2020-10-12 15:01:35 +08:00
juewuy
9ea1fb7df6 Rename install.sh to install_cdn.sh 2020-10-12 10:40:35 +08:00
juewuy
f607cfbc70 Update install.sh 2020-10-12 10:38:05 +08:00
juewuy
8484ffae3b v1.0.0beta14fix3
~修复部分ssr节点不可用的bug
~mac过滤功能增加移除单个设备以及添加全部设备功能
~修复设置本机代理时直接跳出的bug
~优化安装脚本,增加root用户检测
2020-10-11 21:33:40 +08:00
juewuy
87ae8b78be v1.0.0beta14fix3
~修复部分ssr节点不可用的bug
~mac过滤功能增加移除单个设备以及添加全部设备功能
~修复设置本机代理时直接跳出的bug
~优化安装脚本,增加root用户检测
2020-10-11 21:30:20 +08:00
juewuy
156d9193ee v1.0.0beta14fix2
~修复部分ssr节点不可用的bug
~mac过滤功能增加移除单个设备以及添加全部设备功能
2020-10-11 13:08:02 +08:00
juewuy
12f3babe47 v1.0.0beta14fix1
~修复部分ssr节点不可用的bug
2020-10-11 00:03:03 +08:00
juewuy
1f00c32e5a v1.0.0beta14
~新增保存面板配置功能(每小时/手动停止服务时自动保存)
~同步最新1.2.0版本clash核心以及pre版核心
~同步最新版GeoIP数据库
~修改导入配置文件时的规则,现在会自动尝试最多5次
~修复了使用systemd无法正常启动进程的bug
~修复了导入未经转换配置文件时报错的bug
~屏蔽了部分已经无法使用的sub后端服务器地址
~修改了本机代理实现方式,现在会随着clash服务停止而取消
2020-10-10 17:07:14 +08:00
juewuy
cd8a885618 v1.0.0beta14
~新增保存面板配置功能(每小时/手动停止服务时自动保存)
~同步最新1.2.0版本clash核心以及pre版核心
~同步最新版GeoIP数据库
~修改导入配置文件时的规则,现在会自动尝试最多5次
~修复了使用systemd无法正常启动进程的bug
~修复了导入未经转换配置文件时报错的bug
~屏蔽了部分已经无法使用的sub后端服务器地址
~修改了本机代理实现方式,现在会随着clash服务停止而取消
2020-10-10 17:02:53 +08:00
juewuy
a33da9f15f v1.0.0beta14
~同步最新1.2.0版本clash核心以及pre版核心
~同步最新版GeoIP数据库
~修复了使用systemd无法正常启动进程的bug
~修复了导入未经转换配置文件时报错的bug
~屏蔽了部分已经无法使用的sub后端服务器地址
~修改了本机代理实现方式,现在会随着clash服务停止而取消
2020-10-10 09:00:23 +08:00
juewuy
cb413622eb v1.0.0beta13fix3
~修复了使用systemd无法正常启动进程的bug
2020-10-09 19:21:28 +08:00
35 changed files with 372 additions and 325 deletions

View File

@@ -1,12 +1,15 @@
# ShellClash原Clash for Miwifi
在Shell环境下一键部署及管理[Clash](https://github.com/Dreamacro/clash)
=====
功能简介:
--
~通过管理脚本在shell环境下便捷使用[Clash](https://github.com/Dreamacro/clash)<br>
~通过管理脚本在Shell环境下便捷使用[Clash](https://github.com/Dreamacro/clash)<br>
~支持在Shell环境下管理[Clash各种功能](https://lancellc.gitbook.io/clash)<br>
~支持批量导入SS/SSR/v2ray/trojan等节点链接及订阅链接<br>~支持配置定时任务,以及定时更新订阅<br>~支持使用以及安装网页面板管理规则组<br>
~支持批量导入[Clash](https://github.com/Dreamacro/clash)支持的节点链接及订阅链接<br>~支持配置定时任务,以及定时更新订阅<br>~支持在线安装及使用网页面板管理规则组<br>
~支持局域网透明代理/纯净模式等多种模式切换<br>~支持在线更新管理脚本及升级Clash核心<br>
设备支持:
@@ -14,24 +17,33 @@
~支持小米/红米全系使用官方系统或官方开发版系统的路由器设备<br>
~支持各种基于OpenWrt或使用OpenWrt二次定制开发的路由器设备<br>
~支持各种运行标准Linux系统如Debian/CenOS/Armbian等的设备<br>
——————————
~不支持使用Padavan以及梅林系统的路由器设备<br>
~支持各种运行标准Linux系统如Debian/CenOS/Armbian等的设备<br>~兼容Padavan固件保守模式、潘多拉固件<br>——————————
~暂不支持高恪、梅林等固件<br>
~更多设备支持请提issue或前往TG群反馈需提供设备名称及运行uname -a返回的设备核心信息<br>
使用方式:
--
~确认路由器或设备已经开启SSH并获取root权限<br>
~使用SSH连接工具如puttyJuiceSSH系统自带终端等路由器或设备的SSH管理界面并切换到root用户<br>
~在SSH界面执行如下安装命令并按照后续提示完成安装<br>
~确认设备已经安装curl如未安装LInux设备请[参考此处](https://www.howtoing.com/install-curl-in-linux)进行安装基于OpenWrt小米官方系统、潘多拉、高恪等的设备请使用如下命令安装<br>
```shell
opkg update && opkg install curl
```
~之后在SSH界面执行如下安装命令并按照后续提示完成安装<br>
~使用curl<br>
```Shell
#Release版本-github直连
sh -c "$(curl -kfsSl --resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master/install.sh)" && source /etc/profile &> /dev/null
#Release版本-jsdelivrCDN源
sh -c "$(curl -kfsSl https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master/install.sh)" && source /etc/profile &> /dev/null
#Test版本-github直连
sh -c "$(curl -kfsSl --resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master/install.sh)" -s 1 && source /etc/profile &> /dev/null
```
或者
```Shell
sh -c "$(curl -kfsSl https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master/install_cdn.sh)" && source /etc/profile &> /dev/null
```
~安装完成管理脚本后,执行如下命令以运行管理脚本<br>
```Shell

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1 +0,0 @@
version=1.1.0

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1 +0,0 @@
version=2020.09.27

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1 +0,0 @@
version=1.0.0

View File

@@ -1,4 +1,4 @@
GeoIP_v=20201001
clash_v=1.1.0
clashpre_v=2020.09.27
versionsh=1.0.0beta13fix2
clash_v=1.2.0
clashpre_v=2020.10.09
GeoIP_v=20201010
versionsh=1.0.0beta14fix5

View File

@@ -2,7 +2,7 @@
# Copyright (C) Juewuy
echo='echo -e' && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && echo=echo
test=1
[ -z "$1" ] && test=0 || test=$1
echo "***********************************************"
echo "** 欢迎使用 **"
@@ -10,18 +10,22 @@ echo "** ShellClash **"
echo "** by Juewuy **"
echo "***********************************************"
#检查root权限
[ "$USER" != "root" ] && [ "$USER" != "admin" ] && echo 请使用root用户执行安装&& exit 1
#检查更新
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash"
if [ $test -ge 1 ];then
if [ "$test" -gt 0 ];then
url="--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master"
[ $test -ge 2 ] && url="http://192.168.31.30:8080/clash-for-Miwifi"
[ $test -ge 3 ] && url="http://192.168.123.90:8080/clash-for-Miwifi"
[ "$test" -eq 2 ] && url="http://192.168.31.30:8080/clash-for-Miwifi" && echo $url
[ "$test" -eq 3 ] && url="http://192.168.123.90:8080/clash-for-Miwifi"
else
release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') #检查版本
fi
[ -z "$release_new" ] && release_new=$(curl -kfsSL $url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
[ -z "$release_new" ] && echo "无法连接服务器!" && exit
tarurl=$url@$release_new/bin/clashfm.tar.gz
[ $test -ge 1 ] && tarurl=$url/bin/clashfm.tar.gz
[ "$test" -gt 0 ] && tarurl=$url/bin/clashfm.tar.gz
gettar(){
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl)
[ "$result" != "200" ] && echo "文件下载失败!" && exit 1
@@ -39,7 +43,7 @@ gettar(){
mv $clashdir/clashservice /etc/init.d/clash
chmod 777 /etc/init.d/clash
else
[ -d /etc/systemd/system ] && sysdir=/etc/systemd/system
[ -d /etc/systemd/system/ ] && sysdir=/etc/systemd/system/
[ -d /usr/lib/systemd/system/ ] && sysdir=/usr/lib/systemd/system/
if [ -n "$sysdir" ];then
#设为systemd方式启动

View File

@@ -2,7 +2,7 @@
# Copyright (C) Juewuy
echo='echo -e' && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && echo=echo
test=0
[ -z "$1" ] && test=0 || test=$1
echo "***********************************************"
echo "** 欢迎使用 **"
@@ -10,18 +10,22 @@ echo "** ShellClash **"
echo "** by Juewuy **"
echo "***********************************************"
#检查root权限
[ "$USER" != "root" ] && [ "$USER" != "admin" ] && echo 请使用root用户执行安装&& exit 1
#检查更新
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash"
if [ $test -ge 1 ];then
if [ "$test" -gt 0 ];then
url="--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master"
[ $test -ge 2 ] && url="http://192.168.31.30:8080/clash-for-Miwifi"
[ $test -ge 3 ] && url="http://192.168.123.90:8080/clash-for-Miwifi"
[ "$test" -eq 2 ] && url="http://192.168.31.30:8080/clash-for-Miwifi" && echo $url
[ "$test" -eq 3 ] && url="http://192.168.123.90:8080/clash-for-Miwifi"
else
release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') #检查版本
fi
[ -z "$release_new" ] && release_new=$(curl -kfsSL $url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
[ -z "$release_new" ] && echo "无法连接服务器!" && exit
tarurl=$url@$release_new/bin/clashfm.tar.gz
[ $test -ge 1 ] && tarurl=$url/bin/clashfm.tar.gz
[ "$test" -gt 0 ] && tarurl=$url/bin/clashfm.tar.gz
gettar(){
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl)
[ "$result" != "200" ] && echo "文件下载失败!" && exit 1
@@ -39,7 +43,7 @@ gettar(){
mv $clashdir/clashservice /etc/init.d/clash
chmod 777 /etc/init.d/clash
else
[ -d /etc/systemd/system ] && sysdir=/etc/systemd/system
[ -d /etc/systemd/system/ ] && sysdir=/etc/systemd/system/
[ -d /usr/lib/systemd/system/ ] && sysdir=/usr/lib/systemd/system/
if [ -n "$sysdir" ];then
#设为systemd方式启动

View File

@@ -1,140 +0,0 @@
#! /bin/bash
# Copyright (C) Juewuy
echo='echo -e' && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && echo=echo
test=1
echo "***********************************************"
echo "** 欢迎使用 **"
echo "** ShellClash **"
echo "** by Juewuy **"
echo "***********************************************"
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash"
if [ $test -ge 1 ];then
url="--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master"
[ $test -ge 2 ] && url="http://192.168.31.30:8080/clash-for-Miwifi"
[ $test -ge 3 ] && url="http://192.168.123.90:8080/clash-for-Miwifi"
else
release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') #检查版本
fi
[ -z "$release_new" ] && release_new=$(curl -kfsSL $url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
[ -z "$release_new" ] && echo "无法连接服务器!" && exit
tarurl=$url@$release_new/bin/clashfm.tar.gz
[ $test -ge 1 ] && tarurl=$url/bin/clashfm.tar.gz
gettar(){
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl)
[ "$result" != "200" ] && echo "文件下载失败!" && exit 1
#解压
echo -----------------------------------------------
echo 开始解压文件!
mkdir -p $clashdir > /dev/null
tar -zxvf '/tmp/clashfm.tar.gz' -C $clashdir/
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
#初始化文件目录
[ -f "$clashdir/mark" ] || echo '#标识clash运行状态的文件不明勿动' > $clashdir/mark
#判断系统类型写入不同的启动文件
if [ -f /etc/rc.common ];then
#设为init.d方式启动
mv $clashdir/clashservice /etc/init.d/clash
chmod 777 /etc/init.d/clash
else
[ -d /etc/systemd/system ] && sysdir=/etc/systemd/system
[ -d /usr/lib/systemd/system/ ] && sysdir=/usr/lib/systemd/system/
if [ -n "$sysdir" ];then
#设为systemd方式启动
mv $clashdir/clash.service $sysdir/clash.service
sed -i "s%/etc/clash%$clashdir%g" $sysdir/clash.service
systemctl daemon-reload
rm -rf /etc/init.d/clash
else
#设为保守模式启动
sed -i '/start_old=*/'d $clashdir/mark
sed -i "1i\start_old=已开启" $clashdir/mark
fi
fi
#修饰文件及版本号
shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash
sed -i "s%#!/bin/sh%#!/bin/$shtype%g" $clashdir/start.sh
chmod 777 $clashdir/start.sh
sed -i '/versionsh_l=*/'d $clashdir/mark
sed -i "1i\versionsh_l=$release_new" $clashdir/mark
#设置环境变量
sed -i '/alias clash=*/'d /etc/profile
echo "alias clash=\"$shtype $clashdir/clash.sh\"" >> /etc/profile #设置快捷命令环境变量
sed -i '/export clashdir=*/'d /etc/profile
echo "export clashdir=\"$clashdir\"" >> /etc/profile #设置clash路径环境变量
#删除临时文件
rm -rf /tmp/clashfm.tar.gz
rm -rf $clashdir/clashservice
rm -rf $clashdir/clash.service
}
#下载及安装
install(){
echo -----------------------------------------------
echo 开始从服务器获取安装文件!
echo -----------------------------------------------
gettar
echo -----------------------------------------------
echo ShellClash 已经安装成功!
echo -----------------------------------------------
$echo "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理\033[0m"
echo -----------------------------------------------
}
setdir(){
echo -----------------------------------------------
$echo "\033[32m 1 在默认目录(/etc)安装"
$echo "\033[33m 2 手动设置安装目录"
$echo "\033[0m 0 退出安装"
echo -----------------------------------------------
read -p "请输入相应数字 > " num
#设置目录
if [ -z $num ];then
echo 安装已取消
exit;
elif [ "$num" = "1" ];then
dir=/etc
elif [ "$num" = "2" ];then
echo -----------------------------------------------
echo '可用路径 剩余空间:'
df -h | awk '{print $6,$2}'| sed 1d
echo '路径是必须带 / 的格式,写入虚拟内存(/tmp,/sys,..)的文件会在重启后消失!!!'
read -p "请输入自定义路径 > " dir
if [ -z "$dir" ];then
$echo "\033[31m路径错误已取消安装\033[0m"
exit;
fi
else
echo 安装已取消!!!
exit;
fi
clashdir=$dir/clash
install
}
#输出
$echo "最新版本:\033[32m$release_new\033[0m"
echo -----------------------------------------------
$echo "\033[44m如遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
$echo "\033[37m支持各种基于openwrt的路由器设备"
$echo "\033[33m支持Debian、Centos等标准Linux系统\033[0m"
if [ -n "$clashdir" ];then
echo -----------------------------------------------
$echo "检测到旧的安装目录\033[36m$clashdir\033[0m是否覆盖安装"
$echo "\033[32m覆盖安装时不会移除配置文件\033[0m"
read -p "覆盖安装/卸载旧版本?(1/0) > " res
if [ "$res" = "1" ];then
install
elif [ "$res" = "0" ];then
rm -rf $clashdir
echo -----------------------------------------------
$echo "\033[31m 旧版本文件已卸载!\033[0m"
setdir
else
$echo "\033[31m输入错误已取消安装\033[0m"
exit;
fi
else
setdir
fi

View File

@@ -22,7 +22,7 @@ source $ccfg
[ ! -f $clashdir/mac ] && touch $clashdir/mac
#开机自启相关
if [ -f /etc/rc.common ];then
if [ -f /etc/rc.d/*clash ];then
if [ -n "$(find /etc/rc.d -name '*clash')" ];then
autostart=enable_rc
else
autostart=disable_rc
@@ -62,12 +62,13 @@ if [ -n "$PID" ];then
VmRSS=`cat /proc/$PID/status|grep -w VmRSS|awk '{print $2,$3}'`
#获取运行时长
if [ -n "$start_time" ]; then
time=$((`date +%s`-$start_time))
day=$(($time/86400))
if [[ $day != 0 ]]; then
day=$day天
else
time=$((`date +%s`-start_time))
day=$((time/86400))
#day=$(expr $time / 86400)
if [ "$day" = "0" ]; then
day=""
else
day="$day""天"
fi
time=`date -u -d @${time} +%H小时%M分%S秒`
fi
@@ -122,8 +123,8 @@ start_over(){
echo -e "可使用\033[30;47m http://clash.razord.top \033[0m管理内置规则"
echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m $db_port \033[0m"
echo -e "也可前往更新菜单安装本地Dashboard面板连接更稳定\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fi
echo -----------------------------------------------
}
setport(){
inputport(){
@@ -192,7 +193,7 @@ setport(){
}
checkport(){
for portx in $dns_port $mix_port $redir_port $db_port ;do
if [ -n "$(netstat -ntul |grep :$portx)" ];then
if [ -n "$(netstat -ntul 2>&1 |grep :$portx)" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "检测到端口【$portx】被以下进程占用clash可能无法正常启动\033[33m"
echo $(netstat -ntulp | grep :$portx | head -n 1)
@@ -206,16 +207,16 @@ checkport(){
}
clashstart(){
if [ ! -f "$yaml" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -----------------------------------------------
echo -e "\033[31m没有找到配置文件请先导入配置文件\033[0m"
clashlink
fi
if [ -n "$PID" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -----------------------------------------------
$clashdir/start.sh stop
echo -e "\033[31mClash服务已停止\033[0m"
fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -----------------------------------------------
$clashdir/start.sh start
sleep 1
PID=$(pidof clash)
@@ -238,15 +239,17 @@ if [ -z "$server_link" ]; then
server_link=1
fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m 欢迎使用订阅功能!\033[0m"
echo -e "\033[30;47m 欢迎使用导入配置文件功能!\033[0m"
echo -----------------------------------------------
echo -e " 1 在线导入\033[36m订阅\033[0m配置文件"
echo -e " 2 在线导入clash配置文件"
echo -e " 3 添加/修改\033[32m节点过滤\033[0m关键字 \033[47;30m$exclude\033[0m"
echo -e " 4 选取\033[33mclash配置规则\033[0m模版"
echo -e " 5 选择在线生成服务器"
echo -e " 6 \033[36m还原\033[0m配置文件"
echo -e " 7 \033[32m手动更新\033[0m订阅"
echo -e " 1 在线导入\033[36m订阅\033[0m并生成Clash配置文件"
echo -e " 2 在线导入\033[33mClash\033[0m配置文件"
echo -e " 3 设置\033[31m节点过滤\033[0m关键字 \033[47;30m$exclude\033[0m"
echo -e " 4 设置\033[32m节点筛选\033[0m关键字 \033[47;30m$include\033[0m"
echo -e " 5 选取\033[33mClash配置规则\033[0m在线模版"
echo -e " 6 选择在线生成服务器-subconverter"
echo -e " 7 \033[36m还原\033[0m之前的配置文件"
echo -e " 8 \033[33m手动更新\033[0m配置文件"
echo -e " 9 设置\033[36m自动更新\033[0m配置文件"
echo -----------------------------------------------
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
@@ -293,15 +296,20 @@ elif [[ $num == 3 ]];then
elif [[ $num == 4 ]];then
source $clashdir/getdate.sh
linkconfig
linkfilter2
clashlink
elif [[ $num == 5 ]];then
source $clashdir/getdate.sh
linkserver
linkconfig
clashlink
elif [[ $num == 6 ]];then
source $clashdir/getdate.sh
linkserver
clashlink
elif [[ $num == 7 ]];then
yamlbak=$yaml.bak
if [ ! -f "$yaml".bak ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -321,7 +329,7 @@ elif [[ $num == 6 ]];then
fi
clashsh
elif [[ $num == 7 ]];then
elif [[ $num == 8 ]];then
if [ -z "$Url" -a -z "$Https" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m没有找到你的订阅链接请先输入链接\033[0m"
@@ -340,6 +348,10 @@ elif [[ $num == 7 ]];then
fi
clashlink
fi
elif [[ $num == 9 ]];then
clashcron
elif [[ $num == 0 ]];then
clashsh
else
@@ -348,6 +360,105 @@ else
exit;
fi
}
macfilter(){
add_mac(){
echo -----------------------------------------------
echo -e "\033[33m序号 设备IP 设备mac地址 设备名称\033[32m"
cat /tmp/dhcp.leases | awk '{print " "NR" "$3,$2,$4}'
echo -e "\033[0m 0-----------------------------------------------"
echo -e " 0 或回车 结束添加"
read -p "请输入需要添加的设备的对应序号 > " num
if [ -z "$num" ]||[ "$num" -le 0 ]; then
macfilter
elif [ $num -le $(cat /tmp/dhcp.leases | awk 'END{print NR}') ]; then
macadd=$(cat /tmp/dhcp.leases | awk '{print $2}' | sed -n "$num"p)
if [ -z "$(cat $clashdir/mac | grep -E "$macadd")" ];then
echo $macadd >> $clashdir/mac
echo -----------------------------------------------
echo 已添加的mac地址
cat $clashdir/mac
else
echo -----------------------------------------------
echo -e "\033[31m已添加的设备请勿重复添加\033[0m"
fi
else
echo -----------------------------------------------
echo -e "\033[31m输入有误请重新输入\033[0m"
fi
add_mac
}
del_mac(){
echo -----------------------------------------------
if [ -z "$(cat $clashdir/mac)" ];then
echo -e "\033[31m列表中没有需要移除的设备\033[0m"
macfilter
fi
echo -e "\033[33m序号 设备IP 设备mac地址 设备名称\033[0m"
i=1
for mac in $(cat $clashdir/mac); do
echo -e " $i \033[32m$(cat /tmp/dhcp.leases | awk '{print $3,$2,$4}' | grep $mac)\033[0m"
i=$((i+1))
done
echo -----------------------------------------------
echo -e "\033[0m 0 或回车 结束删除"
read -p "请输入需要移除的设备的对应序号 > " num
if [ -z "$num" ]||[ "$num" -le 0 ]; then
macfilter
elif [ $num -le $(cat $clashdir/mac | wc -l) ];then
sed -i "${num}d" $clashdir/mac
echo -----------------------------------------------
echo -e "\033[32m对应设备已移除\033[0m"
else
echo -----------------------------------------------
echo -e "\033[31m输入有误请重新输入\033[0m"
fi
del_mac
}
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m请在此添加或移除设备\033[0m"
if [ -n "$(cat $clashdir/mac)" ]; then
echo -----------------------------------------------
echo -e "当前已过滤设备为:\033[36m"
echo -e "\033[33m 设备IP 设备mac地址 设备名称\033[0m"
for mac in $(cat $clashdir/mac); do
cat /tmp/dhcp.leases | awk '{print $3,$2,$4}' | grep $mac
done
echo -----------------------------------------------
fi
echo -e " 1 \033[31m清空整个列表\033[0m"
echo -e " 2 \033[32m添加指定设备\033[0m"
echo -e " 3 \033[33m移除指定设备\033[0m"
echo -e " 4 \033[32m添加全部设备\033[0m(请搭配移除指定设备使用)"
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
if [ -z "$num" ]; then
echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字\033[0m"
clashcfg
elif [[ $num == 0 ]]; then
clashcfg
elif [[ $num == 1 ]]; then
:>$clashdir/mac
echo -----------------------------------------------
echo -e "\033[31m设备列表已清空\033[0m"
macfilter
elif [[ $num == 2 ]]; then
add_mac
elif [[ $num == 3 ]]; then
del_mac
elif [[ $num == 4 ]]; then
echo -----------------------------------------------
cat /tmp/dhcp.leases | awk '{print $2}' > $clashdir/mac
echo -e "\033[32m已经将所有设备全部添加进过滤列表\033[0m"
echo -e "\033[33m请搭配【移除指定设备】功能使用\033[0m"
sleep 1
macfilter
else
echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字\033[0m"
macfilter
fi
}
clashcfg(){
#获取设置默认显示
[ -z "$skip_cert" ] && skip_cert=已开启
@@ -386,13 +497,13 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -----------------------------------------------
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 " 适合非游戏用户使用"
echo " 2 Tun模式 支持UDP转发且延迟低"
echo " CPU占用极高只支持fake-ip模式"
echo " 适合游戏用户、非大流量用户"
echo " 3 混合模式: 使用redir转发TCPTun转发UPD"
echo " 速度较快,内存占用高"
echo " 适合游戏用户、综合用户"
echo " 4 纯净模式: 不设置iptables静态路由"
echo " 必须手动配置http/sock5代理"
echo " 0 返回上级菜单"
@@ -509,67 +620,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
clashcfg
elif [[ $num == 5 ]]; then
add_mac(){
echo -----------------------------------------------
echo -e "\033[33m序号 设备IP 设备mac地址 设备名称\033[32m"
cat /tmp/dhcp.leases | awk '{print " "NR" "$3,$2,$4}'
echo -e "\033[0m 0 或回车 结束添加"
read -p "请输入对应序号 > " num
if [ -z "$num" ]; then
clashcfg
elif [ $num -le 0 ]; then
clashcfg
elif [ $num -le $(cat /tmp/dhcp.leases | awk 'END{print NR}') ]; then
macadd=$(cat /tmp/dhcp.leases | awk '{print $2}' | sed -n "$num"p)
if [ -z "$(cat $clashdir/mac | grep -E "$macadd")" ];then
echo $macadd >> $clashdir/mac
echo -----------------------------------------------
echo 已添加的mac地址
cat $clashdir/mac
else
echo -----------------------------------------------
echo -e "\033[31m已添加的设备请勿重复添加\033[0m"
fi
else
echo -----------------------------------------------
echo -e "\033[31m输入有误请重新输入\033[0m"
fi
add_mac
}
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m请在此添加或移除设备\033[0m"
if [ -n "$(cat $clashdir/mac)" ]; then
echo -e "当前已过滤设备为:\033[36m"
for mac in $(cat $clashdir/mac); do
cat /tmp/dhcp.leases | awk '{print $3,$2,$4}' | grep $mac
done
echo -e "\033[0m-----------------------------------------------"
fi
echo -e " 1 \033[31m清空列表\033[0m"
echo -e " 2 \033[32m添加设备\033[0m"
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
if [ -z "$num" ]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashcfg
elif [[ $num == 0 ]]; then
clashcfg
elif [[ $num == 1 ]]; then
:>$clashdir/mac
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m设备列表已清空\033[0m"
sleep 1
clashcfg
elif [[ $num == 2 ]]; then
add_mac
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
clashcfg
fi
macfilter
elif [[ $num == 6 ]]; then
sed -i '/dns_over*/'d $ccfg
@@ -686,18 +737,16 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
if [ "$local_proxy" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\local_proxy=已开启" $ccfg
local_proxy=已开启
source $clashdir/start.sh
set_proxy
$clashdir/start.sh set_proxy $mix_port
echo -e "\033[32m已经将代理参数写入环境变量~\033[0m"
echo -e "\033[36m如未生效请重新登录或者重启设备\033[0m"
sleep 1
echo -e "\033[36m如未生效请重新启动终端或重新连接SSH\033[0m"
else
sed -i "1i\local_proxy=未开启" $ccfg
local_proxy=未开启
source $clashdir/start.sh
unset_proxy
$clashdir/start.sh unset_proxy
echo -e "\033[33m已经将代理参数从环境变量移除\033[0m"
fi
sleep 1
clashadv
elif [[ $num == 5 ]]; then
setport
@@ -1117,4 +1166,24 @@ else
fi
exit 1
}
clashsh
[ -z "$1" ] && clashsh
case "$1" in
-h)
echo -----------------------------------------
echo "欢迎使用ShellClash"
echo -----------------------------------------
echo " -t 测试模式"
echo " -h 帮助列表"
echo -----------------------------------------
echo "在线求助t.me/clashfm"
echo "官方博客juewuy.github.io"
echo "发布页面github.com/juewuy/ShellClash"
echo -----------------------------------------
;;
-t)
shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash
$shtype -x $clashdir/clash.sh
;;
esac

View File

@@ -24,7 +24,7 @@ read -p "请输入对应数字 > " num
if [ -z "$num" ] || [[ $num -gt 13 ]];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
elif [[ "$num" = 0 ]];then
elif [[ "$num" = "0" ]];then
echo
elif [[ $num -le 13 ]];then
#将对应标记值写入mark
@@ -68,7 +68,7 @@ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[44m 实验性功能遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
echo -e "\033[33m当前过滤关键字\033[47;30m$exclude\033[0m"
echo -----------------------------------------------
echo -e "\033[36m匹配关键字的节点会在导入时被屏蔽\033[0m"
echo -e "\033[33m匹配关键字的节点会在导入时被屏蔽】!!!\033[0m"
echo -e "多个关键字可以用\033[30;47m | \033[0m号分隔"
echo -e "\033[32m支持正则表达式\033[0m空格请使用\033[30;47m + \033[0m号替代"
echo -----------------------------------------------
@@ -87,6 +87,31 @@ sed -i '/exclude=*/'d $ccfg
sed -i "1i\exclude=\'$exclude\'" $ccfg
linkset
}
linkfilter2(){
[ -z "$include" ] && include="未设置"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[44m 实验性功能遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
echo -e "\033[33m当前筛选关键字\033[47;30m$include\033[0m"
echo -----------------------------------------------
echo -e "\033[33m仅有匹配关键字的节点才会被【导入】\033[0m"
echo -e "多个关键字可以用\033[30;47m | \033[0m号分隔"
echo -e "\033[32m支持正则表达式\033[0m空格请使用\033[30;47m + \033[0m号替代"
echo -----------------------------------------------
echo -e " 000 \033[31m删除\033[0m关键字"
echo -e " 回车 取消输入并返回上级菜单"
echo -----------------------------------------------
read -p "请输入关键字 > " include
if [ -z "$include" ]; then
linkset
elif [ "$include" = '000' ]; then
echo -----------------------------------------------
include=''
echo -e "\033[31m 已删除节点匹配关键字!!!\033[0m"
fi
sed -i '/include=*/'d $ccfg
sed -i "1i\include=\'$include\'" $ccfg
linkset
}
linkset(){
if [ -n "$Url" ];then
[ -z "$skip_cert" ] && skip_cert=已开启
@@ -94,11 +119,12 @@ if [ -n "$Url" ];then
echo -e "\033[47;30m请检查输入的链接是否正确\033[0m"
echo -e "\033[32;4m$Url\033[0m"
echo -----------------------------------------------
echo -e " 1 \033[32m生成配置文件原文件将被备份\033[0m"
echo -e " 2 \033[36m添加/修改节点过滤关键字 \033[47;30m$exclude\033[0m"
echo -e " 3 \033[33m选取配置规则模版\033[0m"
echo -e " 4 \033[0m选取在线生成服务器\033[0m"
echo -e " 5 \033[0m跳过本地证书验证: \033[36m$skip_cert\033[0m ————自建tls节点务必开启"
echo -e " 1 \033[36m生成配置文件\033[0m(原文件将被备份)"
echo -e " 2 设置\033[31m节点过滤\033[0m关键字 \033[47;30m$exclude\033[0m"
echo -e " 3 设置\033[32m节点筛选\033[0m关键字 \033[47;30m$include\033[0m"
echo -e " 4 选取在线\033[33m配置规则模版\033[0m"
echo -e " 5 \033[0m选取在线生成服务器\033[0m"
echo -e " 6 \033[0m跳过本地证书验证 \033[36m$skip_cert\033[0m ————自建tls节点务必开启"
echo -----------------------------------------------
echo -e " 0 \033[31m取消导入\033[0m并返回上级菜单"
echo -----------------------------------------------
@@ -121,12 +147,15 @@ if [ -n "$Url" ];then
linkfilter
linkset
elif [ "$num" = '3' ]; then
linkconfig
linkfilter2
linkset
elif [ "$num" = '4' ]; then
linkserver
linkconfig
linkset
elif [ "$num" = '5' ]; then
linkserver
linkset
elif [ "$num" = '6' ]; then
sed -i '/skip_cert*/'d $ccfg
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$skip_cert" = "未开启" ] > /dev/null 2>&1; then
@@ -154,14 +183,14 @@ while [ $i -le 99 ]
do
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[44m 遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
echo -e "\033[31m本功能依赖第三方网站在线服务实现脚本本身不提供任何代理服务033[0m"
echo -e "\033[31m本功能依赖第三方网站在线服务实现脚本本身不提供任何代理服务\033[0m"
echo -----------------------------------------------
echo -e "支持批量导入订阅文件的在线链接"
echo -----------------------------------------------
echo -e " 0 \033[31m撤销输入\033[0m"
echo -e "回车 \033[32m完成输入\033[0m并\033[33m开始导入\033[0m配置文件"
echo -----------------------------------------------
read -p "请输入第"$i"个链接 > " url
read -p "请输入第${i}个链接 > " url
test=$(echo $url | grep "://")
url=`echo ${url/\ \(*\)/''}` #删除恶心的超链接内容
url=`echo ${url/*\&url\=/""}` #将clash完整链接还原成单一链接
@@ -173,7 +202,7 @@ do
else
Url="$Url"\|"$url"
fi
i=$(($i+1))
i=$((i+1))
elif [ -z "$url" ];then
[ -n "$Url" ] && linkset
elif [[ $url == 0 ]];then
@@ -295,39 +324,45 @@ if [ "$res" = '1' ]; then
fi
}
getcore(){
#source $ccfg
#获取核心及版本信息
if [ ! -f $clashdir/clash ]; then
clashcore=没有安装核心!
clashv=''
fi
clashcore_n=$clashcore
[ ! -f $clashdir/clash ] && clashcore="未安装核心"
#获取设备处理器架构
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.*aarch64.*|linux.*armv8.*")" ] && cpucore="armv8"
[ -n "$(echo $cputype | grep -E "linux.*x86.*")" ] && cpucore="386"
[ -n "$(echo $cputype | grep -E "linux.*x86_64.*")" ] && cpucore="amd64"
if [ -n "$(echo $cputype | grep -E "linux.*mips.*")" ];then
getcputype(){
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.*aarch64.*|linux.*armv8.*")" ] && cpucore="armv8"
[ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="386"
[ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="amd64"
if [ -n "$(echo $cputype | grep -E "linux.*mips.*")" ];then
mipstype=$(echo -n I | hexdump -o | awk '{ print substr($2,6,1); exit}') #通过判断大小端判断mips或mipsle
if [ "$mipstype" = "1" ];then
cpucore="mipsle-softfloat"
[ -n "$(uname -a | grep -E "M2100")" ] && cpucore="mipsle-hardfloat"
fi
#[ -n "$(uname -a | grep -E "M2100")" ] && cpucore="mipsle-hardfloat"
else
cpucore="mips-softfloat"
fi
fi
}
###
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ -z "$cpucore" ] && getcputype
echo -e "当前clash核心\033[47;30m $clashcore \033[46;30m$clashv\033[0m"
echo -e "\033[32m请选择需要下载的核心版本\033[0m"
echo -e "当前系统处理器架构:\033[32m $cpucore \033[0m"
echo -e "\033[33m请选择需要下载的核心版本\033[0m"
echo -----------------------------------------------
echo "1 clash 稳定,内存占用小,推荐!"
echo "(官方正式版) 不支持Tun模式、混合模式"
echo
echo "2 clashpre 支持Tun模式、混合模式"
echo "(高级预览版) 内存占用更高"
echo
echo "3 手动指定处理器架构"
echo -----------------------------------------------
echo 0 返回上级菜单
read -p "请输入对应数字 > " num
if [ -z "$num" ]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字\033[0m"
update
elif [[ $num == 0 ]]; then
@@ -339,10 +374,23 @@ read -p "请输入对应数字 > " num
clashcore=clashpre
version=$clashpre_v
elif [[ $num == 3 ]]; then
clashcore=clashr
version='已停止更新'
cpucore_list="armv5 armv7 armv8 386 amd64 mipsle-softfloat mipsle-hardfloat mips-softfloat"
echo -----------------------------------------------
echo -e "\033[31m仅适合脚本无法正确识别核心或核心无法正常运行时使用\033[0m"
echo -e "当前可供在线下载的处理器架构为:"
echo -e "\033[32m$cpucore_list\033[0m"
echo -e "如果您的CPU架构未在以上列表中请运行【uname -a】命令,并复制好返回信息"
echo -e "之后前往 t.me/clashfm 群提交或 github.com/juewuy/ShellClash 提交issue"
echo -----------------------------------------------
read -p "请手动输入处理器架构 > " cpucore
if [ -z "$(echo $cpucore_list |grep "$cpucore")" ];then
echo -e "\033[31m请输入正确的处理器架构\033[0m"
sleep 1
cpucore=""
fi
getcore
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -----------------------------------------------
echo -e "\033[31m请输入正确的数字\033[0m"
update
fi

View File

@@ -51,7 +51,7 @@ EOF`
#如果传来的是Url链接则合成Https链接否则直接使用Https链接
if [ -z "$Https" ];then
#echo $Url
Https="https://$Server/sub?target=clashr&insert=true&new_name=true&scv=true&exclude=$exclude&url=$Url&config=$Config"
Https="https://$Server/sub?target=clash&insert=true&new_name=true&scv=true&exclude=$exclude&include=$include&url=$Url&config=$Config"
markhttp=1
fi
#
@@ -77,16 +77,19 @@ if [ "$result" != "200" ];then
echo -e "\033[31m请尝试使用【导入节点/链接】功能!\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit 1
else
read -p "是否更换后端地址后重试?[1/0] > " res
if [ "$res" = '1' ]; then
if [ "$retry" -ge 5 ];then
echo -e "\033[32m无法获取配置文件请检查链接格式以及网络连接状态\033[0m"
exit 1
else
retry=$((retry+1))
echo -e "\033[32m尝试使用其他服务器获取配置\033[0m"
echo -e "\033[33m正在尝试第$retry次/共5次\033[0m"
sed -i '/server_link=*/'d $ccfg
if [[ $server_link -ge 6 ]]; then
if [ "$server_link" -ge 5 ]; then
server_link=0
fi
server_link=$(($server_link + 1))
echo $server_link
server_link=$((server_link+1))
sed -i "1i\server_link=$server_link" $ccfg
Https=""
getyaml
@@ -158,7 +161,7 @@ external="external-controller: 0.0.0.0:$db_port"
exper='experimental: {ignore-resolve-fail: true, interface-name: en0}'
#dns配置
if [ "$dns_mod" = "fake-ip" ];then
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"], nameserver: [114.114.114.114, 127.0.0.1:53], fallback: [tcp://1.0.0.1, 8.8.4.4], fallback-filter: {geoip: true}}'
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"], nameserver: [114.114.114.114, 223.5.5.5, 127.0.0.1:53], fallback: [tcp://1.0.0.1, 8.8.4.4], fallback-filter: {geoip: true}}'
elif [ "$dns_over" = "已开启" ];then
dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, enhanced-mode: redir-host, nameserver: [114.114.114.114, 223.5.5.5], fallback: [1.0.0.1, 8.8.4.4], fallback-filter: {geoip: true}}'
else
@@ -169,7 +172,7 @@ fi
yaml=$clashdir/config.yaml
#预删除需要添加的项目
i=$(grep -n "^proxies:" $clashdir/config.yaml | head -1 | cut -d ":" -f 1)
i=$(($i-1))
i=$((i-1))
sed -i "1,${i}d" $yaml
#添加配置
sed -i "1imixed-port:\ $mix_port" $yaml
@@ -214,7 +217,7 @@ start_redir(){
iptables -t nat -A clash -p tcp $ports-j REDIRECT --to-ports $redir_port
iptables -t nat -A PREROUTING -p tcp -j clash
#设置ipv6转发
if [ "$ipv6_support" = "已开启" ];then
if [ -n "ip6_nat" -a "$ipv6_support" = "已开启" ];then
ip6tables -t nat -N clashv6
for mac in $(cat $clashdir/mac); do
ip6tables -t nat -A clashv6 -m mac --mac-source $mac -j RETURN
@@ -261,8 +264,8 @@ start_dns(){
iptables -t nat -I PREROUTING -p tcp -d 8.8.8.8 -j clash_dns
iptables -t nat -I PREROUTING -p tcp -d 8.8.4.4 -j clash_dns
#ipv6DNS
ip6_nat=$(ip6tables -t nat -L 2>&1|grep -o 'not exist')
if [ -z "ip6_nat" ];then
ip6_nat=$(ip6tables -t nat -L 2>&1|grep -o 'Chain')
if [ -n "ip6_nat" ];then
ip6tables -t nat -N clashv6_dns > /dev/null 2>&1
for mac in $(cat $clashdir/mac); do
ip6tables -t nat -A clashv6_dns -m mac --mac-source $mac -j RETURN > /dev/null 2>&1
@@ -270,7 +273,8 @@ start_dns(){
ip6tables -t nat -A clashv6_dns -p udp --dport 53 -j REDIRECT --to $dns_port > /dev/null 2>&1
ip6tables -t nat -A PREROUTING -p udp -j clashv6_dns > /dev/null 2>&1
else
ip6tables -I INPUT -p tcp --dport 53 -j DROP
ip6tables -I INPUT -p tcp --dport 53 -j REJECT
ip6tables -I INPUT -p udp --dport 53 -j REJECT
fi
}
daemon(){
@@ -282,17 +286,44 @@ daemon(){
echo 请进入定时任务菜单手动指定系统定时任务文件路径!!!
fi
}
set_proxy(){
echo 'export http_proxy=http://127.0.0.1:'"$mix_port" >> /etc/profile
echo 'export https_proxy=$http_proxy' >> /etc/profile
echo 'export HTTP_PROXY=$http_proxy' >> /etc/profile
echo 'export HTTPS_PROXY=$http_proxy' >> /etc/profile
source /etc/profile > /dev/null 2>&1
web_save(){
#使用curl获取面板节点设置
curl -s -H "Authorization: Bearer ${secret}" -H "Content-Type:application/json" http://localhost:${db_port}/proxies | awk -F "{" '{for(i=1;i<=NF;i++) print $i}' | grep -E '^"all".*"Selector"' | grep -oE '"name".*"now".*",' | sed 's/"name"://g' | sed 's/"now"://g'| sed 's/"//g' > /tmp/clash_web_save
#对比文件,如果有变动则写入磁盘,否则清除缓存
if [ "$(cat /tmp/clash_web_save)" = "$(cat $clashdir/web_save 2>/dev/null)" ];then
rm -rf /tmp/clash_web_save
else
mv -f /tmp/clash_web_save $clashdir/web_save
fi
}
unset_proxy(){
sed -i '/http*_proxy/'d /etc/profile
sed -i '/HTTP*_PROXY/'d /etc/profile
source /etc/profile > /dev/null 2>&1
web_restore(){
#设置循环检测clash面板端口
i=1
while [ $i -lt 10 ]
do
sleep 1
[ -n "$(curl -s http://localhost:${db_port})" ] && i=10
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)
curl -sS -X PUT -H "Authorization: Bearer ${secret}" -H "Content-Type:application/json" http://localhost:${db_port}/proxies/"${group_name}" -d "{\"name\":\"${now_name}\"}" >/dev/null
done
exit 0
}
web_save_auto(){
if [ -n "$cronpath" ];then
if [ -z "$(cat $cronpath | grep '保存节点配置')" ];then
echo '*/10 * * * * test -n "$(pidof clash)" && /etc/init.d/clash web_save #每10分钟保存节点配置' >> $cronpath
chmod 600 $cronpath
fi
else
echo 找不到定时任务配置文件,无法添加守护进程!
echo 请进入定时任务菜单手动指定系统定时任务文件路径!!!
fi
}
afstart(){
#读取配置文件
@@ -304,7 +335,11 @@ afstart(){
#标记启动时间
mark_time
#设置本机代理
[ "$local_proxy" = "已开启" ] && set_proxy
[ "$local_proxy" = "已开启" ] && $0 set_proxy $mix_port
#启用面板配置自动保存
web_save_auto
#后台还原面板配置
[ -f $clashdir/web_save ] && web_restore &
}
case "$1" in
@@ -320,6 +355,7 @@ start)
#使用不同方式启动clash服务
if [ "$start_old" = "已开启" ];then
$clashdir/clash -d $clashdir >/dev/null 2>&1 &
sleep 1
daemon
afstart
elif [ -f /etc/rc.common ];then
@@ -331,8 +367,11 @@ start)
stop)
#读取配置文件
getconfig
#删除守护进程
#保存面板配置
web_save
#删除守护进程&面板配置自动保存
sed -i /clash保守模式守护进程/d $cronpath >/dev/null 2>&1
sed -i /面板配置自动保存/d $cronpath >/dev/null 2>&1
#多种方式结束进程
if [ -f /etc/rc.common ];then
/etc/init.d/clash stop >/dev/null 2>&1
@@ -343,7 +382,7 @@ stop)
#清理iptables
stop_iptables
#禁用本机代理
[ "$local_proxy" = "已开启" ] && unset_proxy
[ "$local_proxy" = "已开启" ] && $0 unset_proxy
;;
restart)
$0 stop
@@ -356,4 +395,18 @@ getyaml)
daemon)
daemon
;;
web_save)
getconfig
web_save
;;
set_proxy)
echo 'export all_proxy=http://127.0.0.1:'"$2" >> /etc/profile
echo 'export ALL_PROXY=$all_proxy' >> /etc/profile
;;
unset_proxy)
sed -i '/all_proxy/'d /etc/profile
sed -i '/ALL_PROXY/'d /etc/profile
;;
esac
exit 0