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}"