From b5e8fdf24fc81003b444fa47492940df87febd0d Mon Sep 17 00:00:00 2001 From: alexbe <941255+alexbe@users.noreply.github.com> Date: Mon, 17 Nov 2025 23:30:10 +0300 Subject: [PATCH] Generalize the script to all OpenRC distributions --- README.md | 2 +- alpinelinux/install-release.sh | 36 +++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 78ce677..9f0e69b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ English | [简体中文](README_zh-Hans.md) | [繁體中文](README_zh-Hant.md) Bash script for installing Xray in operating systems such as CentOS / Debian / OpenSUSE that support systemd. -**For Alpine Linux users**, please refer to **[Alpine Linux Specific Instructions](alpinelinux/README.md)** for installation scripts and guides tailored for Alpine Linux. +**For Alpine or Gentoo Linux users**, please refer to **[OpenRC Specific Instructions](alpinelinux/README.md)** for installation scripts and guides tailored for Alpine/Gentoo Linux featured by OpenRC init-system. --- diff --git a/alpinelinux/install-release.sh b/alpinelinux/install-release.sh index bef0a03..b61d5b6 100644 --- a/alpinelinux/install-release.sh +++ b/alpinelinux/install-release.sh @@ -3,8 +3,34 @@ set -euo pipefail -check_alpine() { - if [ -f /etc/alpine-release ]; then +pkg_manager() { + local OP="$1" PM=apk + shift + if [ -f /etc/gentoo-release ]; then + PM=emerge + case "$OP" in + add) + OP='-v' + ;; + del) + OP='-C' + ;; + esac + fi + if [ -z "$@" ]; then + echo "$PM $OP" + else + $PM $OP $@ + fi +} + + +check_distr() { + if [ -z "$(command -v rc-service)" ]; then + echo "No OpenRC init-system detected" + return 1 + fi + if [ -f /etc/alpine-release -o -f /etc/gentoo-release ]; then return 0 else return 1 @@ -91,7 +117,7 @@ install_dependencies() { fi if [ "$(command -v apk)" ]; then echo "Installing required dependencies..." - apk add curl unzip + pkg_manager add curl unzip #to generalize installation procedure else echo "error: The script does not support the package manager in this operating system." exit 1 @@ -202,7 +228,7 @@ information() { fi rm -r "$TMP_DIRECTORY" echo "removed: $TMP_DIRECTORY" - echo "You may need to execute a command to remove dependent software: apk del curl unzip" + echo "You may need to execute a command to remove dependent software: $(pkg_manager del) curl unzip" if [ "$XRAY_RUNNING" -eq '1' ]; then rc-service xray start else @@ -212,7 +238,7 @@ information() { } main() { - check_alpine || return 1 + check_distr || return 1 check_if_running_as_root || return 1 identify_architecture || return 1 install_dependencies