36 Commits

Author SHA1 Message Date
juewuy
de77a9b821 v1.0.0beta7
~全面兼容Debian/Armbian/Centos等标准Linux系统
~增加配置本机代理功能
~重写启动脚本,优化在不同系统下的启动方式
~支持以systemd方式启动及守护进程
~~大幅度优化优化安装脚本及更新机制,修复cdn更新延迟
~修改定时任务机制,增加稳定性
2020-09-19 16:54:05 +08:00
juewuy
78b8c0ac82 v1.0.0beta7
~全面兼容Debian/Armbian/Centos等标准Linux系统
~增加配置本机代理功能
~重写启动脚本,优化在不同系统下的启动方式
~支持以systemd方式启动及守护进程
~~大幅度优化优化安装脚本及更新机制,修复cdn更新延迟
~修改定时任务机制,增加稳定性
2020-09-19 16:51:34 +08:00
juewuy
a21c767300 v1.0.0beta7
~全面兼容Debian/Armbian/Centos等标准Linux系统
~增加配置本机代理功能
~重写启动脚本,优化在不同系统下的启动方式
~支持以systemd方式启动及守护进程
~~大幅度优化优化安装脚本及更新机制,修复cdn更新延迟
~修改定时任务机制,增加稳定性
2020-09-19 16:46:22 +08:00
juewuy
307e490dd4 v1.0.0beta7
~全面兼容Debian/Armbian/Centos等标准Linux系统
~增加配置本机代理功能
~重写启动脚本,优化在不同系统下的启动方式
~支持以systemd方式启动及守护进程
~~大幅度优化优化安装脚本及更新机制,修复cdn更新延迟
~修改定时任务机制,增加稳定性
2020-09-19 16:38:21 +08:00
juewuy
d9003e50eb v1.0.0beta7
~大幅度优化更新机制
~重写启动脚本,全面兼容debian及centos
~支持以systemd方式启动及守护进程
~优化安装脚本,修复cdn更新延迟
~修改定时任务机制,增加稳定性
~增加配置本机代理功能
2020-09-19 16:32:50 +08:00
juewuy
230fcb6649 调整安装脚本 2020-09-19 09:29:50 +08:00
juewuy
3247a85a69 调整安装脚本 2020-09-19 00:20:42 +08:00
juewuy
c702520e97 调整安装脚本 2020-09-19 00:17:34 +08:00
juewuy
6434abcfdd v1.0.0beta6
~优化定时任务脚本,修复bug
~优化版本更新机制
~重写启动脚本,全面兼容debian及centos
~支持linux的systemd方式启动
~优化cdn下载链接
2020-09-18 21:17:16 +08:00
juewuy
4014f2ddc8 v1.0.0beta6
~优化定时任务脚本,修复bug
~优化版本更新机制
~重写启动脚本,全面兼容debian及centos
~支持linux的systemd方式启动
~优化cdn下载链接
2020-09-18 21:16:28 +08:00
juewuy
51c877de88 v1.0.0beta6
~优化定时任务脚本,修复bug
~优化版本更新机制
~重写启动脚本,全面兼容debian及centos
~支持linux的systemd方式启动
~优化cdn下载链接
2020-09-18 21:10:41 +08:00
juewuy
e394982270 Merge branch 'master' of https://github.com/juewuy/clash-for-Miwifi 2020-09-18 21:09:13 +08:00
juewuy
d151100c25 v1.0.0beta6
~优化定时任务脚本,修复bug
~优化版本更新机制
~重写启动脚本,全面兼容debian及centos
~支持linux的systemd方式启动
~优化cdn下载链接
2020-09-18 21:09:06 +08:00
juewuy
248e85d7a5 增加 2020-09-18 21:07:13 +08:00
juewuy
33ef70e041 Update README.md
更新安装地址
2020-09-18 20:08:53 +08:00
juewuy
a2fced324e v1.0.0beta6
~优化定时任务脚本,修复bug
~优化版本更新机制
2020-09-17 14:50:29 +08:00
juewuy
56e89cf9b6 Update README.md
1
2020-09-15 20:53:43 +08:00
juewuy
1b0e620413 Update README.md 2020-09-13 21:02:04 +08:00
juewuy
c604739456 v1.0.0beta5
~更名为ShellClash,支持更多设备
~调整脚本更新链接
~修复debian等系统下的大量bug
~添加amd64支持
2020-09-13 20:13:53 +08:00
juewuy
2db14f7e2d 加入amd64支持 2020-09-13 20:12:00 +08:00
juewuy
7be54e1031 v1.0.0beta5
~更名为ShellClash,支持更多设备
~调整脚本更新链接
~修复debian等系统下使用dash运行时报错的bug
2020-09-13 19:33:39 +08:00
juewuy
5b90f49c4f v1.0.0beta4
~更名为ShellClash,支持更多设备
~调整脚本更新链接
2020-09-12 16:42:57 +08:00
juewuy
094489be69 1 2020-09-12 16:23:54 +08:00
juewuy
1409f6e584 Update README.md 2020-09-12 16:07:19 +08:00
juewuy
6652b918b9 Update README.md 2020-09-12 15:59:40 +08:00
juewuy
e64194bf4b Update README.md 2020-09-12 15:58:23 +08:00
juewuy
c111cdcfd3 Update README.md 2020-09-12 15:56:13 +08:00
juewuy
0777cdf2e7 Update README.md 2020-09-12 15:45:27 +08:00
juewuy
49803762b8 Update README.md 2020-09-12 15:44:37 +08:00
juewuy
d47273ca01 Update README.md 2020-09-12 15:43:47 +08:00
juewuy
bd7909d281 Update README.md 2020-09-12 15:37:28 +08:00
juewuy
63be19b81d v1.0.0beta3
~新增纯净模式
~新增用于纯净模式的PAC生成功能
~新增重置配置文件功能
~本地DNS服务默认设置调整为不启用
~同步GeoIP数据库文件
2020-09-08 18:35:49 +08:00
juewuy
564c831c37 v1.0.0beta3
~新增纯净模式
~新增用于纯净模式的PAC生成功能
~新增重置配置文件功能
~本地DNS服务默认设置调整为不启用
2020-09-08 18:12:18 +08:00
juewuy
6aa9077907 v1.0.0beta2
~修复未开启ipv6的设备启动时报错的bug
~测试菜单部分功能优化
~启动失败后的检查逻辑优化
2020-08-29 16:09:52 +08:00
juewuy
b17200ae05 v1.0.0beta1
~安装脚本细节调整
~修改iptables规则,解决部分dns污染问题
~优化了核心下载逻辑
~同步最新版Geoip数据库
2020-08-27 10:46:34 +08:00
juewuy
1f7ab1e88a v0.9.10
~新增了导入订阅时通过关键字过滤节点的功能
~优化了导入节点/订阅流程
~优化了跳过证书验证的方式
~调整了部分前后端规则地址
~同步最新Geoip数据库文件
~修复了保守模式下定时任务无法生效的bug
2020-08-24 20:14:31 +08:00
15 changed files with 668 additions and 421 deletions

View File

