| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #!/bin/bash
- # pm_base.sh - Base package manager interface for USM installer
- #
- # This file provides the generic interface that dispatches to the
- # appropriate package manager implementation.
- #
- # To add a new package manager:
- # 1. Create pm_<name>.sh with:
- # - pm_<name>_detect: Returns 0 if available, 1 otherwise
- # - pm_<name>_get_missing_deps: Prints missing package names
- # - pm_<name>_install_missing_deps: Installs missing packages
- # 2. The compiler will automatically pick it up
- # Detect the available package manager
- # Sets PM_TYPE and returns 0 on success, 1 if no supported PM found
- detect_package_manager() {
- # Try each PM implementation
- for pm_impl in "${PM_IMPLEMENTATIONS[@]}"; do
- if "pm_${pm_impl}_detect" 2>/dev/null; then
- PM_TYPE="$pm_impl"
- return 0
- fi
- done
-
- PM_TYPE="unknown"
- return 1
- }
- # Get missing dependencies using the detected package manager
- pm_get_missing_deps() {
- case "$PM_TYPE" in
- apk) pm_apk_get_missing_deps "$@" ;;
- apt) pm_apt_get_missing_deps "$@" ;;
- dnf) pm_dnf_get_missing_deps "$@" ;;
- *)
- log_error "No package manager detected"
- echo ""
- ;;
- esac
- }
- # Install missing dependencies using the detected package manager
- pm_install_missing_deps() {
- case "$PM_TYPE" in
- apk) pm_apk_install_missing_deps "$@" ;;
- apt) pm_apt_install_missing_deps "$@" ;;
- dnf) pm_dnf_install_missing_deps "$@" ;;
- *)
- log_error "No package manager detected"
- return 1
- ;;
- esac
- }
- # Count missing dependencies
- count_missing_deps() {
- local missing=$(pm_get_missing_deps)
- if [[ -z "$missing" ]]; then
- echo 0
- else
- echo "$missing" | wc -w
- fi
- }
|