make get_pkgmgr public

This commit is contained in:
fatalerrors
2026-05-06 18:27:19 +02:00
parent cd0bcfd214
commit b29fa3b30c

View File

@@ -40,7 +40,7 @@
# checking available binaries in a fixed priority order.
# Echoes one of: apt dnf yum zypper pacman apk portage xbps nix
# Returns 1 if no known package manager could be identified.
_get_pkgmgr()
get_pkgmgr()
{
local distro_id="" distro_like=""
if [[ -r /etc/os-release ]]; then
@@ -56,30 +56,48 @@ _get_pkgmgr()
for id in $distro_id $distro_like; do
case "${id,,}" in
debian|ubuntu|linuxmint|raspbian|pop|kali|elementary|zorin|neon|parrot)
echo "apt"; return 0 ;;
echo "apt"
return 0
;;
fedora)
echo "dnf"; return 0 ;;
echo "dnf"
return 0
;;
rhel|centos|rocky|almalinux|ol|scientific|amzn)
command -v dnf >/dev/null 2>&1 && { echo "dnf"; return 0; }
echo "yum"; return 0 ;;
echo "yum"
return 0
;;
opensuse*|sles|sled)
echo "zypper"; return 0 ;;
echo "zypper"
return 0
;;
arch|manjaro|endeavouros|garuda|artix|cachyos)
echo "pacman"; return 0 ;;
echo "pacman"
return 0
;;
alpine)
echo "apk"; return 0 ;;
echo "apk"
return 0
;;
gentoo)
echo "portage"; return 0 ;;
echo "portage"
return 0
;;
void)
echo "xbps"; return 0 ;;
echo "xbps"
return 0
;;
nixos)
echo "nix"; return 0 ;;
echo "nix"
return 0
;;
esac
done
# Fallback: check for binaries in priority order.
local bin
for bin in apt-get dnf yum zypper pacman apk emerge xbps-install nix-env; do
for bin in apt apt-get dnf yum zypper pacman apk emerge xbps-install nix-env; do
command -v "$bin" >/dev/null 2>&1 && {
case "$bin" in
apt-get) echo "apt" ;;
@@ -94,7 +112,7 @@ _get_pkgmgr()
return 1
}
export -f _get_pkgmgr
export -f get_pkgmgr
# ------------------------------------------------------------------------------
@@ -150,7 +168,7 @@ pkgs()
(( ignore_case )) && grep_opt="-i"
local pkgmgr
pkgmgr=$(_get_pkgmgr) || {
pkgmgr=$(get_pkgmgr) || {
disp E "No usable package manager could be detected on this system."
return 2
}