From 58030f065154996b26c940a5198c674667d01be2 Mon Sep 17 00:00:00 2001 From: DaTekShaman Date: Sun, 15 Feb 2026 14:01:05 +0300 Subject: [PATCH] Migrate Mihomo and IPtables scripts from systemd to OpenRC and update service configurations --- {open-rc => init-scripts/openrc}/mihomo | 0 .../openrc}/mihomo-iptables | 0 .../systemd}/mihomo-iptables.service | 0 .../systemd}/mihomo.service | 0 scripts/config-warpgate-alpine.sh | 60 ++++++++----------- scripts/config-warpgate-debian.sh | 6 +- 6 files changed, 26 insertions(+), 40 deletions(-) rename {open-rc => init-scripts/openrc}/mihomo (100%) rename {open-rc => init-scripts/openrc}/mihomo-iptables (100%) rename {systemd-units => init-scripts/systemd}/mihomo-iptables.service (100%) rename {systemd-units => init-scripts/systemd}/mihomo.service (100%) diff --git a/open-rc/mihomo b/init-scripts/openrc/mihomo similarity index 100% rename from open-rc/mihomo rename to init-scripts/openrc/mihomo diff --git a/open-rc/mihomo-iptables b/init-scripts/openrc/mihomo-iptables similarity index 100% rename from open-rc/mihomo-iptables rename to init-scripts/openrc/mihomo-iptables diff --git a/systemd-units/mihomo-iptables.service b/init-scripts/systemd/mihomo-iptables.service similarity index 100% rename from systemd-units/mihomo-iptables.service rename to init-scripts/systemd/mihomo-iptables.service diff --git a/systemd-units/mihomo.service b/init-scripts/systemd/mihomo.service similarity index 100% rename from systemd-units/mihomo.service rename to init-scripts/systemd/mihomo.service diff --git a/scripts/config-warpgate-alpine.sh b/scripts/config-warpgate-alpine.sh index 6f8f7a1..f16338c 100644 --- a/scripts/config-warpgate-alpine.sh +++ b/scripts/config-warpgate-alpine.sh @@ -33,8 +33,9 @@ MIHOMO_URL="https://github.com/vernesong/mihomo/releases/download/Prerelease-Alp # Remote Resources REPO_BASE="https://gitea.shamanlanding.org/DaTekShaman/clash-rules/raw/branch/main" URL_CONFIG_MIHOMO="${REPO_BASE}/config-clash/cadian/cadian.current.yaml" -# Init-скрипты генерируем локально, так как в репо лежат systemd юниты 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 BIN_DIR="/usr/local/bin" @@ -139,7 +140,7 @@ chown -R mihomo:mihomo "$CONF_DIR" /var/log/mihomo # ========================================== # 6. CONFIGURATION & OPENRC SERVICES # ========================================== -echo ">>> [6/8] Downloading Configs and Generating Services..." +echo ">>> [6/8] Downloading Configs and Services..." # 6.1 Mihomo Config if [ ! -f "${CONF_DIR}/config.yaml" ]; then @@ -165,45 +166,32 @@ else echo "✅ Configuration test passed." fi -# 6.4 Generate OpenRC Services (Вместо скачивания systemd units) +# 6.4 Download OpenRC Services +echo "Fetching OpenRC Init Scripts..." # Service: Mihomo -cat < /etc/init.d/mihomo -#!/sbin/openrc-run -name="mihomo" -description="Mihomo Daemon" -command="${BIN_DIR}/mihomo" -command_args="-d ${CONF_DIR}" -command_background=true -pidfile="/run/mihomo.pid" -# Запускаем от юзера mihomo -command_user="mihomo:mihomo" - -depend() { - need net - use dns - after firewall -} -EOF -chmod +x /etc/init.d/mihomo +if [ ! -f "${INIT_DIR}/mihomo" ]; then + echo "Downloading Service: $URL_INIT_MIHOMO" + wget -qO "${INIT_DIR}/mihomo" "$URL_INIT_MIHOMO" + chmod +x "${INIT_DIR}/mihomo" +else + echo "Service 'mihomo' already exists." +fi # Service: IPtables Helper -cat < /etc/init.d/mihomo-iptables -#!/sbin/openrc-run -description="Mihomo IPtables Setup" +if [ ! -f "${INIT_DIR}/mihomo-iptables" ]; then + echo "Downloading Service: $URL_INIT_IPTABLES" + wget -qO "${INIT_DIR}/mihomo-iptables" "$URL_INIT_IPTABLES" + chmod +x "${INIT_DIR}/mihomo-iptables" +else + echo "Service 'mihomo-iptables' already exists." +fi -depend() { - need net - before mihomo -} - -start() { - ebegin "Applying Mihomo IPtables rules" - ${BIN_DIR}/iptables-mihomo-setup.sh - eend \$? -} -EOF -chmod +x /etc/init.d/mihomo-iptables +# 6.5 Enable Services (rc-update) +# Добавляем в автозагрузку (default runlevel) +echo "Enabling services..." +rc-update add mihomo-iptables default +rc-update add mihomo default # ========================================== # 7. USER & SSH SETUP diff --git a/scripts/config-warpgate-debian.sh b/scripts/config-warpgate-debian.sh index 37d2077..d461446 100644 --- a/scripts/config-warpgate-debian.sh +++ b/scripts/config-warpgate-debian.sh @@ -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" # Remote Resources (URLs) -# Укажи здесь ссылки на raw-файлы из твоего Gitea/GitHub REPO_BASE="https://gitea.shamanlanding.org/DaTekShaman/clash-rules/raw/branch/main" - URL_CONFIG_MIHOMO="${REPO_BASE}/config-clash/cadian/cadian.current.yaml" -URL_UNIT_MIHOMO="${REPO_BASE}/systemd-units/mihomo.service" -URL_UNIT_IPTABLES="${REPO_BASE}/systemd-units/mihomo-iptables.service" +URL_UNIT_MIHOMO="${REPO_BASE}/init-scripts/systemd/mihomo.service" +URL_UNIT_IPTABLES="${REPO_BASE}/init-scripts/systemd/mihomo-iptables.service" URL_SCRIPT_IPTABLES="${REPO_BASE}/scripts/iptables-mihomo-setup.sh" # Paths