moved helpers separately

This commit is contained in:
2026-10-13 16:21:24 +02:00
parent ba1e07744e
commit 9911f6d01d
33 changed files with 1489 additions and 1089 deletions
+3 -51
View File
@@ -36,6 +36,9 @@
load_conf "packages"
# Common helpers, then the ones private to this module (helpers/packages.sh)
declare -F _profile_load_helpers >/dev/null || . "$(dirname -- "${BASH_SOURCE[0]}")/../helpers/common.sh"
_profile_load_helpers "${BASH_SOURCE[0]}"
# ------------------------------------------------------------------------------
# Detect the active package manager of the current distribution.
@@ -116,9 +119,6 @@ get_pkgmgr()
return 1
}
export -f get_pkgmgr
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Look for a package within installed one
# Usage: pkgs <string>
@@ -197,9 +197,6 @@ pkgs()
"${list_cmd[@]}" | grep ${grep_opt:+"$grep_opt"} -e "$pkg"
}
export -f pkgs
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Find which installed package a file belongs to.
# Usage: pkgf <file>
@@ -286,47 +283,6 @@ pkgf()
esac
}
export -f pkgf
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Internal helper: run a package manager command, with root privileges when
# needed (sudo, else doas), or only display it in dry-run mode.
# Usage: _pkg_run <needs_root 0|1> <dry_run 0|1> <command> [args...]
_pkg_run()
{
local needs_root="$1" dry="$2"
shift 2
local -a prefix=()
if (( needs_root )) && [[ $EUID -ne 0 ]]; then
if command -v sudo >/dev/null 2>&1; then
prefix=(sudo)
elif command -v doas >/dev/null 2>&1; then
prefix=(doas)
elif (( ! dry )); then
disp E "Root privileges are required and neither sudo nor doas is available."
return 1
fi
fi
if (( dry )); then
# %q gives a copy-pasteable command line
printf '%q ' "${prefix[@]}" "$@"
printf '\n'
return 0
fi
if ! command -v "$1" >/dev/null 2>&1; then
disp E "'$1' is not installed."
return 1
fi
"${prefix[@]}" "$@"
}
export -f _pkg_run
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Install packages with the package manager of the distribution.
# Usage: pkgi [options] <package> [package...]
@@ -441,9 +397,6 @@ pkgi()
_pkg_run "$needs_root" "$dry_run" "${cmd[@]}" "$@"
}
export -f pkgi
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Uninstall packages with the package manager of the distribution.
# Usage: pkgr [options] <package> [package...]
@@ -597,5 +550,4 @@ pkgr()
export -f pkgr
# ------------------------------------------------------------------------------
# EOF