From 472b6db3f13d7eacb34e4aaa931105ff54c6497d Mon Sep 17 00:00:00 2001 From: chunzhimoe Date: Fri, 10 Apr 2026 17:26:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Alpine=20=E4=B8=8B=E4=BC=98=E5=85=88?= =?UTF-8?q?=E8=B5=B0=20OpenRC=EF=BC=8C=E9=81=BF=E5=85=8D=20systemctl=20stu?= =?UTF-8?q?b=20=E8=AF=AF=E5=88=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- port.sh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/port.sh b/port.sh index f75eb25..93e9fa2 100644 --- a/port.sh +++ b/port.sh @@ -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}"