From 3ac1a8aef590b597139c5eb078ecabb94c8b4199 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Tue, 20 Aug 2024 00:27:51 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E9=80=9A=E8=BF=87=E7=B3=BB=E7=BB=9F=20?= =?UTF-8?q?id=20=E6=9F=A5=E6=89=BE=E5=8C=85=E7=AE=A1=E7=90=86=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reinstall.sh | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/reinstall.sh b/reinstall.sh index 662237f..926dc37 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -1355,12 +1355,37 @@ install_pkg() { is_in_windows && return find_pkg_mgr() { - if [ -z "$pkg_mgr" ]; then - for mgr in dnf yum apt pacman zypper emerge apk opkg nix-env; do - is_have_cmd $mgr && pkg_mgr=$mgr && return + [ -n "$pkg_mgr" ] && return + + # 查找方法1: 通过 ID_LIKE / ID + # 因为可能装了多种包管理器 + if [ -f /etc/os-release ]; then + # shellcheck source=/dev/null + . /etc/os-release + set -- $ID_LIKE $ID + # https://github.com/chef/os_release + while [ $# -gt 0 ]; do + case "$1" in + fedora | centos | rhel) is_have_cmd dnf && pkg_mgr=dnf || pkg_mgr=yum ;; + debian | ubuntu) pkg_mgr=apt ;; + opensuse | suse) pkg_mgr=zypper ;; + alpine) pkg_mgr=apk ;; + arch) pkg_mgr=pacman ;; + gentoo) pkg_mgr=emerge ;; + openwrt) pkg_mgr=opkg ;; + nixos) pkg_mgr=nix-env ;; + esac + [ -n "$pkg_mgr" ] && return + shift done - return 1 fi + + # 查找方法 2 + for mgr in dnf yum apt pacman zypper emerge apk opkg nix-env; do + is_have_cmd $mgr && pkg_mgr=$mgr && return + done + + return 1 } cmd_to_pkg() {