feat: detects existing clash instances before it starts one

This commit is contained in:
NekoRectifier 2023-12-12 15:19:39 +08:00
parent 725d109594
commit 5530eaf4e4
17 changed files with 9723 additions and 58 deletions

0
bin/clash-linux-amd64 Normal file → Executable file
View File

0
bin/clash-linux-arm64 Normal file → Executable file
View File

0
bin/clash-linux-armv7 Normal file → Executable file
View File

BIN
conf/cache.db Normal file

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

4
restart.sh Normal file → Executable file
View File

@ -36,7 +36,7 @@ if_success() {
fi fi
} }
# 定义路变量 # 定义路变量
Server_Dir=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) Server_Dir=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
Conf_Dir="$Server_Dir/conf" Conf_Dir="$Server_Dir/conf"
Log_Dir="$Server_Dir/logs" Log_Dir="$Server_Dir/logs"
@ -45,7 +45,7 @@ Log_Dir="$Server_Dir/logs"
Text1="服务关闭成功!" Text1="服务关闭成功!"
Text2="服务关闭失败!" Text2="服务关闭失败!"
# 查询并关闭程序进程 # 查询并关闭程序进程
PID_NUM=`ps -ef | grep [c]lash-linux-a | wc -l` PID_NUM=`PID_NUM=`ps -ef | grep [c]lash-linux-a | wc -l``
PID=`ps -ef | grep [c]lash-linux-a | awk '{print $2}'` PID=`ps -ef | grep [c]lash-linux-a | awk '{print $2}'`
if [ $PID_NUM -ne 0 ]; then if [ $PID_NUM -ne 0 ]; then
kill -9 $PID kill -9 $PID

0
scripts/clash_profile_conversion.sh Normal file → Executable file
View File

0
scripts/get_cpu_arch.sh Normal file → Executable file
View File

32
setup.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
echo -e "Run this with root permission!\n"
# 添加环境变量(root权限)
cat>/etc/profile.d/clash.fish<<EOF
# 开启系统代理
function proxy_on
export http_proxy=http://127.0.0.1:7890
#export https_proxy=http://127.0.0.1:7890
export no_proxy=127.0.0.1,localhost
export HTTP_PROXY=http://127.0.0.1:7890
#export HTTPS_PROXY=http://127.0.0.1:7890
export NO_PROXY=127.0.0.1,localhost
echo -e "\033[32m[√] 已开启代理\033[0m"
end
# 关闭系统代理
function proxy_off
set -e http_proxy
set -e https_proxy
set -e no_proxy
set -e HTTP_PROXY
set -e HTTPS_PROXY
set -e NO_PROXY
echo -e "\033[31m[×] 已关闭代理\033[0m"
end
EOF
echo -e "请执行以下命令加载环境变量: source /etc/profile.d/clash.fish\n"
echo -e "请执行以下命令开启系统代理: proxy_on\n"
echo -e "若要临时关闭系统代理,请执行: proxy_off\n"

0
shutdown.sh Normal file → Executable file
View File

38
start.sh Normal file → Executable file
View File

@ -155,6 +155,16 @@ Dashboard_Dir="${Work_Dir}/dashboard/public"
sed -ri "s@^# external-ui:.*@external-ui: ${Dashboard_Dir}@g" $Conf_Dir/config.yaml sed -ri "s@^# external-ui:.*@external-ui: ${Dashboard_Dir}@g" $Conf_Dir/config.yaml
sed -r -i '/^secret: /s@(secret: ).*@\1'${Secret}'@g' $Conf_Dir/config.yaml sed -r -i '/^secret: /s@(secret: ).*@\1'${Secret}'@g' $Conf_Dir/config.yaml
PID=`ps -ef | grep [c]lash-linux-a | awk '{print $2}'`
if [ -z "$PID" ]; then
echo -e "Clash isn't running"
else
echo "Running clash detected."
echo "Killing clash now. PID:"$PID
sudo kill -9 $PID
fi
## 启动Clash服务 ## 启动Clash服务
echo -e '\n正在启动Clash服务...' echo -e '\n正在启动Clash服务...'
@ -183,31 +193,3 @@ echo -e "Clash Dashboard 访问地址: http://<ip>:9090/ui"
echo -e "Secret: ${Secret}" echo -e "Secret: ${Secret}"
echo '' echo ''
# 添加环境变量(root权限)
cat>/etc/profile.d/clash.sh<<EOF
# 开启系统代理
function proxy_on() {
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
export no_proxy=127.0.0.1,localhost
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
export NO_PROXY=127.0.0.1,localhost
echo -e "\033[32m[√] 已开启代理\033[0m"
}
# 关闭系统代理
function proxy_off(){
unset http_proxy
unset https_proxy
unset no_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
unset NO_PROXY
echo -e "\033[31m[×] 已关闭代理\033[0m"
}
EOF
echo -e "请执行以下命令加载环境变量: source /etc/profile.d/clash.sh\n"
echo -e "请执行以下命令开启系统代理: proxy_on\n"
echo -e "若要临时关闭系统代理,请执行: proxy_off\n"

View File

View File

View File

View File

@ -1,28 +0,0 @@
# HTTP 代理端口
port: 7890
# SOCKS5 代理端口
socks-port: 7891
# Linux 和 macOS 的 redir 代理端口
redir-port: 7892
# 允许局域网的连接
allow-lan: true
# 规则模式Rule规则 / Global全局代理/ Direct全局直连
mode: rule
# 设置日志输出级别 (默认级别silent即不输出任何内容以避免因日志内容过大而导致程序内存溢出
# 5 个级别silent / info / warning / error / debug。级别越高日志输出量越大越倾向于调试若需要请自行开启。
log-level: silent
# Clash 的 RESTful API
external-controller: '0.0.0.0:9090'
# RESTful API 的口令
secret: 'b&ZlKTte5OnEt2Sn'
# 您可以将静态网页资源(如 clash-dashboard放置在一个目录中clash 将会服务于 `RESTful API/ui`
# 参数应填写配置目录的相对路径或绝对路径。
# external-ui: /code/clash-dashboard

0
tools/subconverter/subconverter Normal file → Executable file
View File