47 Commits

Author SHA1 Message Date
juewuy
f16ba5a49d v1.0.0beta11
~同步最新GeoIP数据库
~修复启动失败后依然提示服务启动的bug
~屏蔽经常出现的netstat命令提示
~优化节点链接导入功能
~修复部分设备开启ipv6后造成dns污染的问题
2020-10-01 19:14:29 +08:00
juewuy
b83104a888 v1.0.0beta10fix3
~修复启动失败后依然提示服务启动的bug
~屏蔽经常出现的netstat命令提示
~优化节点链接导入功能
~修复部分设备开启ipv6后造成dns污染的问题
2020-10-01 18:45:26 +08:00
juewuy
e9674a1ca6 v1.0.0beta10fix2
~增加大量订阅内置规则
~修复偶尔无法正常更新的bug
~修复导入订阅时无法正常启动的bug
~修复ac2100核心无法正常工作的bug
~修复切换更新源后无法正常更新的bug
2020-09-29 19:40:07 +08:00
juewuy
29f7ba1518 v1.0.0beta10fix2
~增加大量订阅内置规则
~修复偶尔无法正常更新的bug
~修复导入订阅时无法正常启动的bug
~修复ac2100核心无法正常工作的bug
~修复切换更新源后无法正常更新的bug
2020-09-29 19:31:12 +08:00
juewuy
baf0b1adc5 v1.0.0beta10fix2
~增加大量订阅内置规则
~修复偶尔无法正常更新的bug
~修复导入订阅时无法正常启动的bug
~修复ac2100核心无法正常工作的bug
2020-09-29 19:03:45 +08:00
juewuy
dbe7ca280a v1.0.0beta10fix1
~增加大量订阅内置规则
~修复偶尔无法正常更新的bug
~修复导入订阅时无法正常启动的bug
~修复ac2100核心无法正常工作的bug
2020-09-29 19:02:28 +08:00
juewuy
87e1d5773c v1.0.0beta10
~同步Premium核心版本至20200927
~增加对小米/红米AC2100系列设备的支持
~修复了默认配置设置显示与实际设置不符的bug
2020-09-28 22:05:18 +08:00
juewuy
e78b336edf v1.0.0beta10
~同步Premium核心版本至20200927
~增加对小米/红米AC2100系列设备的支持
~修复了默认配置设置显示与实际设置不符的bug
2020-09-28 21:11:00 +08:00
juewuy
aa2f16a7d9 v1.0.0beta10
~同步Premium核心版本至20200927
~增加对小米/红米AC2100系列设备的支持
~修复了默认配置设置显示与实际设置不符的bug
2020-09-28 21:10:37 +08:00
juewuy
7c18992e9b v1.0.0beta10
~同步Premium核心版本至20200927
~增加对小米/红米AC2100系列设备的支持
~修复了默认配置设置显示与实际设置不符的bug
2020-09-28 21:02:46 +08:00
juewuy
99af6fe1d9 v1.0.0beta10
~同步Premium核心版本至20200927
~增加对小米/红米AC2100系列设备的支持
~修复了默认配置设置显示与实际设置不符的bug
2020-09-28 20:56:00 +08:00
juewuy
38aeddd90d v1.0.0beta9fix2
~修复ipv6开启后dns被污染的问题
~修复导入订阅后不显示本机host地址的问题
~修复卸载时未清理本机代理的bug
2020-09-25 10:10:33 +08:00
juewuy
ddf17bf39a v1.0.0beta9fix1
~修复部分设备启动时报错的bug
~修改更新脚本,优化更新流程
~安装systemd启动脚本时增加reload
~进一步优化安装脚本
2020-09-21 23:53:27 +08:00
juewuy
85af5ed310 v1.0.0beta9
~修复部分设备启动时报错的bug
~修改更新脚本,优化更新流程
~安装systemd启动脚本时增加reload
~进一步优化安装脚本
2020-09-21 23:51:03 +08:00
juewuy
84cda4034a v1.0.0beta9
~优化本机代理功能
~修复GoogleHome无法使用的问题(待测试)
~调整启动脚本,适配Openwrt旧版本设备
~修复非Openwrt系统下定时任务不生效的bug
~修复保守模式守护进程不生效的bug
~修复手动更新订阅功能出错的bug
~优化更新订阅时的启动逻辑
~屏蔽ClashR核心下载,如有必要请在选择界面输入“3”以切换
2020-09-21 17:04:04 +08:00
juewuy
8bc51d57eb v1.0.0beta9
~优化本机代理功能
~修复GoogleHome无法使用的问题(待测试)
~调整启动脚本,适配Openwrt旧版本设备
~修复非Openwrt系统下定时任务不生效的bug
~修复保守模式守护进程不生效的bug
~修复手动更新订阅功能出错的bug
~优化更新订阅时的启动逻辑
~屏蔽ClashR核心下载,如有必要请在选择界面输入“3”以切换
2020-09-21 16:51:14 +08:00
juewuy
cafef2f413 v1.0.0beta9
~修复手动更新订阅功能出错的bug
~调整本机代理功能设置
~修复GoogleHome无法使用的问题
~调整启动脚本,适配旧版本设备
~修复非Openwrt系统下定时任务不生效的bug
~修复保守模式守护进程不生效的bug
~优化更新订阅时的启动逻辑
2020-09-21 16:21:26 +08:00
juewuy
93e74b5579 v1.0.0beta8fix2
~修复手动更新订阅功能出错的bug
~调整本机代理功能设置
~修复GoogleHome无法使用的问题
~调整启动脚本,适配部分采用openwrt12等旧版本的设备
2020-09-20 19:12:48 +08:00
juewuy
b74ae6b114 v1.0.0beta8fix2
~修复手动更新订阅功能出错的bug
~调整本机代理功能设置
~修复GoogleHome无法使用的问题
~调整启动脚本,适配部分采用openwrt12等旧版本的设备
2020-09-20 18:48:27 +08:00
juewuy
60a01d0358 v1.0.0beta8fix2
~修复手动更新订阅功能出错的bug
~调整本机代理功能设置
~修复GoogleHome无法使用的问题
~调整启动脚本,适配部分采用openwrt12等旧版本的设备
2020-09-20 18:47:13 +08:00
juewuy
1194671896 v1.0.0beta8fix2
~修复手动更新订阅功能出错的bug
~调整本机代理功能设置
~修复GoogleHome无法使用的问题
~调整启动脚本,适配部分采用openwrt12等旧版本的设备
2020-09-20 18:23:05 +08:00
juewuy
1ab371b08e v1.0.0beta8fix2
~修复手动更新订阅功能出错的bug
~调整本机代理功能设置
~修复GoogleHome无法使用的问题
~调整启动脚本,适配部分采用openwrt12等旧版本的设备
2020-09-20 17:57:21 +08:00
juewuy
af50730d3a v1.0.0beta8fix
~修复手动更新订阅功能出错的bug
~调整本机代理功能设置
~修复GoogleHome无法使用的问题
2020-09-20 14:37:35 +08:00
juewuy
0abe34884e 增加测试安装脚本 2020-09-20 12:25:19 +08:00
juewuy
4c2222a75e v1.0.0beta8
~修复手动更新订阅功能出错的bug
~调整本机代理功能设置
~修复GoogleHome无法使用的问题
2020-09-20 12:16:53 +08:00
juewuy
bc5ca550fb v1.0.0beta8
~修复手动更新订阅功能出错的bug
~调整本机代理功能设置
~修复GoogleHome无法使用的问题
2020-09-20 12:01:10 +08:00
juewuy
95bc9d6d55 v1.0.0beta8
~修复手动更新订阅功能出错的bug
~调整本机代理功能设置
~修复GoogleHome无法使用的问题
2020-09-20 11:59:01 +08:00
juewuy
1c76af82aa v1.0.0beta8
~修复手动更新订阅功能出错的bug
~调整本机代理功能设置
~修复GoogleHome无法使用的问题
2020-09-20 11:47:50 +08:00
juewuy
cf621a47ac v1.0.0beta7fix
~修复手动更新订阅功能出错的bug
~调整本机代理功能设置
2020-09-19 22:06:01 +08:00
juewuy
9dc284572b v1.0.0beta7
~全面兼容Debian/Armbian/Centos等标准Linux系统
~增加配置本机代理功能
~重写启动脚本,优化在不同系统下的启动方式
~支持以systemd方式启动及守护进程
~~大幅度优化优化安装脚本及更新机制,修复cdn更新延迟
~修改定时任务机制,增加稳定性
2020-09-19 17:06:01 +08:00
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
21 changed files with 860 additions and 537 deletions

