pm_base.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. # pm_base.sh - Base package manager interface for USM installer
  3. #
  4. # This file provides the generic interface that dispatches to the
  5. # appropriate package manager implementation.
  6. #
  7. # To add a new package manager:
  8. # 1. Create pm_<name>.sh with:
  9. # - pm_<name>_detect: Returns 0 if available, 1 otherwise
  10. # - pm_<name>_get_missing_deps: Prints missing package names
  11. # - pm_<name>_install_missing_deps: Installs missing packages
  12. # 2. The compiler will automatically pick it up
  13. # Detect the available package manager
  14. # Sets PM_TYPE and returns 0 on success, 1 if no supported PM found
  15. detect_package_manager() {
  16. # Try each PM implementation
  17. for pm_impl in "${PM_IMPLEMENTATIONS[@]}"; do
  18. if "pm_${pm_impl}_detect" 2>/dev/null; then
  19. PM_TYPE="$pm_impl"
  20. return 0
  21. fi
  22. done
  23. PM_TYPE="unknown"
  24. return 1
  25. }
  26. # Get missing dependencies using the detected package manager
  27. pm_get_missing_deps() {
  28. case "$PM_TYPE" in
  29. apt) pm_apt_get_missing_deps "$@" ;;
  30. dnf) pm_dnf_get_missing_deps "$@" ;;
  31. *)
  32. log_error "No package manager detected"
  33. echo ""
  34. ;;
  35. esac
  36. }
  37. # Install missing dependencies using the detected package manager
  38. pm_install_missing_deps() {
  39. case "$PM_TYPE" in
  40. apt) pm_apt_install_missing_deps "$@" ;;
  41. dnf) pm_dnf_install_missing_deps "$@" ;;
  42. *)
  43. log_error "No package manager detected"
  44. return 1
  45. ;;
  46. esac
  47. }
  48. # Count missing dependencies
  49. count_missing_deps() {
  50. local missing=$(pm_get_missing_deps)
  51. if [[ -z "$missing" ]]; then
  52. echo 0
  53. else
  54. echo "$missing" | wc -w
  55. fi
  56. }