Skip to content

Commit b5e8fdf

Browse files
alexbeyuhan6665
authored andcommitted
Generalize the script to all OpenRC distributions
1 parent b7410c4 commit b5e8fdf

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ English | [简体中文](README_zh-Hans.md) | [繁體中文](README_zh-Hant.md)
44

55
Bash script for installing Xray in operating systems such as CentOS / Debian / OpenSUSE that support systemd.
66

7-
**For Alpine Linux users**, please refer to **[Alpine Linux Specific Instructions](alpinelinux/README.md)** for installation scripts and guides tailored for Alpine Linux.
7+
**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.
88

99
---
1010

alpinelinux/install-release.sh

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,34 @@
33

44
set -euo pipefail
55

6-
check_alpine() {
7-
if [ -f /etc/alpine-release ]; then
6+
pkg_manager() {
7+
local OP="$1" PM=apk
8+
shift
9+
if [ -f /etc/gentoo-release ]; then
10+
PM=emerge
11+
case "$OP" in
12+
add)
13+
OP='-v'
14+
;;
15+
del)
16+
OP='-C'
17+
;;
18+
esac
19+
fi
20+
if [ -z "$@" ]; then
21+
echo "$PM $OP"
22+
else
23+
$PM $OP $@
24+
fi
25+
}
26+
27+
28+
check_distr() {
29+
if [ -z "$(command -v rc-service)" ]; then
30+
echo "No OpenRC init-system detected"
31+
return 1
32+
fi
33+
if [ -f /etc/alpine-release -o -f /etc/gentoo-release ]; then
834
return 0
935
else
1036
return 1
@@ -91,7 +117,7 @@ install_dependencies() {
91117
fi
92118
if [ "$(command -v apk)" ]; then
93119
echo "Installing required dependencies..."
94-
apk add curl unzip
120+
pkg_manager add curl unzip #to generalize installation procedure
95121
else
96122
echo "error: The script does not support the package manager in this operating system."
97123
exit 1
@@ -202,7 +228,7 @@ information() {
202228
fi
203229
rm -r "$TMP_DIRECTORY"
204230
echo "removed: $TMP_DIRECTORY"
205-
echo "You may need to execute a command to remove dependent software: apk del curl unzip"
231+
echo "You may need to execute a command to remove dependent software: $(pkg_manager del) curl unzip"
206232
if [ "$XRAY_RUNNING" -eq '1' ]; then
207233
rc-service xray start
208234
else
@@ -212,7 +238,7 @@ information() {
212238
}
213239

214240
main() {
215-
check_alpine || return 1
241+
check_distr || return 1
216242
check_if_running_as_root || return 1
217243
identify_architecture || return 1
218244
install_dependencies

0 commit comments

Comments
 (0)