2023-02-13 12:33:16 +08:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# 自定义action函数,实现通用action功能
|
|
|
|
|
success() {
|
|
|
|
|
echo -en "\\033[60G[\\033[1;32m OK \\033[0;39m]\r"
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
failure() {
|
|
|
|
|
local rc=$?
|
|
|
|
|
echo -en "\\033[60G[\\033[1;31mFAILED\\033[0;39m]\r"
|
|
|
|
|
[ -x /bin/plymouth ] && /bin/plymouth --details
|
|
|
|
|
return $rc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
action() {
|
|
|
|
|
local STRING rc
|
|
|
|
|
|
|
|
|
|
STRING=$1
|
|
|
|
|
echo -n "$STRING "
|
|
|
|
|
shift
|
|
|
|
|
"$@" && success $"$STRING" || failure $"$STRING"
|
|
|
|
|
rc=$?
|
|
|
|
|
echo
|
|
|
|
|
return $rc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 函数,判断命令是否正常执行
|
|
|
|
|
if_success() {
|
2023-02-18 03:02:04 +08:00
|
|
|
|
local ReturnStatus=$3
|
|
|
|
|
if [ $ReturnStatus -eq 0 ]; then
|
|
|
|
|
action "$1" /bin/true
|
|
|
|
|
else
|
|
|
|
|
action "$2" /bin/false
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2023-02-13 12:33:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 定义路劲变量
|
|
|
|
|
Server_Dir=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
|
|
|
|
|
Conf_Dir="$Server_Dir/conf"
|
|
|
|
|
Log_Dir="$Server_Dir/logs"
|
|
|
|
|
|
|
|
|
|
## 关闭clash服务
|
|
|
|
|
Text1="服务关闭成功!"
|
|
|
|
|
Text2="服务关闭失败!"
|
|
|
|
|
# 查询并关闭程序进程
|
|
|
|
|
PID_NUM=`ps -ef | grep [c]lash-linux-a | wc -l`
|
|
|
|
|
PID=`ps -ef | grep [c]lash-linux-a | awk '{print $2}'`
|
|
|
|
|
if [ $PID_NUM -ne 0 ]; then
|
|
|
|
|
kill -9 $PID
|
2023-02-18 03:02:04 +08:00
|
|
|
|
ReturnStatus=$?
|
2023-02-13 12:33:16 +08:00
|
|
|
|
# ps -ef | grep [c]lash-linux-a | awk '{print $2}' | xargs kill -9
|
|
|
|
|
fi
|
2023-02-18 03:02:04 +08:00
|
|
|
|
if_success $Text1 $Text2 $ReturnStatus
|
2023-02-13 12:33:16 +08:00
|
|
|
|
|
|
|
|
|
sleep 3
|
|
|
|
|
|
2023-02-18 03:02:04 +08:00
|
|
|
|
## 获取CPU架构
|
|
|
|
|
if /bin/arch &>/dev/null; then
|
|
|
|
|
CpuArch=`/bin/arch`
|
|
|
|
|
elif /usr/bin/arch &>/dev/null; then
|
|
|
|
|
CpuArch=`/usr/bin/arch`
|
|
|
|
|
elif /bin/uname -m &>/dev/null; then
|
|
|
|
|
CpuArch=`/bin/uname -m`
|
|
|
|
|
else
|
|
|
|
|
echo -e "\033[31m\n[ERROR] Failed to obtain CPU architecture!\033[0m"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2023-02-13 12:33:16 +08:00
|
|
|
|
## 重启启动clash服务
|
2023-02-18 03:02:04 +08:00
|
|
|
|
Text5="服务启动成功!"
|
|
|
|
|
Text6="服务启动失败!"
|
|
|
|
|
if [[ $CpuArch =~ "x86_64" ]]; then
|
|
|
|
|
nohup $Server_Dir/bin/clash-linux-amd64 -d $Conf_Dir &> $Log_Dir/clash.log &
|
|
|
|
|
ReturnStatus=$?
|
|
|
|
|
if_success $Text5 $Text6 $ReturnStatus
|
2023-03-28 12:57:32 +08:00
|
|
|
|
elif [[ $CpuArch =~ "aarch64" || $CpuArch =~ "arm64" ]]; then
|
2023-03-28 00:21:24 +08:00
|
|
|
|
nohup $Server_Dir/bin/clash-linux-arm64 -d $Conf_Dir &> $Log_Dir/clash.log &
|
|
|
|
|
ReturnStatus=$?
|
|
|
|
|
if_success $Text5 $Text6 $ReturnStatus
|
|
|
|
|
elif [[ $CpuArch =~ "armv7" ]]; then
|
2023-02-13 12:33:16 +08:00
|
|
|
|
nohup $Server_Dir/bin/clash-linux-armv7 -d $Conf_Dir &> $Log_Dir/clash.log &
|
2023-02-18 03:02:04 +08:00
|
|
|
|
ReturnStatus=$?
|
|
|
|
|
if_success $Text5 $Text6 $ReturnStatus
|
2023-02-13 12:33:16 +08:00
|
|
|
|
else
|
2023-02-18 03:02:04 +08:00
|
|
|
|
echo -e "\033[31m\n[ERROR] Unsupported CPU Architecture!\033[0m"
|
2023-02-13 12:33:16 +08:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|