@@ -1,31 +1,52 @@
# clash-for-Miwifi
小米等基于openwrt系统的路由器上使用clash做透明代理
# ShellClash原Clash for Miwifi
shell环境下一键部署及管理[clash](https://github.com/Dreamacro/clash)
=====
功能简介:
--
~支持小米全系列路由器设备使用clash做透明代理理论支持各种基于openwrt框架的路由器系统<br>
~支持SS、SSR、v2ray、trojan、sock5等协议<br>
~支持批量导入节点链接及订阅链接<br>
~支持使用网页面板管理规则组<br>
~支持多种模式切换,支持在线更新<br>
~支持部署内置的管理面板<br>
~更多功能可在使用中发掘<br>
~通过管理脚本在shell环境下便捷使用[clash](https://github.com/Dreamacro/clash)<br>
~支持在shell环境下管理[clash各种功能](https://lancellc.gitbook.io/clash)<br>
~支持批量导入SS/SSR/v2ray/trojan节点链接及各种订阅链接<br>
~支持使用/安装网页面板管理规则组<br>
~支持局域网透明代理/纯净模式等多种模式切换<br>
~支持在线更新<br>
使用依赖
使用方式
--
~路由器或设备已经开启SSH并获取root权限<br>
~SSH连接工具,例如puttybitviseJuiceSSH支持安卓手机<br>
~确认路由器或设备已经开启SSH并获取root权限<br>
~使用SSH连接工具如puttyJuiceSSHmac终端登陆路由器或设备的SSH管理界面<br>
~在SSH界面执行如下安装命令并按照提示安装clash管理脚本<br>
OpenWrt系统
```Shell
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
```
或者
```Shell
sh -c "$(curl -kfsSl https://cdn.jsdelivr.net/gh/juewuy/ShellClash/install_cdn.sh)" && source /etc/profile &> /dev/null
```
Debian/CenOS/Armbian等默认使用dash的Linux系统
```Shell
bash -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
```
或者
```Shell
bash -c "$(curl -kfsSl https://cdn.jsdelivr.net/gh/juewuy/ShellClash/install_cdn.sh)" && source /etc/profile &> /dev/null
```
~安装完成管理脚本后,执行如下命令以运行管理脚本<br>
```Shell
clash
```
设备支持:
--
~支持小米/红米全系使用官方系统或官方开发版系统的路由器设备ac2100系列除外<br>
~支持所有基于openwrt或使用openwrt二次开发的路由器设备<br>
~支持各种运行标准Linux系统Debian/CenOS/Armbian等的设备<br>
~如有不兼容的Linux设备或CPU架构请提issue或前往TG群反馈需提供设备名称及运行uname -a返回的设备核心信息<br>
更新日志:
--
https://github.com/juewuy/clash-for-Miwifi/releases
一键安装:
--
```Shell
sh -c "$(curl -kfsSl https://juewuy.xyz/clash/install.sh)" && source /etc/profile &> /dev/null
```
https://github.com/juewuy/ShellClash/releases
交流反馈:
--
@@ -33,27 +54,12 @@ sh -c "$(curl -kfsSl https://juewuy.xyz/clash/install.sh)" && source /etc/profil
已知问题:
--
~Tun模式下clash服务可能会和小米路由器内置的tx网游加速器冲突,请谨慎同时使用<br>
~Redir模式无法转发udp流量外服游戏可能会受影响此功能是由官方系统阉割了Tproxy导致暂时无解外服游戏用户建议使用Tun模式<br>
~Tun模式下clash服务可能会和路由器内置的网游加速器冲突请谨慎同时使用<br>
~Redir模式暂不支持转发udp流量外服游戏可能会受影响外服游戏用户建议使用Tun模式<br>
~部分设备长时间使用会出现内存占用偏高——此为golang内存回收不及时导致可以通过屏蔽p2p流量及设置每日定时重启核心以缓解<br>
~节点无法连接——在【clash功能设置】中打开【跳过本地证书验证】<br>
~非OpenWrt系统下定时任务不工作待修复<br>
ToDo
友情推广
--
~~增加订阅功能~~<br>
~~添加一键安装脚本~~<br>
~~增加屏蔽P2P流量功能~~<br>
~~增加更新功能~~<br>
~~修复redir-host DNS以及IPV6支持~~<br>
~~增加定时功能~~<br>
~~增加屏蔽局域网设备~~<br>
~~增加更多设备支持~~<br>
感谢:
--
~https://lancellc.gitbook.io/clash/start-clash/clash-tun-mode<br>
~https://comzyh.gitbook.io/clash/<br>
~https://h-cheung.gitlab.io/post/使用_clash_和路由表实现透明代理<br>
~https://www.right.com.cn/forum/thread-4042741-1-1.html<br>
请喝杯茶:
--
![](https://juewuy.xyz/clash/others/qrcodevx.png)
https://dler.best/auth/register?affid=89698

Binary file not shown.

BIN
bin/clash/clash-linux-amd64 Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

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

View File

@@ -1,24 +1,22 @@
#!/bin/sh
#! /bin/bash
# Copyright (C) Juewuy
echo "***********************************************"
echo "** 欢迎使用 **"
echo "** Clash for Miwifi **"
echo "** ShellClash **"
echo "** by Juewuy **"
echo "***********************************************"
url="https://juewuy.xyz/clash/"
result=$(curl -w %{http_code} -skLo /tmp/clashversion $url/bin/version)
[ "$result" != "200" ] && echo "无法连接服务器!" && exit 1
source /tmp/clashversion
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash"
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')
[ -z "$release_new" ] && release_new=$(curl -kfsSL $url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
[ -z "$release_new" ] && echo "无法连接服务器!" && exit
echo -e "最新版本:\033[32m$release_new\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "~~~~版本:\033[32m$versionsh\033[0m"
echo -e "\033[44m如遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
echo -e "\033[37m支持各种基于openwrt的路由器设备"
echo -e "\033[33m有限兼容debian、centos等Linux系统\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[44m使用中如遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
echo -e "\033[37m目前仅支持小米AX系列3款路由器"
echo -e "\033[44m其余型号可到TG群报名参与测试\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[32m 1 在默认目录(/etc)安装Clash for Miwifi"
echo -e "\033[32m 1 在默认目录(/etc)安装ShellClash"
echo -e "\033[33m 2 手动设置安装目录(不明勿用!)"
echo -e "\033[0m 0 退出安装"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -27,9 +25,9 @@ read -p "请输入相应数字 > " num
if [ -z $num ];then
echo 安装已取消
exit;
elif [[ $num == 1 ]];then
elif [ "$num" = "1" ];then
dir=/etc
elif [[ $num == 2 ]];then
elif [ "$num" = "2" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo '可用路径 剩余空间:'
df -h | awk '{print $6,$2}'| sed 1d
@@ -47,7 +45,7 @@ fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 开始从服务器获取安装文件!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tarurl=$url/bin/clashfm.tar.gz
tarurl=$url@$release_new/bin/clashfm.tar.gz
if command -v curl &> /dev/null; then
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl)
else $result
@@ -61,26 +59,43 @@ echo 开始解压文件!
mkdir -p $dir/clash > /dev/null
tar -zxvf '/tmp/clashfm.tar.gz' -C $dir/clash/
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
#判断系统类型写入不同的启动文件
if [ -n "$(cat /proc/version | grep -i openwrt)" ];then
mv $dir/clash/clashservice /etc/init.d/clash #将rc服务文件移动到系统目录
chmod 777 /etc/init.d/clash #授予权限
rm -rf $dir/clash/clash.service
else
[ -d /etc/systemd/system ] && sysdir=/etc/systemd/system
[ -d /usr/lib/systemd/system/ ] && sysdir=/usr/lib/systemd/system/
mv $dir/clash/clash.service $sysdir/clash.service #将service服务文件移动到系统目录
sed -i "s%/etc/clash%${dir}/clash%g" $sysdir/clash.service
rm -rf $dir/clash/clashservice
rm -rf /etc/init.d/clash
fi
#初始化文件目录
mv $dir/clash/clashservice /etc/init.d/clash #将clash服务文件移动到系统目录
chmod 777 /etc/init.d/clash #授予权限
if [ ! -f "$dir/clash/mark" ]; then
cat >$dir/clash/mark<<EOF
#标识clash运行状态的文件不明勿动
EOF
fi
#修饰文件及版本号
shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash
sed -i "s%#!/bin/sh%#!/bin/$shtype%g" $dir/clash/start.sh
chmod 777 $dir/clash/start.sh
sed -i '/versionsh_l=*/'d $dir/clash/mark
sed -i "1i\versionsh_l=$versionsh" $dir/clash/mark
sed -i "1i\versionsh_l=$release_new" $dir/clash/mark
#设置环境变量
sed -i '/alias clash=*/'d /etc/profile
echo "alias clash=\"sh $dir/clash/clash.sh\"" >> /etc/profile #设置快捷命令环境变量
echo "alias clash=\"$shtype $dir/clash/clash.sh\"" >> /etc/profile #设置快捷命令环境变量
sed -i '/export clashdir=*/'d /etc/profile
echo "export clashdir=\"$dir/clash\"" >> /etc/profile #设置clash路径环境变量
#删除临时文件
rm -rf /tmp/clashfm.tar.gz
#提示
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo clash for Miwifi 已经安装成功!
echo -e "\033[33m直接输入\033[30;47m clash \033[0;33m命令即可管理\033[0m"
echo ShellClash 已经安装成功!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

101
install_cdn.sh Normal file
View File

@@ -0,0 +1,101 @@
#! /bin/bash
# Copyright (C) Juewuy
echo "***********************************************"
echo "** 欢迎使用 **"
echo "** ShellClash **"
echo "** by Juewuy **"
echo "***********************************************"
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash"
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')
[ -z "$release_new" ] && release_new=$(curl -kfsSL $url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
[ -z "$release_new" ] && echo "无法连接服务器!" && exit
echo -e "最新版本:\033[32m$release_new\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[44m如遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
echo -e "\033[37m支持各种基于openwrt的路由器设备"
echo -e "\033[33m有限兼容debian、centos等Linux系统\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[32m 1 在默认目录(/etc)安装ShellClash"
echo -e "\033[33m 2 手动设置安装目录(不明勿用!)"
echo -e "\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 路径错误!已取消安装!
exit;
fi
else
echo 安装已取消
exit;
fi
#下载文件包
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 开始从服务器获取安装文件!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tarurl=$url@$release_new/bin/clashfm.tar.gz
if command -v curl &> /dev/null; then
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl)
else $result
wget-ssl -q --no-check-certificate --tries=1 --timeout=10 -O /tmp/clashfm.tar.gz $tarurl
[ $? -eq 0 ] && result="200"
fi
[ "$result" != "200" ] && echo "文件下载失败!" && exit 1
#解压
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 开始解压文件!
mkdir -p $dir/clash > /dev/null
tar -zxvf '/tmp/clashfm.tar.gz' -C $dir/clash/
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
#判断系统类型写入不同的启动文件
if [ -n "$(cat /proc/version | grep -i openwrt)" ];then
mv $dir/clash/clashservice /etc/init.d/clash #将rc服务文件移动到系统目录
chmod 777 /etc/init.d/clash #授予权限
rm -rf $dir/clash/clash.service
else
[ -d /etc/systemd/system ] && sysdir=/etc/systemd/system
[ -d /usr/lib/systemd/system/ ] && sysdir=/usr/lib/systemd/system/
mv $dir/clash/clash.service $sysdir/clash.service #将service服务文件移动到系统目录
sed -i "s%/etc/clash%${dir}/clash%g" $sysdir/clash.service
rm -rf $dir/clash/clashservice
rm -rf /etc/init.d/clash
fi
#初始化文件目录
if [ ! -f "$dir/clash/mark" ]; then
cat >$dir/clash/mark<<EOF
#标识clash运行状态的文件不明勿动
EOF
fi
#修饰文件及版本号
shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash
sed -i "s%#!/bin/sh%#!/bin/$shtype%g" $dir/clash/start.sh
chmod 777 $dir/clash/start.sh
sed -i '/versionsh_l=*/'d $dir/clash/mark
sed -i "1i\versionsh_l=$release_new" $dir/clash/mark
#设置环境变量
sed -i '/alias clash=*/'d /etc/profile
echo "alias clash=\"$shtype $dir/clash/clash.sh\"" >> /etc/profile #设置快捷命令环境变量
sed -i '/export clashdir=*/'d /etc/profile
echo "export clashdir=\"$dir/clash\"" >> /etc/profile #设置clash路径环境变量
#删除临时文件
rm -rf /tmp/clashfm.tar.gz
#提示
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ShellClash 已经安装成功!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

15
scripts/clash.service Normal file
View File

@@ -0,0 +1,15 @@
[Unit]
Description=clash
After=network.target
[Service]
Type=simple
User=root
ExecStart=/etc/clash/clash -d /etc/clash
ExecStartPost=/etc/clash/start.sh afstart
Restart=on-failure
RestartSec=3s
[Install]
WantedBy=multi-user.target

View File

@@ -1,19 +1,33 @@
#!/bin/sh
#!/bin/sh
# Copyright (C) Juewuy
getconfig(){
#系统类型
systype=$(cat /proc/version | grep -io openwrt)
if [ -n "$systype" ];then
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
autostart=enable_rc
else
autostart=disable_rc
fi
else
cron_user='root '
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
if [ -n "$(systemctl list-unit-files clash.service | grep -o enable)" ];then
autostart=enable_sys
else
autostart=disable_sys
fi
fi
#服务器地址
if [ -z "$update_url" ]; then
update_url=https://cdn.jsdelivr.net/gh/juewuy/clash-for-Miwifi@latest
fi
[ -z "$update_url" ] && update_url=https://cdn.jsdelivr.net/gh/juewuy/ShellClash
#文件路径
if [ -z "$clashdir" ];then
clashdir=$(dirname $(readlink -f "$0"))
echo "export clashdir=\"$clashdir\"" >> /etc/profile
fi
[ -z "$clashdir" ] && clashdir=$(dirname $(readlink -f "$0")) && echo "export clashdir=\"$clashdir\"" >> /etc/profile
ccfg=$clashdir/mark
yaml=$clashdir/config.yaml
#检查标识文件
#检查/读取标识文件
if [ ! -f $ccfg ]; then
echo mark文件不存在正在创建
cat >$ccfg<<EOF
@@ -27,7 +41,7 @@ source $ccfg
if [ "$start_old" = "已开启" ];then
auto="\033[33m已设置保守模式\033[0m"
auto1="\033[36m设为\033[0m常规模式启动"
elif [ -f /etc/rc.d/*clash ];then
elif [ "$autostart" = "enable_rc" -o "$autostart" = "enable_sys" ]; then
auto="\033[32m已设置开机启动\033[0m"
auto1="\033[36m禁用\033[0mclash开机启动"
else
@@ -40,11 +54,10 @@ if [ -z "$redir_mod" ];then
redir_mod=Redir模式
fi
#获取运行状态
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh|wc -l`
if [[ $status -gt 0 ]];then
PID=$(pidof clash)
if [ -n "$PID" ];then
run="\033[32m正在运行$redir_mod\033[0m"
uid=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh|awk '{print $1}'`
VmRSS=`cat /proc/$uid/status|grep -w VmRSS|awk '{print $2,$3}'`
VmRSS=`cat /proc/$PID/status|grep -w VmRSS|awk '{print $2,$3}'`
#获取运行时长
if [ -n "$start_time" ]; then
time=$((`date +%s`-$start_time))
@@ -62,21 +75,21 @@ fi
#输出状态
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;46m欢迎使用Clash for Miwifi\033[0m 版本:$versionsh_l"
echo -e "\033[30;46m欢迎使用ShellClash\033[0m 版本:$versionsh_l"
echo -e "Clash服务"$run""$auto""
if [ $status -gt 0 ];then
if [ -n "$PID" ];then
echo -e "当前内存占用:\033[44m"$VmRSS"\033[0m已运行\033[46;30m"$day"\033[44;37m"$time"\033[0m"
fi
echo -e "博客:\033[36;4mhttps://juewuy.xyz\033[0mTG群\033[36;4mhttps://t.me/clashfm\033[0m"
echo -e "TG群\033[36;4mhttps://t.me/clashfm\033[0m"
echo -----------------------------------------------
#安装clash核心
#检查clash核心
if [ ! -f $clashdir/clash ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m没有找到核心文件请先下载clash核心\033[0m"
source $clashdir/getdate.sh
getcore
fi
#安装GeoIP数据库
#检查GeoIP数据库
if [ ! -f $clashdir/Country.mmdb ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m没有找到GeoIP数据库文件请先下载数据库\033[0m"
@@ -85,54 +98,37 @@ if [ ! -f $clashdir/Country.mmdb ];then
clashstart
fi
}
clashstop(){
source $clashdir/start.sh && stop_old
/etc/init.d/clash stop > /dev/null 2>&1
}
clashstart(){
if [ ! -f "$yaml" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m没有找到配置文件请先导入节点/订阅链接!\033[0m"
clashlink
fi
if [ $status -gt 0 ];then
if [ -n "$PID" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clashstop
$clashdir/start.sh stop
echo -e "\033[31mClash服务已停止\033[0m"
fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$start_old" = "已开启" ];then
source $clashdir/start.sh && start_old
sleep 1
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh`
if [ -z "$status" ];then
echo -e "\033[31mclash启动失败\033[0m"
sed -i /start_old=*/d $ccfg
exit
fi
else
/etc/init.d/clash start
sleep 1
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh`
if [ -z "$status" ];then
echo -e "\033[31mclash启动失败尝试使用保守方式启动\033[0m"
source $clashdir/start.sh && start_old
sleep 1
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh`
if [ -z "$status" ];then
echo -e "\033[31mclash启动失败\033[0m"
sed -i /start_old=*/d $ccfg
exit
fi
fi
$clashdir/start.sh start
sleep 1
PID=$(pidof clash)
if [ -z "$PID" ];then
echo -e "\033[31mclash启动失败\033[0m"
exit
fi
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}';)
echo -e "\033[32mclash服务已启动\033[0m"
echo -e "可以使用\033[30;47m http://clash.razord.top \033[0m管理内置规则"
echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m 9999 \033[0m"
echo -e "也可前往更新菜单安装本地Dashboard面板连接更稳定\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ -d /www/clash ];then
echo -e "请使用\033[30;47m http://$host/clash \033[0m管理内置规则"
elif [ -d $clashdir/ui ];then
echo -e "请使用\033[30;47m http://$host:9999/ui \033[0m管理内置规则"
else
echo -e "可使用\033[30;47m http://clash.razord.top \033[0m管理内置规则"
echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m 9999 \033[0m"
echo -e "也可前往更新菜单安装本地Dashboard面板连接更稳定\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fi
}
clashlink(){
#获取订阅规则
@@ -153,7 +149,7 @@ 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[33m配置规则\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订阅"
@@ -259,10 +255,10 @@ fi
}
clashcfg(){
#获取设置默认显示
[ -z "$skip_cert" ] && skip_cert=开启
[ -z "$common_ports" ] && common_ports=开启
[ -z "$skip_cert" ] && skip_cert=开启
[ -z "$common_ports" ] && common_ports=开启
[ -z "$dns_mod" ] && dns_mod=redir_host
[ -z "$dns_over" ] && dns_over=开启
[ -z "$dns_over" ] && dns_over=开启
if [ -z "$(cat $clashdir/mac)" ]; then
mac_return=未开启
else
@@ -302,6 +298,8 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo " 3 混合模式: 仅使用Tun转发UPD流量"
echo " CPU和内存占用较高"
echo " 不推荐使用redir-host"
echo " 4 纯净模式: 不设置iptables静态路由"
echo " 必须手动配置http/sock5代理"
echo " 0 返回上级菜单"
read -p "请输入对应数字 > " num
if [ -z "$num" ]; then
@@ -326,7 +324,19 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -e "\033[31m当前核心不支持开启Tun模式请先切换clash核心\033[0m"
clashcfg
fi
redir_mod=混合模式
redir_mod=混合模式
elif [[ $num == 4 ]]; then
redir_mod=纯净模式
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[32m已经设置为纯净模式\033[0m"
echo -e "\033[33m当前模式必须手动在设备WiFi或应用中配置HTTP或sock5代理\033[0m"
echo -e "HTTP/SOCK5代理服务器地址\033[30;47m$host\033[0m;端口均为:\033[30;47m7890\033[0m"
echo -e "\033[31m也可以使用PAC自动代理文件具体使用方法请自行搜索\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
read -p "是否配置自动代理PAC文件(1/0) > " res
if [ "$res" = 1 ]; then
source $clashdir/getdate.sh && catpac
fi
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
@@ -346,7 +356,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -e "\033[33m切换模式后需要手动重启clash服务以生效\033[0m"
echo -----------------------------------------------
echo " 1 fake-ip模式 响应速度更快"
echo " 但可能和部分软件有冲突"
echo " 不兼容部分软件"
echo " 2 redir_host模式使用稳定兼容性好"
echo " 不支持Tun模式"
echo " 0 返回上级菜单"
@@ -502,6 +512,7 @@ clashadv(){
[ -z "$modify_yaml" ] && modify_yaml=未开启
[ -z "$ipv6_support" ] && ipv6_support=未开启
[ -z "$start_old" ] && start_old=未开启
[ -z "$local_proxy" ] && local_proxy=未开启
#
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m欢迎使用进阶模式菜单\033[0m"
@@ -509,9 +520,11 @@ echo -e "\033[33m如您不是很了解clash的运行机制请勿更改\033
echo -e "\033[32m修改配置后请手动重启clash服务\033[0m"
echo -----------------------------------------------
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 " 4 代理本机流量: \033[36m$local_proxy\033[0m ————配置本机代理环境变量"
echo -----------------------------------------------
echo -e " 8 \033[31m重置\033[0m配置文件"
echo -e " 9 \033[32m重启\033[0mclash服务"
echo -e " 0 返回上级菜单 \033[0m"
echo -----------------------------------------------
@@ -561,16 +574,46 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -e "\033[33m改为使用保守方式启动clash服务\033[0m"
echo -e "\033[36m此模式兼容性更好但无法禁用开机启动\033[0m"
start_old=已开启
/etc/init.d/clash stop > /dev/null 2>&1
$clashdir/start.sh stop > /dev/null 2>&1
sleep 2
else
sed -i "1i\start_old=未开启" $ccfg
echo -e "\033[32m改为使用默认方式启动clash服务\033[0m"
start_old=未开启
source $clashdir/start.sh && stop_old
$clashdir/start.sh stop > /dev/null 2>&1
fi
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
read -p "确认重置配置文件?(1/0) > " res
if [ "$res" = "1" ];then
echo "versionsh_l=$versionsh_l" > $ccfg
echo "start_time=$start_time" >> $ccfg
echo "#标识clash运行状态的文件不明勿动" >> $ccfg
echo -e "\033[33m配置文件已重置请重新运行脚本\033[0m"
exit
fi
clashadv
elif [[ $num == 9 ]]; then
clashstart
@@ -587,18 +630,27 @@ fi
exit;
}
update(){
if [ -z "$release_new" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m正在检查更新\033[0m"
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')
[ -z "$release_new" ] && release_new=$(curl -kfsSL $update_url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
[ -z "$release_new" ] && echo "检查更新失败!"
fi
[ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ] && update_url=$update_url@$release_new
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m欢迎使用更新功能\033[0m"
echo -e "感谢:\033[32mClash \033[0m作者\033[36m Dreamacro\033[0m 项目地址:\033[32mhttps://github.com/Dreamacro/clash\033[0m"
echo -e "感谢:\033[32mClashR \033[0m作者\033[36m BROBIRD\033[0m 项目地址:\033[32mhttps://github.com/BROBIRD/clash\033[0m"
echo -e "感谢:\033[32m更多的帮助过我的人\033[0m"
[ -n "$release_new" ] && echo -e "当前ShellClash版本:\033[33m $versionsh_l \033[0m"
[ -n "$release_new" ] && echo -e "最新ShellClash版本\033[32m $release_new \033[0m"
echo -----------------------------------------------
echo -e " 1 更新\033[36m管理脚本\033[0m"
echo -e " 2 切换\033[33mclash核心\033[0m"
echo -e " 3 更新\033[32mGeoIP数据库\033[0m"
echo -e " 4 安装本地\033[35mDashboard\033[0m面板"
echo -e " 5 生成本地PAC文件(需先安装本地面板)"
echo -----------------------------------------------
echo -e " 8 切换\033[36m安装源\033[0m地址"
echo -e " 7 切换\033[36m安装源\033[0m地址"
echo -e " 8 鸣谢"
echo -e " 9 \033[31m卸载\033[34mClash for Miwfi\033[0m"
echo -e " 0 返回上级菜单"
echo -----------------------------------------------
@@ -624,10 +676,22 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
source $clashdir/getdate.sh
getdb
elif [[ $num == 8 ]]; then
elif [[ $num == 5 ]]; then
source $clashdir/getdate.sh
catpac
update
elif [[ $num == 7 ]]; then
source $clashdir/getdate.sh
setserver
elif [[ $num == 8 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "感谢:\033[32mClash \033[0m作者\033[36m Dreamacro\033[0m 项目地址:\033[32mhttps://github.com/Dreamacro/clash\033[0m"
echo -e "感谢:\033[32malecthw大神提供的GeoIP数据库\033[0m 项目地址:\033[32mhttps://github.com/alecthw/mmdb_china_ip_list\033[0m"
echo -e "感谢:\033[32m更多的帮助过我的人\033[0m"
update
elif [[ $num == 9 ]]; then
read -p "确认卸载clash警告该操作不可逆[1/0] " res
if [ "$res" = '1' ]; then
@@ -635,11 +699,15 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
/etc/init.d/clash stop
rm -rf $clashdir
rm -rf /etc/init.d/clash
rm -rf /etc/systemd/system/clash.service
rm -rf /usr/lib/systemd/system/clash.service
rm -rf /www/clash
rm -rf $csh
sed -i '/alias clash=*/'d /etc/profile
sed -i '/export clashdir=*/'d /etc/profile
source /etc/profile > /dev/null 2>&1
echo 已卸载clash相关文件
exit
fi
echo -e "\033[31m操作已取消\033[0m"
exit;
@@ -719,20 +787,17 @@ clashcron(){
read -p "是否确认添加定时任务?(1/0) > " res
if [ "$res" = '1' ]; then
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 -e "\033[31m定时任务已添加\033[0m"
fi
clashcron
}
checkcron(){
if [ -d /etc/crontabs/ ]; then
cronpath="/etc/crontabs/root"
elif [ -d /var/spool/cron/ ]; then
cronpath="/var/spool/cron/root"
elif [ -d /var/spool/cron/crontabs/ ]; then
cronpath="/var/spool/cron/crontabs/root"
else
[ -d /etc/crontabs/ ]&&cronpath="/etc/crontabs/root"
[ -d /var/spool/cron/ ]&&cronpath="/var/spool/cron/root"
[ -d /var/spool/cron/crontabs/ ]&&cronpath="/var/spool/cron/crontabs/root"
if [ -z $cronpath ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo "找不到定时任务文件,无法添加定时任务!"
clashsh
@@ -745,8 +810,8 @@ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m欢迎使用定时任务功能\033[0m"
echo -e "\033[44m 实验性功能遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
echo -----------------------------------------------
echo -e "\033[33m当前已经添加的定时任务\033[36m"
crontab -l | egrep -o '#.*'
echo -e "\033[33m添加的定时任务:\033[36m"
cat $cronpath | egrep -o ' #.*'
echo -e "\033[0m"-----------------------------------------------
echo -e " 1 设置\033[33m定时重启\033[0mclash服务"
echo -e " 2 设置\033[31m定时停止\033[0mclash服务"
@@ -765,19 +830,19 @@ elif [[ $num == 0 ]]; then
elif [[ $num == 1 ]]; then
cronname=重启clash服务
cronset='source /etc/profile && source $clashdir/start.sh && restart'
cronset="$clashdir/start.sh restart"
setcron
elif [[ $num == 2 ]]; then
cronname=停止clash服务
cronset='source /etc/profile && source $clashdir/start.sh && stop'
cronset="$clashdir/start.sh stop"
setcron
elif [[ $num == 3 ]]; then
cronname=开启clash服务
cronset='source /etc/profile && source $clashdir/start.sh && start'
cronset="$clashdir/start.sh start"
setcron
elif [[ $num == 4 ]]; then
cronname=更新订阅链接
cronset="source /etc/profile && source $clashdir/getdate.sh && getyaml"
cronset="$clashdir/start.sh getyaml"
setcron
else
@@ -815,7 +880,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
clashcfg
elif [[ $num == 3 ]]; then
clashstop
$clashdir/start.sh stop
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31mClash服务已停止\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -828,12 +893,20 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
sed -i "1i\start_old=未开启" $ccfg
echo -e "\033[32m已设为使用默认方式启动clash服务\033[0m"
start_old=未开启
elif [ -f /etc/rc.d/*clash ]; then
elif [ "$autostart" = "enable_rc" ]; then
/etc/init.d/clash disable
echo -e "\033[33m已禁止Clash开机启动\033[0m"
else
elif [ "$autostart" = "disable_rc" ]; then
/etc/init.d/clash enable
echo -e "\033[32m已设置Clash开机启动\033[0m"
elif [ "$autostart" = "enable_sys" ]; then
systemctl disable clash.service > /dev/null 2>&1
echo -e "\033[33m已禁止Clash开机启动\033[0m"
elif [ "$autostart" = "disable_sys" ]; then
systemctl enable clash.service > /dev/null 2>&1
echo -e "\033[32m已设置Clash开机启动\033[0m"
else
echo -e "\033[32m当前系统不支持设置开启启动\033[0m"
fi
clashsh
@@ -850,6 +923,8 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m这里是测试命令菜单\033[0m"
echo -e "\033[33m如遇问题尽量运行相应命令后截图发群\033[0m"
echo -e "磁盘占用/所在目录:"
du -h $clashdir
echo -----------------------------------------------
echo " 1 查看clash运行时的报错信息"
echo " 2 查看系统DNS端口(:53)占用 "
@@ -867,15 +942,17 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
elif [[ $num == 0 ]]; then
clashsh
elif [[ $num == 1 ]]; then
/etc/init.d/clash stop
echo -e "\033[31m如有报错请截图后到TG群询问\033[0m"
$clashdir/start.sh stop
echo -----------------------------------------------
$clashdir/clash -d $clashdir & { sleep 3 ; kill $! & }
echo -----------------------------------------------
echo -e "\033[31m如有报错请截图后到TG群询问\033[0m"
exit;
elif [[ $num == 2 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
netstat -ntulp |grep 53
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "可以使用\033[44m netstat -ntulp |grep xxx \033[0m来查询任意(xxx)端口"
exit;
elif [[ $num == 3 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -8,12 +8,6 @@ START=92
start_service() {
#开机加载环境变量保证找到文件路径
source /etc/profile > /dev/null 2>&1
#加载修饰脚本
source $clashdir/start.sh
#读取配置文件
getconfig
#使用内置规则强行覆盖config配置文件
[ "$modify_yaml" != "已开启" ] && modify_yaml
#创建clash后台进程
procd_open_instance
procd_set_param respawn
@@ -21,17 +15,6 @@ start_service() {
procd_set_param stdout 1
procd_set_param command $clashdir/clash -d $clashdir
procd_close_instance
#修改iptables规则使流量进入clash
stop_iptables
start_dns
[ "$redir_mod" != "Tun模式" ] && start_redir
#标记启动时间
mark_time
#标记启动方式
sed -i /start_old=*/d $ccfg
sed -i "1i\start_old=未开启" $ccfg
#其他设置
sh $clashdir/start.sh afstart
}
stop_service() {
source $clashdir/start.sh
stop_iptables
}

View File

@@ -1,158 +1,6 @@
#!/bin/sh
#!/bin/bash
# Copyright (C) Juewuy
getyaml(){
ccfg=$clashdir/mark
source $ccfg
#前后端订阅服务器地址索引,可在此处添加!
Server=`sed -n ""$server_link"p"<<EOF
subconverter-web.now.sh
subconverter.herokuapp.com
subcon.py6.pw
api.dler.io
api.wcc.best
skapi.cool
EOF`
Config=`sed -n ""$rule_link"p"<<EOF
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online.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_NoReject.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_NoAuto.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_NoAuto.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
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"
markhttp=1
fi
#
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 正在连接服务器获取配置文件…………链接地址为:
echo -e "\033[4;32m$Https\033[0m"
echo 可以手动复制该链接到浏览器打开并查看数据是否正常!
echo -e "\033[36m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo -e "| |"
echo -e "| 需要一点时间,请耐心等待! |"
echo -e "| \033[0m如长时间没有数据请用ctrl+c退出\033[36m |"
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m"
#获取在线yaml文件
yaml=$clashdir/config.yaml
yamlnew=/tmp/config.yaml
rm -rf $yamlnew > /dev/null 2>&1
result=$(curl -w %{http_code} -kLo $yamlnew $Https)
if [ "$result" != "200" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m配置文件获取失败\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo
if [ -z $markhttp ];then
echo 请尝试使用导入节点/链接功能!
getlink
else
read -p "是否更换后端地址后重试?[1/0] > " res
if [ "$res" = '1' ]; then
sed -i '/server_link=*/'d $ccfg
if [[ $server_link -ge 6 ]]; then
server_link=0
fi
server_link=$(($server_link + 1))
echo $server_link
sed -i "1i\server_link=$server_link" $ccfg
Https=""
getyaml
fi
#exit;
fi
else
Https=""
if cat $yamlnew | grep ', server:' >/dev/null;then
#检测旧格式
if cat $yamlnew | grep 'Proxy Group:' >/dev/null;then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m已经停止对旧格式配置文件的支持\033[0m"
echo -e "请使用新格式或者使用\033[32m导入节点/订阅\033[0m功能"
sleep 2
clashlink
fi
#检测不支持的加密协议
if cat $yamlnew | grep 'cipher: chacha20,' >/dev/null;then
if [ "$clashcore" = "clash" -o "$clashcore" = "clashpre" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m当前核心$clashcore不支持chacha20加密\033[0m"
echo -e "请更换使用clashR核心"
sleep 2
getcore
fi
fi
#替换文件
[ -f $yaml ] && mv $yaml $yaml.bak
mv $yamlnew $yaml
echo 配置文件已生成正在启动clash使其生效
#重启clash服务
killall -9 clash &> /dev/null
start_over(){
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}';)
echo -e "\033[32mclash服务已启动\033[0m"
echo -e "可以使用\033[30;47m http://clash.razord.top \033[0m管理内置规则"
echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m 9999 \033[0m"
echo -e "也可前往更新菜单安装本地Dashboard面板连接更稳定\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clashsh
}
if [ "$start_old" = "已开启" ];then
source $clashdir/start.sh && start_old
sleep 1
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh|wc -l`
if [[ $status -gt 0 ]];then
start_over
fi
else
/etc/init.d/clash start
sleep 1
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh|wc -l`
if [[ $status -gt 0 ]];then
start_over
else
echo -e "\033[31mclash服务启动失败尝试使用保守方式启动\033[0m"
source $clashdir/start.sh && start_old
sleep 1
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh|wc -l`
if [[ $status -gt 0 ]];then
start_over
fi
fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ -f $yaml.bak ];then
echo -e "\033[31mclash服务启动失败已还原配置文件并重启clash\033[0m"
mv $yaml.bak $yaml
/etc/init.d/clash start
sleep 1
clashsh
else
echo -e "\033[31mclash服务启动失败请查看报错信息\033[0m"
$clashdir/clash -d $clashdir & { sleep 3 ; kill $! & }
exit;
fi
fi
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m获取到了配置文件但格式似乎不对\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sed -n '1,20p' $yamlnew
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m请检查如上配置文件信息:\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fi
#exit;
fi
#exit
}
linkconfig(){
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[44m 实验性功能遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
@@ -245,6 +93,8 @@ if [ -n $Url ];then
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 ————解决节点证书验证错误"
echo -----------------------------------------------
echo -e " 0 \033[31m取消导入\033[0m并返回上级菜单"
echo -----------------------------------------------
read -p "请输入对应数字 > " num
@@ -259,7 +109,7 @@ if [ -n $Url ];then
sed -i "6i\Url=\'$Url\'" $ccfg
Https=""
#获取在线yaml文件
getyaml
$clashdir/start.sh getyaml
elif [ "$num" = '2' ]; then
linkfilter
linkset
@@ -269,6 +119,19 @@ if [ -n $Url ];then
elif [ "$num" = '4' ]; then
linkserver
linkset
elif [ "$num" = '5' ]; then
sed -i '/skip_cert*/'d $ccfg
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$skip_cert" = "未开启" ] > /dev/null 2>&1; then
sed -i "1i\skip_cert=已开启" $ccfg
#echo -e "\033[33m已设为开启跳过本地证书验证\033[0m"
skip_cert=已开启
else
sed -i "1i\skip_cert=未开启" $ccfg
#echo -e "\033[33m已设为禁止跳过本地证书验证\033[0m"
skip_cert=未开启
fi
linkset
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
@@ -326,7 +189,8 @@ getlink2(){
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m 此功能不明勿用,出问题自行解决!\033[0m"
echo -----------------------------------------------
echo -e "\033[33m仅限导入完整clash链接"
echo -e "\033[33m仅限导入完整clash链接\033[0m"
echo -e "可以使用\033[32m https://acl4ssr.netlify.app \033[0m在线转换"
echo -e "\033[36m导入后如无法运行请使用【导入节点/订阅链接】功能"
echo -e "\033[31m注意如节点使用了chacha20加密协议需将核心更新为clashr核心\033[0m"
echo -----------------------------------------------
@@ -348,7 +212,7 @@ if [ -n $Https ];then
sed -i '/Https=*/'d $ccfg
sed -i "6i\Https=\'$Https\'" $ccfg
#获取在线yaml文件
getyaml
$clashdir/start.sh getyaml
fi
clashlink
fi
@@ -360,14 +224,9 @@ else
fi
}
getsh(){
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m正在检查更新\033[0m"
result=$(curl -w %{http_code} -skLo /tmp/clashversion $update_url/bin/version)
[ "$result" != "200" ] && echo "检查更新失败!" && exit 1
source /tmp/clashversion
echo -----------------------------------------------
echo -e "当前脚本版本为:\033[33m $versionsh_l \033[0m"
echo -e "最新脚本版本为:\033[32m $versionsh \033[0m"
echo -e "最新脚本版本为:\033[32m $release_new \033[0m"
echo -----------------------------------------------
read -p "是否更新脚本?[1/0] > " res
if [ "$res" = '1' ]; then
@@ -375,7 +234,7 @@ if [ "$res" = '1' ]; then
echo 正在获取更新文件
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $update_url/bin/clashfm.tar.gz)
else $result
wget-ssl -q --no-check-certificate --tries=1 --timeout=10 -O /tmp/clashfm.tar.gz $tarurl
wget-ssl -q --no-check-certificate --tries=1 --timeout=10 -O /tmp/clashfm.tar.gz $update_url/bin/clashfm.tar.gz
[ $? -eq 0 ] && result="200"
fi
[ "$result" != "200" ] && echo "文件下载失败!" && exit 1
@@ -385,12 +244,25 @@ if [ "$res" = '1' ]; then
mkdir -p $clashdir > /dev/null
tar -zxvf '/tmp/clashfm.tar.gz' -C $clashdir/ > /dev/null
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
#初始化文件目录
mv $clashdir/clashservice /etc/init.d/clash #将clash服务文件移动到系统目录
chmod 777 /etc/init.d/clash #授予权限
#写入版本号
#判断系统类型写入不同的启动文件
if [ -n "$(cat /proc/version | grep -i openwrt)" ];then
mv $clashdir/clashservice /etc/init.d/clash #将rc服务文件移动到系统目录
chmod 777 /etc/init.d/clash #授予权限
rm -rf $clashdir/clash.service
else
[ -d /etc/systemd/system ] && sysdir=/etc/systemd/system
[ -d /usr/lib/systemd/system/ ] && sysdir=/usr/lib/systemd/system/
mv $clashdir/clash.service $sysdir/clash.service #将service服务文件移动到系统目录
sed -i "s%/etc/clash%${clashdir}%g" $sysdir/clash.service
rm -rf $clashdir/clashservice
rm -rf /etc/init.d/clash
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 $ccfg
sed -i "1i\versionsh_l=$versionsh" $ccfg
sed -i "1i\versionsh_l=$release_new" $ccfg
#删除临时文件
rm -rf /tmp/clashfm.tar.gz
rm -rf /tmp/clashversion
@@ -400,7 +272,7 @@ if [ "$res" = '1' ]; then
echo -----------------------------------------------
exit;
else
clashsh
update
fi
}
getcore(){
@@ -413,12 +285,14 @@ fi
clashcore_n=$clashcore
#获取设备处理器架构
cpucore=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
[ -n "$(echo $cpucore | grep -E "linux.*aarch64.*")" ] && cpucore="armv8"
[ -n "$(echo $cpucore | grep -E "linux.*armv7.*")" ] && cpucore="armv7"
[ -n "$(echo $cpucore | grep -E "linux.*armv.*")" ] && cpucore="armv5"
[ -n "$(echo $cpucore | grep -E "linux.*aarch64.*")" ] && cpucore="armv8"
[ -n "$(echo $cpucore | grep -E "linux.*armv8.*")" ] && cpucore="armv8"
[ -n "$(echo $cpucore | grep -E "linux.*armv7.*")" ] && cpucore="armv7"
[ -n "$(echo $cpucore | grep -E "linux.*mips.*")" ] && cpucore="mipsle-softfloat"
[ -n "$(echo $cpucore | grep -E "linux.*x86.*")" ] && cpucore="386"
[ -n "$(echo $cpucore | grep -E "linux.*amd64.*")" ] && cpucore="386"
[ -n "$(echo $cpucore | grep -E "linux.*amd64.*")" ] && cpucore="amd64"
[ -n "$(echo $cpucore | grep -E "linux.*x86_64.*")" ] && cpucore="amd64"
###
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "当前clash核心\033[47;30m $clashcore \033[46;30m$clashv\033[0m"
@@ -503,12 +377,13 @@ fi
getgeo(){
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m正在检查更新\033[0m"
echo $update_url
result=$(curl -w %{http_code} -skLo /tmp/clashversion $update_url/bin/version)
[ "$result" != "200" ] && echo "检查更新失败!" && exit 1
source /tmp/clashversion
echo -----------------------------------------------
echo -e "当前脚本版本为:\033[33m $Geo_v \033[0m"
echo -e "最新脚本版本为:\033[32m $GeoIP_v \033[0m"
echo -e "当前GeoIP版本为:\033[33m $Geo_v \033[0m"
echo -e "最新GeoIP版本为:\033[32m $GeoIP_v \033[0m"
echo -----------------------------------------------
read -p "是否更新数据库文件?[1/0] > " res
if [ "$res" = '1' ]; then
@@ -534,7 +409,7 @@ clashsh
fi
}
getdb(){
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}';)
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[36m安装本地版dashboard管理面板\033[0m"
echo -----------------------------------------------
@@ -600,15 +475,46 @@ fi
update
}
catpac(){
#检测目录
[ ! -d /www/clash -a ! -d $clashdir/ui ]&&echo 未检测到本地Dashboard面板请先安装面板&&sleep 1&&getdb
#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}';)
[ -d /www/clash ]&&dir="/www/clash"&&pac=http://$host/clash/pac
[ -d $clashdir/ui ]&&dir="$clashdir/ui"&&pac=http://$host:9999/ui/pac
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m生成用于设备WIFI或浏览器的自动PAC代理文件\033[0m"
echo -e "\033[33m非纯净模式不推荐使用此功能\033[0m"
[ -f $dir/pac ]&&echo -e "PAC地址\033[32m$pac\033[0m"
echo -----------------------------------------------
echo -e " 1 生成PAC文件"
echo -e " 2 清除PAC文件"
echo -----------------------------------------------
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
if [ "$num" = '1' ]; then
echo 'function FindProxyForURL(url, host) {' > $dir/pac
echo " return \"SOCKS $host:7890; PROXY $host:7890; DIRECT;\"" >> $dir/pac
echo '}' >> $dir/pac
echo -e "\033[33mPAC文件已生成\033[0m"
echo -e "PAC地址\033[32m$pac\033[0m"
echo "使用教程https://baike.baidu.com/item/PAC/16292100"
sleep 2
elif [[ $num == 2 ]]; then
rm -rf $dir/pac
echo -----------------------------------------------
echo -e "\033[33mPAC文件已清除\033[0m"
sleep 1
fi
}
setserver(){
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m您可以在此处切换在线更新时使用的资源地址\033[0m"
echo -e "当前源:\033[4;32m$update_url\033[0m"
echo -----------------------------------------------
echo -e " 1 CDN源(可能有一定的同步延迟)"
echo -e " 2 Github源(不稳定,不推荐)"
echo -e " 3 Github源+clash代理(需开启clash服务,推荐)"
echo -e " 1 Github源(使用host指定IP)"
echo -e " 2 CDN源(版本同步较慢)"
echo -e " 3 Github源+clash代理(需开启clash服务)"
echo -e " 4 自定义输入(请务必确保路径正确)"
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
@@ -617,13 +523,11 @@ if [ -z $num ]; then
echo -e "\033[31m请输入正确的数字\033[0m"
update
elif [[ $num == 1 ]]; then
update_url="https://cdn.jsdelivr.net/gh/juewuy/clash-for-Miwifi@latest"
elif [[ $num == 9 ]]; then
update_url="https://juewuy.xyz/clash"
update_url='--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master'
elif [[ $num == 2 ]]; then
update_url="https://raw.githubusercontent.com/juewuy/clash-for-Miwifi/master"
update_url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash'
elif [[ $num == 3 ]]; then
update_url="-x 127.0.0.1:7890 https://raw.githubusercontent.com/juewuy/clash-for-Miwifi/master"
update_url='-x 127.0.0.1:7890 https://raw.githubusercontent.com/juewuy/ShellClash/master'
elif [[ $num == 4 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
read -p "请输入个人源路径 > " update_url
@@ -632,6 +536,8 @@ elif [[ $num == 4 ]]; then
echo -e "\033[31m取消输入返回上级菜单\033[0m"
update
fi
elif [[ $num == 9 ]]; then
update_url='http://127.0.0.1:8080/clash-for-Miwifi'
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"

View File

@@ -1,7 +1,9 @@
#!/bin/sh
#!/bin/sh
# Copyright (C) Juewuy
getconfig(){
#加载环境变量
[ -z "$clashdir" ] && source /etc/profile > /dev/null 2>&1
ccfg=$clashdir/mark
if [ ! -f "$ccfg" ]; then
echo mark文件不存在默认以Redir模式运行
@@ -20,6 +22,137 @@ for portx in 1053 7890 7892 9999 ;do
[ -n "$(netstat -ntulp |grep :$portx|grep -v clash)" ] && echo -e "检测到端口:\033[30;47m $portx \033[0m被以下进程占用clash无法启动" && echo $(netstat -ntulp |grep :$portx) && exit;
done
}
getyaml(){
#前后端订阅服务器地址索引,可在此处添加!
Server=`sed -n ""$server_link"p"<<EOF
subconverter-web.now.sh
subconverter.herokuapp.com
subcon.py6.pw
api.dler.io
api.wcc.best
skapi.cool
EOF`
Config=`sed -n ""$rule_link"p"<<EOF
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online.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_NoReject.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_NoAuto.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_NoAuto.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
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"
markhttp=1
fi
#
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 正在连接服务器获取配置文件…………链接地址为:
echo -e "\033[4;32m$Https\033[0m"
echo 可以手动复制该链接到浏览器打开并查看数据是否正常!
echo -e "\033[36m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo -e "| |"
echo -e "| 需要一点时间,请耐心等待! |"
echo -e "| \033[0m如长时间没有数据请用ctrl+c退出\033[36m |"
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m"
#获取在线yaml文件
yaml=$clashdir/config.yaml
yamlnew=/tmp/config.yaml
rm -rf $yamlnew > /dev/null 2>&1
result=$(curl -w %{http_code} -kLo $yamlnew $Https)
if [ "$result" != "200" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m配置文件获取失败\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo
if [ -z $markhttp ];then
echo 请尝试使用导入节点/链接功能!
getlink
else
read -p "是否更换后端地址后重试?[1/0] > " res
if [ "$res" = '1' ]; then
sed -i '/server_link=*/'d $ccfg
if [[ $server_link -ge 6 ]]; then
server_link=0
fi
server_link=$(($server_link + 1))
echo $server_link
sed -i "1i\server_link=$server_link" $ccfg
Https=""
getyaml
fi
#exit;
fi
else
Https=""
if cat $yamlnew | grep ', server:' >/dev/null;then
#检测旧格式
if cat $yamlnew | grep 'Proxy Group:' >/dev/null;then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m已经停止对旧格式配置文件的支持\033[0m"
echo -e "请使用新格式或者使用\033[32m导入节点/订阅\033[0m功能"
sleep 2
clashlink
fi
#检测不支持的加密协议
if cat $yamlnew | grep 'cipher: chacha20,' >/dev/null;then
if [ "$clashcore" = "clash" -o "$clashcore" = "clashpre" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m当前核心$clashcore不支持chacha20加密\033[0m"
echo -e "请更换使用clashR核心"
sleep 2
getcore
fi
fi
#替换文件
[ -f $yaml ] && mv $yaml $yaml.bak
mv $yamlnew $yaml
echo 配置文件已生成正在启动clash使其生效
#重启clash服务
$0 stop
start_over(){
echo -e "\033[32mclash服务已启动\033[0m"
echo -e "可以使用\033[30;47m http://clash.razord.top \033[0m管理内置规则"
echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m 9999 \033[0m"
echo -e "也可前往更新菜单安装本地Dashboard面板连接更稳定\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
$0 start
sleep 1
PID=$(pidof clash)
if [ -n "$PID" ];then
start_over
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ -f $yaml.bak ];then
echo -e "\033[31mclash服务启动失败已还原配置文件并重启clash\033[0m"
mv $yaml.bak $yaml
$0 start
sleep 1
else
echo -e "\033[31mclash服务启动失败请查看报错信息\033[0m"
$clashdir/clash -d $clashdir & { sleep 3 ; kill $! & }
exit;
fi
fi
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m获取到了配置文件但格式似乎不对\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sed -n '1,30p' $yamlnew
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m请检查如上配置文件信息:\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fi
#exit;
fi
#exit
}
modify_yaml(){
##########需要变更的配置###########
mix='mixed-port: 7890'
@@ -77,11 +210,11 @@ exper='experimental: {ignore-resolve-fail: true, interface-name: en0}'
}
mark_time(){
start_time=`date +%s`
sed -i '/start_time*/'d $ccfg
sed -i "3i\start_time=$start_time" $ccfg
sed -i '/start_time*/'d $clashdir/mark
sed -i "1i\start_time=$start_time" $clashdir/mark
}
start_redir(){
#修改iptables规则使流量进入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 10.0.0.0/8 -j RETURN
@@ -94,9 +227,10 @@ start_redir(){
for mac in $(cat $clashdir/mac); do
iptables -t nat -A clash -m mac --mac-source $mac -j RETURN
done
#设置防火墙流量转发
iptables -t nat -A clash -p tcp $ports-j REDIRECT --to-ports 7892
iptables -t nat -A PREROUTING -p tcp -j clash
#设置ipv6转发
if [ "$ipv6_support" = "已开启" ];then
ip6tables -t nat -N clash
for mac in $(cat $clashdir/mac); do
@@ -125,7 +259,7 @@ stop_iptables(){
start_dns(){
#允许tun网卡接受流量
iptables -I FORWARD -o utun -j ACCEPT
ip6tables -I FORWARD -o utun -j ACCEPT
ip6tables -I FORWARD -o utun -j ACCEPT > /dev/null 2>&1
#设置dns转发
iptables -t nat -N clash_dns
for mac in $(cat $clashdir/mac); do
@@ -133,77 +267,87 @@ start_dns(){
done
iptables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to 1053
iptables -t nat -A PREROUTING -p udp -j clash_dns
#ipv6DNS
ip6tables -t nat -N clash_dns
for mac in $(cat $clashdir/mac); do
ip6tables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN
done
ip6tables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to 1053
ip6tables -t nat -A PREROUTING -p udp -j clash_dns
if [ "$ipv6_support" = "已开启" ];then
ip6tables -t nat -N clash_dns > /dev/null 2>&1
for mac in $(cat $clashdir/mac); do
ip6tables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN > /dev/null 2>&1
done
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
fi
}
daemon_old(){
#守护进程状态
status=$(ps |grep -w 'clash'|grep -v grep|grep -v clash.sh)
[ -z $status ] && $clashdir/clash -d $clashdir && mark_time
PID=$(pidof clash)
if [ -z "$PID" ];then
$clashdir/clash -d $clashdir > /dev/null &
mark_time
fi
}
checkcron(){
if [ -d /etc/crontabs/ ]; then
cronpath="/etc/crontabs/root"
elif [ -d /var/spool/cron/ ]; then
cronpath="/var/spool/cron/root"
elif [ -d /var/spool/cron/crontabs/ ]; then
cronpath="/var/spool/cron/crontabs/root"
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo "找不到定时任务文件,无法添加定时任务!"
fi
[ -d /etc/crontabs/ ]&&cronpath="/etc/crontabs/root"
[ -d /var/spool/cron/ ]&&cronpath="/var/spool/cron/root"
[ -d /var/spool/cron/crontabs/ ]&&cronpath="/var/spool/cron/crontabs/root"
if [ -z $cronpath ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo "找不到定时任务文件,无法添加定时任务!"
clashsh
fi
}
start_old(){
afstart(){
#读取配置文件
getconfig
#使用内置规则强行覆盖config配置文件
[ "$modify_yaml" != "已开启" ] && modify_yaml
#创建clash后台进程
$clashdir/clash -d $clashdir> /dev/null &
#修改iptables规则使流量进入clash
stop_iptables
start_dns
[ "$redir_mod" != "Tun模式" ] && start_redir
[ "$redir_mod" != "纯净模式" ] && start_dns
[ "$redir_mod" != "纯净模式" ] && [ "$redir_mod" != "Tun模式" ] && start_redir
#标记启动时间
mark_time
#创建守护进程
checkcron
sed -i /start.sh/d $cronpath
echo "*/1 * * * * source /etc/profile && source $clashdir/start.sh && daemon_old >/dev/null 2>&1" >> $cronpath
#设定启动方式
sed -i /start_old=*/d $ccfg
sed -i "1i\start_old=已开启" $ccfg
}
stop_old(){
#删除守护
checkcron
sed -i /start.sh/d $cronpath
#结束进程
killall -9 clash &> /dev/null
stop_iptables
}
start(){
getconfig
if [ "$start_old" ="已开启" ];then
start_old
else
/etc/init.d/clash start
fi
}
stop(){
getconfig
if [ "$start_old" ="已开启" ];then
stop_old
else
/etc/init.d/clash stop
fi
}
restart(){
stop
start
}
case "$1" in
afstart)
afstart
;;
start)
#读取配置文件
getconfig
#使用内置规则强行覆盖config配置文件
[ "$modify_yaml" != "已开启" ] && modify_yaml
#使用不同方式启动clash服务
if [ "$start_old" = "已开启" ];then
$clashdir/clash -d $clashdir >/dev/null 2>&1 &
afstart
elif [ -f /etc/rc.common ];then
/etc/init.d/clash start
else
systemctl start clash.service
fi
;;
stop)
#删除守护
checkcron
sed -i /start.sh/d $cronpath >/dev/null 2>&1
#多种方式结束进程
if [ -f /etc/rc.common ];then
/etc/init.d/clash stop >/dev/null 2>&1
else
systemctl stop clash.service >/dev/null 2>&1
fi
killall -9 clash >/dev/null 2>&1
#清理iptables
stop_iptables
;;
restart)
$0 stop
$0 start
;;
getyaml)
getconfig
getyaml
;;
esac
exit 0