View File

@@ -1,44 +1,44 @@
# ShellClash原Clash for Miwifi
shell环境下一键部署及管理[clash](https://github.com/Dreamacro/clash)
Shell环境下一键部署及管理[Clash](https://github.com/Dreamacro/clash)
=====
功能简介:
--
~通过管理脚本在shell环境下便捷使用[clash](https://github.com/Dreamacro/clash)<br>
~支持在shell环境下管理[clash各种功能](https://lancellc.gitbook.io/clash)<br>
~支持批量导入SS/SSR/v2ray/trojan节点链接及各种订阅链接<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>~支持在线更新管理脚本及升级Clash核心<br>
设备支持:
--
~支持小米/红米全系使用官方系统或官方开发版系统的路由器设备<br>
~支持各种基于OpenWrt或使用OpenWrt二次定制开发的路由器设备<br>
~支持各种运行标准Linux系统如Debian/CenOS/Armbian等的设备<br>
~更多设备请提issue或前往TG群反馈需提供设备名称及运行uname -a返回的设备核心信息<br>
使用方式:
--
~确认路由器或设备已经开启SSH并获取root权限<br>
~使用SSH连接工具如puttyJuiceSSHmac终端登陆路由器或设备的SSH管理界面<br>
~在SSH界面执行如下安装命令并按照提示安装clash管理脚本<br>
openwrt输入
~使用SSH连接工具如puttyJuiceSSH系统自带终端等)路由器或设备的SSH管理界面并切换到root用户<br>
~在SSH界面执行如下安装命令并按照后续提示完成安装<br>
```Shell
sh -c "$(curl -kfsSl https://cdn.jsdelivr.net/gh/juewuy/ShellClash@latest/install.sh)" && source /etc/profile &> /dev/null
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
```
其他Linux系统输入
或者
```Shell
bash -c "$(curl -kfsSl https://cdn.jsdelivr.net/gh/juewuy/ShellClash@latest/install.sh)" && source /etc/profile &> /dev/null
sh -c "$(curl -kfsSl https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master/install_cdn.sh)" && source /etc/profile &> /dev/null
```
~安装完成管理脚本后,执行如下命令以运行管理脚本<br>
```Shell
clash
```
设备支持:
--
~支持小米/红米全系使用官方系统或官方开发版系统的路由器设备ac2100系列除外<br>
~支持所有基于openwrt或使用openwrt二次开发的路由器设备<br>
~有限兼容各种运行标准Linux系统如debian、centos等发行版系统的设备<br>
~不兼容的Linux设备或CPU架构请提issue提供设备名称及运行uname -a返回的设备核心信息或前往TG群反馈<br>
更新日志:
--
https://github.com/juewuy/clash-for-Miwifi/releases
https://github.com/juewuy/ShellClash/releases
交流反馈:
--
@@ -49,8 +49,8 @@ https://github.com/juewuy/clash-for-Miwifi/releases
~Tun模式下clash服务可能会和路由器内置的网游加速器冲突请谨慎同时使用<br>
~Redir模式暂不支持转发udp流量外服游戏可能会受影响外服游戏用户建议使用Tun模式<br>
~部分设备长时间使用会出现内存占用偏高——此为golang内存回收不及时导致可以通过屏蔽p2p流量及设置每日定时重启核心以缓解<br>
~节点无法连接——在【clash功能设置】中打开【跳过本地证书验证】<br>
~节点无法连接——在【clash功能设置】中打开【跳过本地证书验证】或者升级clash核心<br>
友情推广:
--
https://dler.best/auth/register?affid=89698
[顶级8K专线机场-墙洞](https://dler.best/auth/register?affid=89698)

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.

Binary file not shown.

Binary file not shown.

View File

@@ -1 +1 @@
version=2020.08.16
version=2020.09.27

View File

@@ -1,2 +1,2 @@
GeoIP_v=20200913
versionsh=1.0.0.beta5
versionsh=1.0.0beta10fix2
GeoIP_v=20201001

View File

@@ -1,27 +1,86 @@
#! /bin/bash
# Copyright (C) Juewuy
echo='echo -e' && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && echo=echo
test=0
echo "***********************************************"
echo "** 欢迎使用 **"
echo "** ShellClash **"
echo "** by Juewuy **"
echo "***********************************************"
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash@latest"
result=$(curl -w %{http_code} -skLo /tmp/clashversion $url/bin/version)
[ "$result" != "200" ] && echo "无法连接到服务器!" && exit 1
source /tmp/clashversion
echo -e "~~~~版本:\033[32m$versionsh\033[0m"
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"
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
}
#输出
$echo "最新版本:\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 "\033[44m如遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
$echo "\033[37m支持各种基于openwrt的路由器设备"
$echo "\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 "\033[32m 1 在默认目录(/etc)安装"
$echo "\033[33m 2 手动设置安装目录"
$echo "\033[0m 0 退出安装"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
read -p "请输入相应数字 > " num
#设置目录
if [ -z $num ];then
echo 安装已取消
exit;
@@ -41,46 +100,16 @@ else
echo 安装已取消
exit;
fi
#下载文件包
clashdir=$dir/clash
#输出
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 开始从服务器获取安装文件!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tarurl=$url/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
#初始化文件目录
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
sed -i '/versionsh_l=*/'d $dir/clash/mark
sed -i "1i\versionsh_l=$versionsh" $dir/clash/mark
#设置环境变量
shtype=sh&&[ -n $(ls -l /bin/sh|grep -o dash) ]&&shtype=bash
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
#提示
#下载及安装
gettar
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ShellClash 已经安装成功!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理\033[0m"
$echo "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

115
install_cdn.sh Normal file
View File

@@ -0,0 +1,115 @@
#! /bin/bash
# Copyright (C) Juewuy
echo='echo -e' && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && echo=echo
test=0
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"
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
}
#输出
$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"
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 路径错误!已取消安装!
exit;
fi
else
echo 安装已取消
exit;
fi
clashdir=$dir/clash
#输出
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 开始从服务器获取安装文件!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#下载及安装
gettar
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ShellClash 已经安装成功!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$echo "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

115
install_test.sh Normal file
View File

@@ -0,0 +1,115 @@
#! /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"
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
}
#输出
$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"
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 路径错误!已取消安装!
exit;
fi
else
echo 安装已取消
exit;
fi
clashdir=$dir/clash
#输出
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 开始从服务器获取安装文件!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#下载及安装
gettar
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ShellClash 已经安装成功!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$echo "\033[33m输入\033[30;47m clash \033[0;33m命令即可管理\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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,28 +1,43 @@
#!/bin/bash
#!/bin/sh
# Copyright (C) Juewuy
getconfig(){
#系统类型
if [ -f /bin/opkg ];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}';)
else
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
fi
#服务器地址
[ -z "$update_url" ] && update_url=https://cdn.jsdelivr.net/gh/juewuy/ShellClash@latest
[ -z "$update_url" ] && update_url=https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master
#文件路径
[ -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
#标识clash运行状态的文件不明勿动
EOF
fi
[ ! -f $ccfg ]&& echo '#标识clash运行状态的文件不明勿动' >> $ccfg
source $ccfg
#检查mac地址记录
[ ! -f $clashdir/mac ] && touch $clashdir/mac
#获取自启状态
#开机自启相关
if [ -f /etc/rc.common ];then
if [ -f /etc/rc.d/*clash ];then
autostart=enable_rc
else
autostart=disable_rc
fi
else
if [ -n "$(systemctl list-unit-files clash.service | grep -o enable)" ];then
autostart=enable_sys
else
autostart=disable_sys
fi
fi
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
@@ -35,11 +50,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))
@@ -59,7 +73,7 @@ fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 "TG群\033[36;4mhttps://t.me/clashfm\033[0m"
@@ -80,55 +94,8 @@ 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
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clashstop
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"
read -p "是否尝试使用保守方式启动?[1/0] > " res
if [ "$res" = '1' ]; 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
echo -e "\033[33m操作取消\033[0m"
exit
fi
fi
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}';)
start_over(){
[ $? -eq 1 ] && exit
echo -e "\033[32mclash服务已启动\033[0m"
if [ -d /www/clash ];then
echo -e "请使用\033[30;47m http://$host/clash \033[0m管理内置规则"
@@ -141,16 +108,36 @@ clashstart(){
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fi
}
clashstart(){
if [ ! -f "$yaml" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m没有找到配置文件请先导入节点/订阅链接!\033[0m"
clashlink
fi
if [ -n "$PID" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$clashdir/start.sh stop
echo -e "\033[31mClash服务已停止\033[0m"
fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$clashdir/start.sh start
sleep 1
PID=$(pidof clash)
if [ -z "$PID" ];then
$clashdir/start.sh stop
echo -e "\033[31mclash启动失败\033[0m"
exit
fi
start_over
}
clashlink(){
#获取订阅规则
if [ -z "$rule_link" ]; then
sed -i '/rule_link=*/'d $ccfg
sed -i "4i\rule_link=1" $ccfg
rule_link=1
fi
#获取后端服务器地址
if [ -z "$server_link" ]; then
sed -i '/server_link=*/'d $ccfg
sed -i "5i\server_link=1" $ccfg
server_link=1
fi
@@ -158,7 +145,7 @@ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m 欢迎使用订阅功能!\033[0m"
echo -----------------------------------------------
echo -e " 1 导入\033[36m节点/订阅\033[0m链接"
echo -e " 2 使用完整clash规则链接"
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 选择在线生成服务器"
@@ -241,18 +228,19 @@ elif [[ $num == 6 ]];then
elif [[ $num == 7 ]];then
if [ -z "$Url" -a -z "$Https" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 没有找到你的订阅链接!请先输入链接!
echo -e "\033[31m没有找到你的订阅链接!请先输入链接!\033[0m"
sleep 2
clashlink
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m当前系统记录的订阅链接为\033[0m"
echo -e "\033[4;32m$Url\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
read -p "确认更新配置文件?[1/0] > " res
if [ "$res" = '1' ]; then
source $clashdir/getdate.sh
getyaml
$clashdir/start.sh getyaml
start_over
exit;
fi
clashlink
fi
@@ -338,7 +326,6 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
redir_mod=混合模式
elif [[ $num == 4 ]]; then
redir_mod=纯净模式
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[32m已经设置为纯净模式\033[0m"
echo -e "\033[33m当前模式必须手动在设备WiFi或应用中配置HTTP或sock5代理\033[0m"
@@ -368,7 +355,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 返回上级菜单"
@@ -524,6 +511,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"
@@ -533,6 +521,7 @@ 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 " 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服务"
@@ -584,16 +573,39 @@ 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
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
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_proxy' >> /etc/profile
echo 'export HTTP_PROXY=$http_proxy' >> /etc/profile
echo 'export HTTPS_PROXY=$http_proxy' >> /etc/profile
echo -e "\033[32m已经将代理参数写入环境变量~\033[0m"
echo -e "\033[36m如未生效请重新登录或者重启设备\033[0m"
sleep 1
else
sed -i "1i\local_proxy=未开启" $ccfg
sed -i '/http*_proxy/'d /etc/profile
sed -i '/HTTP*_PROXY/'d /etc/profile
echo -e "\033[33m已经将代理参数从环境变量移除\033[0m"
local_proxy=未开启
fi
source /etc/profile > /dev/null 2>&1
clashadv
elif [[ $num == 8 ]]; then
read -p "确认重置配置文件?(1/0) > " res
if [ "$res" = "1" ];then
@@ -620,11 +632,20 @@ fi
exit;
}
update(){
if [ -z "$release_new" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m正在检查更新\033[0m"
if [ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master" ];then
release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 --connect-timeout 3 -m 3 "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')
update_url=$update_url@$release_new
fi
[ -z "$release_new" ] && release_new=$(curl -kfsSL --connect-timeout 3 -m 3 $update_url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
[ -z "$release_new" ] && echo "检查更新失败!"
fi
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[32malecthw大神提供的GeoIP数据库\033[0m 项目地址:\033[32mhttps://github.com/alecthw/mmdb_china_ip_list\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"
@@ -632,8 +653,9 @@ 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 " 9 \033[31m卸载\033[34mClash for Miwfi\033[0m"
echo -e " 7 切换\033[36m安装源\033[0m地址"
echo -e " 8 鸣谢"
echo -e " 9 \033[31m卸载\033[34mShellClash\033[0m"
echo -e " 0 返回上级菜单"
echo -----------------------------------------------
read -p "请输入对应数字 > " num
@@ -663,22 +685,35 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
catpac
update
elif [[ $num == 8 ]]; then
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[32msubconverter \033[0m作者\033[36m tindy2013\033[0m 项目地址:\033[32mhttps://github.com/tindy2013/subconverter\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
read -p "确认卸载ShellClash警告该操作不可逆[1/0] " res
if [ "$res" = '1' ]; then
/etc/init.d/clash disable
/etc/init.d/clash stop
$clashdir/start.sh 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
echo 已卸载clash相关文件
sed -i '/http*_proxy/'d /etc/profile
sed -i '/HTTP*_PROXY/'d /etc/profile
source /etc/profile > /dev/null 2>&1
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 已卸载ShellClash相关文件有缘再会
exit
fi
echo -e "\033[31m操作已取消\033[0m"
exit;
@@ -761,17 +796,15 @@ clashcron(){
echo "$min $hour * * $week $cronset >/dev/null 2>&1 #$week1的$hour点$min分$cronname" >> $cronpath
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m定时任务已添加\033[0m"
chmod 600 $cronpath #修改权限
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
@@ -784,13 +817,13 @@ 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服务"
echo -e " 3 设置\033[32m定时开启\033[0mclash服务"
echo -e " 4 设置\033[33m定时更新\033[0m订阅链接(实验性,可能不稳定)"
echo -e " 4 设置\033[33m定时更新\033[0m订阅并重启服务"
echo -----------------------------------------------
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
@@ -804,19 +837,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
@@ -854,7 +887,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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -867,12 +900,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
@@ -908,9 +949,9 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
elif [[ $num == 0 ]]; then
clashsh
elif [[ $num == 1 ]]; then
clashstop
$clashdir/start.sh stop
echo -----------------------------------------------
$clashdir/clash -d $clashdir & { sleep 3 ; kill $! & }
$clashdir/clash -t -d $clashdir
echo -----------------------------------------------
echo -e "\033[31m如有报错请截图后到TG群询问\033[0m"
exit;
@@ -949,15 +990,6 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -e "\033[31m连接超时请重试或检查节点配置\033[0m"
fi
clashsh
elif [[ $num == 7 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for PID in $(ps|awk '{print $1}');do
[ -f "/proc/$PID/status" ] && vmrss=$(cat /proc/$PID/status|grep -w VmRSS|awk '{print $2}')
[ -n "$vmrss" ] && echo $vmrss $(cat /proc/$PID/status|grep -w Name|awk '{print $2}')
done
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit;
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"

View File

@@ -1,37 +1,33 @@
#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007 OpenWrt.org
USE_PROCD=1
START=92
SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1
USE_PROCD=1
DIR=$(cat /etc/profile|grep clashdir|awk -F "\"" '{print $2}')
start_service() {
#开机加载环境变量保证找到文件路径
source /etc/profile > /dev/null 2>&1
#加载修饰脚本
source $clashdir/start.sh
#读取配置文件
getconfig
#使用内置规则强行覆盖config配置文件
[ "$modify_yaml" != "已开启" ] && modify_yaml
#创建clash后台进程
#使用procd创建clash后台进程
procd_open_instance
procd_set_param respawn
procd_set_param stderr 1
procd_set_param stdout 1
procd_set_param command $clashdir/clash -d $clashdir
procd_set_param command $DIR/clash -d $DIR
procd_close_instance
#修改iptables规则使流量进入clash
stop_iptables
[ "$redir_mod" != "纯净模式" ] && start_dns
[ "$redir_mod" != "纯净模式" ] && [ "$redir_mod" != "Tun模式" ] && start_redir
#标记启动时间
mark_time
#标记启动方式
sed -i /start_old=*/d $ccfg
sed -i "1i\start_old=未开启" $ccfg
#其他设置
$DIR/start.sh afstart
}
stop_service() {
source $clashdir/start.sh
stop_iptables
start() {
if [ -z "$(pidof procd)" ];then
#创建后台进程
service_start $DIR/clash -d $DIR
#设置守护进程
$DIR/start.sh deamon
#其他设置
$DIR/start.sh afstart
else
start_service
fi
}

View File

@@ -1,182 +1,32 @@
#!/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"
echo -e "\033[33m5秒后尝试使用保守方式启动使用ctrl+c退出\033[0m"
echo 5&&sleep 1&&echo 4&&sleep 1&&echo 3&&sleep 1&&echo 2&&sleep 1&&echo 1&&sleep 1
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,30p' $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"
echo 当前使用规则为:$rule_link
echo 1 ACL4SSR默认通用版
echo 1 ACL4SSR通用版无去广告(推荐)
echo 2 ACL4SSR精简全能版推荐
echo 3 ACL4SSR通用版+去广告加强
echo 4 ACL4SSR精简版+去广告加强
echo 5 ACL4SSR通用版无去广告
echo 6 ACL4SSR通用版无自动测速
echo 7 ACL4SSR精简版无自动测速
echo 8 ACL4SSR全分组+奈飞(慎用)
echo 9 ACL4SSR全分组+去广告(慎用)
echo 5 ACL4SSR重度全分组+奈飞分流
echo 6 ACL4SSR重度全分组+去广告加强
echo 7 洞主规则精简版(推荐)
echo 8 洞主规则重度完整版
echo 9 神机规则高级版
echo 10 神机规则-回国专用
echo 11 李哥规则-墙洞专用
echo 12 基础规则-仅Geoip CN+Final
echo 13 网易云解锁-仅规则分组
echo -----------------------------------------------
echo 0 返回上级菜单
read -p "请输入对应数字 > " num
if [ -z "$num" ] || [[ $num -gt 9 ]];then
if [ -z "$num" ] || [[ $num -gt 13 ]];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
elif [[ "$num" = 0 ]];then
echo
elif [[ $num -le 9 ]];then
elif [[ $num -le 13 ]];then
#将对应标记值写入mark
sed -i '/rule_link*/'d $ccfg
sed -i "4i\rule_link="$num"" $ccfg
@@ -220,7 +70,7 @@ echo -e "\033[33m当前过滤关键字\033[47;30m$exclude\033[0m"
echo -----------------------------------------------
echo -e "\033[36m匹配关键字的节点会在导入时被屏蔽\033[0m"
echo -e "多个关键字可以用\033[30;47m | \033[0m号分隔"
echo -e "\033[32m支持正则表达式\033[0m特殊符号请使用\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 " 回车 取消输入并返回上级菜单"
@@ -239,6 +89,7 @@ linkset
}
linkset(){
if [ -n $Url ];then
[ -z "$skip_cert" ] && skip_cert=已开启
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[47;30m请检查输入的链接是否正确\033[0m"
echo -e "\033[32;4m$Url\033[0m"
@@ -247,7 +98,7 @@ 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 -e " 5 \033[0m跳过本地证书验证 \033[36m$skip_cert\033[0m ————自建tls节点务必开启"
echo -----------------------------------------------
echo -e " 0 \033[31m取消导入\033[0m并返回上级菜单"
echo -----------------------------------------------
@@ -263,7 +114,9 @@ if [ -n $Url ];then
sed -i "6i\Url=\'$Url\'" $ccfg
Https=""
#获取在线yaml文件
getyaml
$clashdir/start.sh getyaml
start_over
exit;
elif [ "$num" = '2' ]; then
linkfilter
linkset
@@ -303,7 +156,8 @@ do
echo -e "\033[44m 遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
echo -----------------------------------------------
echo -e "支持批量导入\033[30;46m Http/Https/Clash \033[0m等格式的订阅链接"
echo -e "以及\033[30;42m Vmess/SSR/SS/Trojan/Sock5 \033[0m等格式的节点链接"
echo -e "以及\033[30;42m Vmess/SSR/SS/Trojan \033[0m等格式的节点链接"
echo -e "自建Trojan节点链接格式为trojan://密码@host地址:443"
echo -----------------------------------------------
echo -e "多个较短的链接可以用\033[30;47m | \033[0m号分隔以一次性输入"
echo -e "多个较长的链接可分次输入,支持多达\033[30;47m 99 \033[0m次输入"
@@ -318,15 +172,16 @@ do
url=`echo ${url/\&config\=*/""}` #将clash完整链接还原成单一链接
url=`echo ${url//\&/\%26}` #将分隔符 & 替换成urlcode%26
if [[ "$test" != "" ]];then
if [[ -z $Url ]];then
if [ -z "$Url" ];then
Url="$url"
else
Url="$Url"\|"$url"
fi
i=$(($i+1))
elif [ -z $url ];then
linkset
[ -n "$Url" ] && linkset
elif [[ $url == 0 ]];then
Url=""
clashlink
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -341,12 +196,11 @@ clashlink
}
getlink2(){
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m 此功能不明勿用,出问题自行解决\033[0m"
echo -e "\033[30;47m 此功能不明勿用!\033[0m"
echo -----------------------------------------------
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 -----------------------------------------------
echo -e "\033[33m0 返回上级菜单\033[0m"
echo -----------------------------------------------
@@ -366,7 +220,9 @@ if [ -n $Https ];then
sed -i '/Https=*/'d $ccfg
sed -i "6i\Https=\'$Https\'" $ccfg
#获取在线yaml文件
getyaml
$clashdir/start.sh getyaml
start_over
exit;
fi
clashlink
fi
@@ -377,48 +233,70 @@ else
echo -e "\033[31m请输入正确的链接地址\033[0m"
fi
}
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
}
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
if command -v curl &> /dev/null; 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
[ $? -eq 0 ] && result="200"
fi
[ "$result" != "200" ] && echo "文件下载失败!" && exit 1
#解压
echo -----------------------------------------------
echo 开始解压文件!
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 #授予权限
#写入版本号
sed -i '/versionsh_l=*/'d $ccfg
sed -i "1i\versionsh_l=$versionsh" $ccfg
#删除临时文件
rm -rf /tmp/clashfm.tar.gz
rm -rf /tmp/clashversion
tarurl=$update_url/bin/clashfm.tar.gz
#下载更新
gettar
#提示
echo -----------------------------------------------
echo -e "\033[32m管理脚本更新成功!\033[0m"
echo -----------------------------------------------
exit;
else
clashsh
else
update
fi
}
getcore(){
@@ -430,27 +308,27 @@ if [ ! -f $clashdir/clash ]; then
fi
clashcore_n=$clashcore
#获取设备处理器架构
cpucore=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
[ -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="amd64"
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.*")" ] && cpucore="armv7"
[ -n "$(echo $cputype | grep -E "linux.*aarch64.*")" ] && cpucore="armv8"
[ -n "$(echo $cputype | grep -E "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
cpucore="mipsle-softfloat"
[ -n "$(uname -a | grep -E "M2100")" ] && cpucore="mipsle-hardfloat"
fi
###
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "当前clash核心\033[47;30m $clashcore \033[46;30m$clashv\033[0m"
echo -e "\033[32m请选择需要下载的核心版本\033[0m"
echo -----------------------------------------------
echo "1 clash 稳定,内存占用小,推荐!"
echo "(官方正式版) 不支持chacha20加密不支持Tun模式"
echo "(官方正式版) 不支持Tun模式"
echo
echo "2 clashr 内存占用小支持chacha20加密"
echo "(clashR修改版)不支持Tun模式"
echo
echo "3 clashpre 支持Tun模式"
echo "(高级预览版) 内存占用高不支持chacha20加密"
echo "2 clashpre 支持Tun模式、混合模式"
echo "(高级预览版) 内存占用更高"
echo -----------------------------------------------
echo 0 返回上级菜单
read -p "请输入对应数字 > " num
@@ -463,9 +341,9 @@ read -p "请输入对应数字 > " num
elif [[ $num == 1 ]]; then
clashcore=clash
elif [[ $num == 2 ]]; then
clashcore=clashr
elif [[ $num == 3 ]]; then
clashcore=clashpre
elif [[ $num == 3 ]]; then
clashcore=clashr
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"
@@ -522,6 +400,7 @@ 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
@@ -553,7 +432,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 -----------------------------------------------
@@ -622,7 +501,7 @@ 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}';)
#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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -656,9 +535,9 @@ 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源(仅同步最新release版本)"
echo -e " 3 Github源+clash代理(需开启clash服务)"
echo -e " 4 自定义输入(请务必确保路径正确)"
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
@@ -667,13 +546,11 @@ if [ -z $num ]; then
echo -e "\033[31m请输入正确的数字\033[0m"
update
elif [[ $num == 1 ]]; then
update_url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash@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/ShellClash/master"
update_url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master'
elif [[ $num == 3 ]]; then
update_url="-x 127.0.0.1:7890 https://raw.githubusercontent.com/juewuy/ShellClash/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
@@ -682,6 +559,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"
@@ -692,5 +571,6 @@ sed -i '/update_url*/'d $ccfg
sed -i "1i\update_url=\'$update_url\'" $ccfg
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[32m源地址更新成功\033[0m"
release_new=""
update
}

View File

@@ -1,24 +1,147 @@
#!/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模式运行
cat >$ccfg<<EOF
#标识clash运行状态的文件不明勿动
EOF
#指定一些默认状态
redir_mod=redir模式
modify_yaml=开启
fi
source $ccfg #加载配置文件
#检查/读取标识文件
[ ! -f $ccfg ]&& echo '#标识clash运行状态的文件不明勿动' >> $ccfg
source $ccfg
#默认设置
[ -z "$skip_cert" ] && skip_cert=已开启
[ -z "$common_ports" ] && common_ports=已开启
[ -z "$dns_mod" ] && dns_mod=redir_host
[ -z "$dns_over" ] && dns_over=开启
[ -z "$modify_yaml" ] && modify_yaml=未开启
[ -z "$ipv6_support" ] && ipv6_support=未开启
[ -z "$start_old" ] && start_old=未开启
[ -z "$local_proxy" ] && local_proxy=未开启
#是否代理常用端口
[ "$common_ports" = "已开启" ] && ports='-m multiport --dports 22,53,587,465,995,993,143,80,443 '
#检测系统端口占用
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_NoReject.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiMode.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_AdblockPlus.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_AdblockPlus.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_Netflix.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_AdblockPlus.ini
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_clash.ini
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/lhie1_dler.ini
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/connershua_pro.ini
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/connershua_backtocn.ini
https://gist.githubusercontent.com/tindy2013/1fa08640a9088ac8652dbd40c5d2715b/raw/dlercloud_lige_platinum.ini
https://subconverter.oss-ap-southeast-1.aliyuncs.com/Rules/RemoteConfig/special/basic.ini
https://subconverter.oss-ap-southeast-1.aliyuncs.com/Rules/RemoteConfig/special/netease.ini
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"
if [ -z $markhttp ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请尝试使用【导入节点/链接】功能!\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit 1
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
fi
else
Https=""
#检测节点
if [ -z "$(cat $yamlnew | grep ', server:')" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m获取到了配置文件但格式似乎不对\033[0m"
echo -----------------------------------------------
sed -n '1,30p' $yamlnew
echo -----------------------------------------------
echo -e "\033[33m请检查如上配置文件信息:\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit 1
fi
#检测旧格式
if cat $yamlnew | grep 'Proxy Group:' >/dev/null;then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m已经停止对旧格式配置文件的支持\033[0m"
echo -e "请使用新格式或者使用【导入节点/链接】功能!"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit 1
fi
#检测不支持的加密协议
if cat $yamlnew | grep 'cipher: chacha20,' >/dev/null;then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m不支持chacha20加密请更换节点加密协议\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit 1
fi
#替换文件
[ -f $yaml ] && mv $yaml $yaml.bak
mv $yamlnew $yaml
echo 配置文件已生成正在启动clash使其生效
#重启clash服务
$0 stop
$0 start
sleep 1
if [ -z $(pidof clash) ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ -f $yaml.bak ];then
$clashdir/start.sh stop
mv $yaml.bak $yaml
$0 start
echo -e "\033[31mclash服务启动失败已还原配置文件并重启clash\033[0m"
sleep 1
[ -n $(pidof clash) ] && exit 0
fi
echo -e "\033[31mclash服务启动失败请查看报错信息\033[0m"
$0 stop
$clashdir/clash -t -d $clashdir
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit 1
fi
fi
}
modify_yaml(){
##########需要变更的配置###########
@@ -55,7 +178,7 @@ exper='experimental: {ignore-resolve-fail: true, interface-name: en0}'
#预删除需要添加的项目
i=$(grep -n "^proxies:" $clashdir/config.yaml | head -1 | cut -d ":" -f 1)
i=$(($i-1))
sed -i '1,'$i'd' $clashdir/config.yaml
sed -i "1,${i}d" $clashdir/config.yaml
#添加配置
sed -i "1i$mix" $clashdir/config.yaml
sed -i "1a$redir" $clashdir/config.yaml
@@ -77,11 +200,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,116 +217,134 @@ 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
ip6tables -t nat -N clashv6
for mac in $(cat $clashdir/mac); do
ip6tables -t nat -A clash -m mac --mac-source $mac -j RETURN
ip6tables -t nat -A clashv6 -m mac --mac-source $mac -j RETURN
done
ip6tables -t nat -A clash -p tcp $ports-j REDIRECT --to-ports 7892
ip6tables -t nat -A PREROUTING -p tcp -j clash
ip6tables -t nat -A clashv6 -p tcp $ports-j REDIRECT --to-ports 7892
ip6tables -t nat -A PREROUTING -p tcp -j clashv6
fi
}
stop_iptables(){
#重置iptables规则
iptables -t nat -D PREROUTING -p tcp -j clash > /dev/null 2>&1
iptables -t nat -D PREROUTING -p udp -j clash_dns > /dev/null 2>&1
iptables -t nat -D PREROUTING -p tcp -d 8.8.8.8 -j clash_dns > /dev/null 2>&1
iptables -t nat -D PREROUTING -p tcp -d 8.8.4.4 -j clash_dns > /dev/null 2>&1
iptables -t nat -F clash > /dev/null 2>&1
iptables -t nat -X clash > /dev/null 2>&1
iptables -t nat -F clash_dns > /dev/null 2>&1
iptables -t nat -X clash_dns > /dev/null 2>&1
iptables -D FORWARD -o utun -j ACCEPT > /dev/null 2>&1
#重置ipv6规则
ip6tables -t nat -D PREROUTING -p tcp -j clash > /dev/null 2>&1
ip6tables -t nat -D PREROUTING -p udp -j clash_dns > /dev/null 2>&1
ip6tables -t nat -F clash > /dev/null 2>&1
ip6tables -t nat -X clash > /dev/null 2>&1
ip6tables -t nat -F clash_dns > /dev/null 2>&1
ip6tables -t nat -X clash_dns > /dev/null 2>&1
ip6tables -t nat -D PREROUTING -p tcp -j clashv6 > /dev/null 2>&1
ip6tables -t nat -D PREROUTING -p udp -j clashv6_dns > /dev/null 2>&1
ip6tables -t nat -F clashv6 > /dev/null 2>&1
ip6tables -t nat -X clashv6 > /dev/null 2>&1
ip6tables -t nat -F clashv6_dns > /dev/null 2>&1
ip6tables -t nat -X clashv6_dns > /dev/null 2>&1
ip6tables -D FORWARD -o utun -j ACCEPT > /dev/null 2>&1
}
start_dns(){
#允许tun网卡接受流量
if [ "$redir_mod" = "Tun模式" -o "$redir_mod" = "混合模式" ];then
iptables -I FORWARD -o utun -j ACCEPT
ip6tables -I FORWARD -o utun -j ACCEPT > /dev/null 2>&1
[ "$ipv6_support" = "已开启" ] && ip6tables -I FORWARD -o utun -j ACCEPT > /dev/null 2>&1
fi
#设置dns转发
iptables -t nat -N clash_dns
for mac in $(cat $clashdir/mac); do
iptables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN
done
iptables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to 1053
iptables -t nat -A clash_dns -p tcp --dport 53 -j REDIRECT --to 1053
iptables -t nat -A PREROUTING -p udp -j clash_dns
#Google home 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
ip6tables -t nat -N clash_dns > /dev/null 2>&1
ip6tables -t nat -N clashv6_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
ip6tables -t nat -A clashv6_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
}
daemon_old(){
#守护进程状态
status=$(ps |grep -w 'clash'|grep -v grep|grep -v clash.sh)
[ -z $status ] && $clashdir/clash -d $clashdir && mark_time
ip6tables -t nat -A clashv6_dns -p udp --dport 53 -j REDIRECT --to 1053 > /dev/null 2>&1
ip6tables -t nat -A PREROUTING -p udp -j clashv6_dns > /dev/null 2>&1
}
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"
[ -z $cronpath ]&&echo "找不到定时任务文件,无法添加定时任务!"
}
start_old(){
daemon(){
checkcron
echo '*/1 * * * * test -z "$(pidof clash)" && /etc/init.d/clash restart #clash守护进程' >> $cronpath
chmod 600 $cronpath
}
afstart(){
#读取配置文件
getconfig
#使用内置规则强行覆盖config配置文件
[ "$modify_yaml" != "已开启" ] && modify_yaml
#创建clash后台进程
$clashdir/clash -d $clashdir> /dev/null &
#修改iptables规则使流量进入clash
stop_iptables
[ "$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(){
case "$1" in
afstart)
afstart
;;
start)
#读取配置文件
getconfig
#检测系统端口占用
for portx in 1053 7890 7892 9999 ;do
[ -n "$(netstat -ntul |grep :$portx)" ] && echo "检测到端口【$portx】被以下进程占用clash无法启动" && echo $(netstat -ntulp |grep :$portx) && exit 1
done
#使用内置规则强行覆盖config配置文件
[ "$modify_yaml" != "已开启" ] && modify_yaml
#使用不同方式启动clash服务
if [ "$start_old" = "已开启" ];then
$clashdir/clash -d $clashdir >/dev/null 2>&1 &
daemon
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
#结束进程
killall -9 clash &> /dev/null
sed -i /clash守护进程/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
}
start(){
;;
restart)
$0 stop
$0 start
;;
getyaml)
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
}
getyaml
;;
daemon)
daemon
;;
esac