commit e40250f242ef9f3cbe5fe7fc2c23d2e4cbceb46e Author: libm Date: Tue Mar 12 03:53:53 2024 +0800 init diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..d44d53a --- /dev/null +++ b/install.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +n1=$(wc -l < ./resource/config.yaml) +if [ $n1 -lt 0 ]; then + read -p '订阅链接:' url + wget --no-check-certificate --timeout=3 -qo ./resource/config.yaml $url + n2=$(wc -l < ./resource/config.yaml) + if [ $n2 -eq 0 ]; then + echo "链接无效,自行粘贴配置到./resource/config.yaml" + fi +fi + +# gzip解压后不保留原文件 +cp ./resource/clash-linux-amd64-v3-2023.08.17.gz ./clash_copy +# 解压 +gzip -d ./resource/clash-linux-amd64-v3-2023.08.17.gz +# 可执行 +mv ./resource/clash-linux-amd64-v3-2023.08.17 /usr/local/bin/clash && chmod +x /usr/local/bin/clash +mv ./clash_copy ./resource/clash-linux-amd64-v3-2023.08.17.gz + +# clash配置目录 +mkdir -p /etc/clash +tar -xf ./resource/yacd.tar.xz -C /etc/clash/ +/bin/cp -f ./resource/config.yaml /etc/clash/ +/bin/cp -f ./resource/Country.mmdb /etc/clash/ +/bin/cp -rf ./service/ /etc/clash/ + +# 创建服务配置文件 +cat << EOF > /etc/systemd/system/clash.service +[Unit] +Description=Clash 守护进程, Go 语言实现的基于规则的代理. +After=network-online.target + +[Service] +Type=simple +Restart=always +ExecStart=/etc/clash/service/ExecStart.sh +ExecStopPost=/etc/clash/service/ExecStopPost.sh + +[Install] +WantedBy=multi-user.target +EOF + +# 重新加载 systemd +systemctl daemon-reload + +# 开机自启clash +systemctl enable clash +if [ $? -eq 0 ]; then + echo "clash 设置自启成功!" +else + echo "clash 设置自启失败!" +fi + +# 启动clash服务 +systemctl start clash +# 检查服务启动状态 +if [ $? -eq 0 ]; then + echo "clash 启动!" +else + echo "clash 启动失败!" +fi + +# ui面板 +chmod +x ./ui.sh +bash ./ui.sh \ No newline at end of file diff --git a/resource/Country.mmdb b/resource/Country.mmdb new file mode 100644 index 0000000..05870f1 Binary files /dev/null and b/resource/Country.mmdb differ diff --git a/resource/clash-linux-amd64-v3-2023.08.17.gz b/resource/clash-linux-amd64-v3-2023.08.17.gz new file mode 100644 index 0000000..89a8869 Binary files /dev/null and b/resource/clash-linux-amd64-v3-2023.08.17.gz differ diff --git a/resource/yacd.tar.xz b/resource/yacd.tar.xz new file mode 100644 index 0000000..fb7ac09 Binary files /dev/null and b/resource/yacd.tar.xz differ diff --git a/service/ExecStart.sh b/service/ExecStart.sh new file mode 100644 index 0000000..e2cde8b --- /dev/null +++ b/service/ExecStart.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# 环境变量 设置代理 +cat << EOF > /etc/profile.d/clash.sh +export http_proxy=http://127.0.0.1:7890 +export https_proxy=http://127.0.0.1:7890 +EOF +source /etc/profile.d/clash.sh + +# clash 启动! +/usr/local/bin/clash -d /etc/clash -ext-ui public \ No newline at end of file diff --git a/service/ExecStopPost.sh b/service/ExecStopPost.sh new file mode 100644 index 0000000..c2bfd89 --- /dev/null +++ b/service/ExecStopPost.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "" > /etc/profile.d/clash.sh; +source /etc/profile diff --git a/ui.sh b/ui.sh new file mode 100644 index 0000000..4e26ab7 --- /dev/null +++ b/ui.sh @@ -0,0 +1,4 @@ +ip=$(curl -s ifconfig.cc | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") + +# 输出变量中的IP地址 +echo "clash面板地址:http://$ip:9090/ui" diff --git a/uninstall.sh b/uninstall.sh new file mode 100644 index 0000000..bf27a13 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,8 @@ +systemctl stop clash +rm -rf /etc/clash +rm -f /etc/profile.d/clash.sh +source /etc/profile +rm -f /etc/systemd/system/clash.service +rm -f /usr/local/bin/clash +systemctl daemon-reload +echo clash已卸载,相关配置已清除! \ No newline at end of file