Migrate Mihomo and IPtables scripts from systemd to OpenRC and update service configurations
This commit is contained in:
@@ -33,8 +33,9 @@ MIHOMO_URL="https://github.com/vernesong/mihomo/releases/download/Prerelease-Alp
|
|||||||
# Remote Resources
|
# Remote Resources
|
||||||
REPO_BASE="https://gitea.shamanlanding.org/DaTekShaman/clash-rules/raw/branch/main"
|
REPO_BASE="https://gitea.shamanlanding.org/DaTekShaman/clash-rules/raw/branch/main"
|
||||||
URL_CONFIG_MIHOMO="${REPO_BASE}/config-clash/cadian/cadian.current.yaml"
|
URL_CONFIG_MIHOMO="${REPO_BASE}/config-clash/cadian/cadian.current.yaml"
|
||||||
# Init-скрипты генерируем локально, так как в репо лежат systemd юниты
|
|
||||||
URL_SCRIPT_IPTABLES="${REPO_BASE}/scripts/iptables-mihomo-setup.sh"
|
URL_SCRIPT_IPTABLES="${REPO_BASE}/scripts/iptables-mihomo-setup.sh"
|
||||||
|
URL_INIT_MIHOMO="${REPO_BASE}/init-scripts/openrc/mihomo"
|
||||||
|
URL_INIT_IPTABLES="${REPO_BASE}/init-scripts/openrc/mihomo-iptables"
|
||||||
|
|
||||||
# Paths
|
# Paths
|
||||||
BIN_DIR="/usr/local/bin"
|
BIN_DIR="/usr/local/bin"
|
||||||
@@ -139,7 +140,7 @@ chown -R mihomo:mihomo "$CONF_DIR" /var/log/mihomo
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
# 6. CONFIGURATION & OPENRC SERVICES
|
# 6. CONFIGURATION & OPENRC SERVICES
|
||||||
# ==========================================
|
# ==========================================
|
||||||
echo ">>> [6/8] Downloading Configs and Generating Services..."
|
echo ">>> [6/8] Downloading Configs and Services..."
|
||||||
|
|
||||||
# 6.1 Mihomo Config
|
# 6.1 Mihomo Config
|
||||||
if [ ! -f "${CONF_DIR}/config.yaml" ]; then
|
if [ ! -f "${CONF_DIR}/config.yaml" ]; then
|
||||||
@@ -165,45 +166,32 @@ else
|
|||||||
echo "✅ Configuration test passed."
|
echo "✅ Configuration test passed."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 6.4 Generate OpenRC Services (Вместо скачивания systemd units)
|
# 6.4 Download OpenRC Services
|
||||||
|
echo "Fetching OpenRC Init Scripts..."
|
||||||
|
|
||||||
# Service: Mihomo
|
# Service: Mihomo
|
||||||
cat <<EOF > /etc/init.d/mihomo
|
if [ ! -f "${INIT_DIR}/mihomo" ]; then
|
||||||
#!/sbin/openrc-run
|
echo "Downloading Service: $URL_INIT_MIHOMO"
|
||||||
name="mihomo"
|
wget -qO "${INIT_DIR}/mihomo" "$URL_INIT_MIHOMO"
|
||||||
description="Mihomo Daemon"
|
chmod +x "${INIT_DIR}/mihomo"
|
||||||
command="${BIN_DIR}/mihomo"
|
else
|
||||||
command_args="-d ${CONF_DIR}"
|
echo "Service 'mihomo' already exists."
|
||||||
command_background=true
|
fi
|
||||||
pidfile="/run/mihomo.pid"
|
|
||||||
# Запускаем от юзера mihomo
|
|
||||||
command_user="mihomo:mihomo"
|
|
||||||
|
|
||||||
depend() {
|
|
||||||
need net
|
|
||||||
use dns
|
|
||||||
after firewall
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
chmod +x /etc/init.d/mihomo
|
|
||||||
|
|
||||||
# Service: IPtables Helper
|
# Service: IPtables Helper
|
||||||
cat <<EOF > /etc/init.d/mihomo-iptables
|
if [ ! -f "${INIT_DIR}/mihomo-iptables" ]; then
|
||||||
#!/sbin/openrc-run
|
echo "Downloading Service: $URL_INIT_IPTABLES"
|
||||||
description="Mihomo IPtables Setup"
|
wget -qO "${INIT_DIR}/mihomo-iptables" "$URL_INIT_IPTABLES"
|
||||||
|
chmod +x "${INIT_DIR}/mihomo-iptables"
|
||||||
|
else
|
||||||
|
echo "Service 'mihomo-iptables' already exists."
|
||||||
|
fi
|
||||||
|
|
||||||
depend() {
|
# 6.5 Enable Services (rc-update)
|
||||||
need net
|
# Добавляем в автозагрузку (default runlevel)
|
||||||
before mihomo
|
echo "Enabling services..."
|
||||||
}
|
rc-update add mihomo-iptables default
|
||||||
|
rc-update add mihomo default
|
||||||
start() {
|
|
||||||
ebegin "Applying Mihomo IPtables rules"
|
|
||||||
${BIN_DIR}/iptables-mihomo-setup.sh
|
|
||||||
eend \$?
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
chmod +x /etc/init.d/mihomo-iptables
|
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# 7. USER & SSH SETUP
|
# 7. USER & SSH SETUP
|
||||||
|
|||||||
@@ -27,12 +27,10 @@ NETBIRD_SETUP_KEY="7369BE4D-C485-4339-A7CA-C245FD95E857"
|
|||||||
MIHOMO_URL="https://github.com/vernesong/mihomo/releases/download/Prerelease-Alpha/mihomo-linux-amd64-v3-alpha-smart-06249f8.gz"
|
MIHOMO_URL="https://github.com/vernesong/mihomo/releases/download/Prerelease-Alpha/mihomo-linux-amd64-v3-alpha-smart-06249f8.gz"
|
||||||
|
|
||||||
# Remote Resources (URLs)
|
# Remote Resources (URLs)
|
||||||
# Укажи здесь ссылки на raw-файлы из твоего Gitea/GitHub
|
|
||||||
REPO_BASE="https://gitea.shamanlanding.org/DaTekShaman/clash-rules/raw/branch/main"
|
REPO_BASE="https://gitea.shamanlanding.org/DaTekShaman/clash-rules/raw/branch/main"
|
||||||
|
|
||||||
URL_CONFIG_MIHOMO="${REPO_BASE}/config-clash/cadian/cadian.current.yaml"
|
URL_CONFIG_MIHOMO="${REPO_BASE}/config-clash/cadian/cadian.current.yaml"
|
||||||
URL_UNIT_MIHOMO="${REPO_BASE}/systemd-units/mihomo.service"
|
URL_UNIT_MIHOMO="${REPO_BASE}/init-scripts/systemd/mihomo.service"
|
||||||
URL_UNIT_IPTABLES="${REPO_BASE}/systemd-units/mihomo-iptables.service"
|
URL_UNIT_IPTABLES="${REPO_BASE}/init-scripts/systemd/mihomo-iptables.service"
|
||||||
URL_SCRIPT_IPTABLES="${REPO_BASE}/scripts/iptables-mihomo-setup.sh"
|
URL_SCRIPT_IPTABLES="${REPO_BASE}/scripts/iptables-mihomo-setup.sh"
|
||||||
|
|
||||||
# Paths
|
# Paths
|
||||||
|
|||||||
Reference in New Issue
Block a user