#!/bin/bash set -euo pipefail #################### 基本变量 #################### Server_Dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" Service_Name="clash-for-linux" Service_User="root" Service_Group="root" Unit_Path="/etc/systemd/system/${Service_Name}.service" PID_FILE="$Server_Dir/temp/clash.pid" #################### 权限检查 #################### if [ "$(id -u)" -ne 0 ]; then echo -e "\033[31m[ERROR] 需要 root 权限来安装 systemd 单元\033[0m" exit 1 fi #################### 目录初始化 #################### install -d -m 0755 \ "$Server_Dir/conf" \ "$Server_Dir/logs" \ "$Server_Dir/temp" #################### 生成 systemd Unit #################### cat >"$Unit_Path"<