#!/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_.sh with: # - pm__detect: Returns 0 if available, 1 otherwise # - pm__get_missing_deps: Prints missing package names # - pm__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 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 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 }