fix: Alpine 下优先走 OpenRC,避免 systemctl stub 误判

This commit is contained in:
chunzhimoe 2026-04-10 17:26:42 +08:00
parent 7eaff9fd0a
commit 472b6db3f1

26
port.sh
View File

@ -44,25 +44,29 @@ detect_system() {
OS="unknown"
fi
if command -v systemctl > /dev/null 2>&1 && systemctl --version > /dev/null 2>&1; then
INIT_SYS="systemd"
elif command -v rc-service > /dev/null 2>&1; then
INIT_SYS="openrc"
else
# Alpine 下尝试自动安装 OpenRC
if [ "$OS" = "alpine" ]; then
# Alpine 优先走 OpenRC不依赖 systemctl 检测
if [ "$OS" = "alpine" ]; then
if command -v rc-service > /dev/null 2>&1; then
INIT_SYS="openrc"
else
echo -e "${YELLOW}OpenRC 未安装,正在安装...${NC}"
apk add --no-cache openrc
mkdir -p /run/openrc
touch /run/openrc/softlevel
if command -v rc-service > /dev/null 2>&1; then
INIT_SYS="openrc"
else
echo -e "${RED}错误: OpenRC 安装失败${NC}"
exit 1
fi
fi
if [ -z "$INIT_SYS" ]; then
echo -e "${RED}错误: 不支持的初始化系统(需要 systemd 或 OpenRC${NC}"
exit 1
fi
elif command -v systemctl > /dev/null 2>&1 && [ -d /etc/systemd/system ]; then
INIT_SYS="systemd"
elif command -v rc-service > /dev/null 2>&1; then
INIT_SYS="openrc"
else
echo -e "${RED}错误: 不支持的初始化系统(需要 systemd 或 OpenRC${NC}"
exit 1
fi
echo -e "${BLUE}系统: ${OS} | 初始化系统: ${INIT_SYS}${NC}"