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

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

22
port.sh
View File

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