pm_pacman.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. # pm_pacman.sh - pacman package manager implementation for Arch systems
  3. #
  4. # To add a new package manager, create a file named pm_<name>.sh with:
  5. # - pm_<name>_detect: Returns 0 if this PM is available, 1 otherwise
  6. # - pm_<name>_get_missing_deps: Prints space-separated list of missing packages
  7. # - pm_<name>_install_missing_deps: Installs the missing packages
  8. #
  9. # Arch notes:
  10. # - PACMAN_DEPS mirror the dnf/apt dependency sets. Arch carries no
  11. # -dev split: glib2, json-glib, libgee, gobject-introspection ship
  12. # headers, pkg-config, .gir/.typelib and .vapi artifacts themselves,
  13. # and glibc already bundles the crt objects gcc needs, so no
  14. # companion package (musl-dev style) is required.
  15. # Package names required by USM
  16. PACMAN_DEPS="vala meson ninja pkgconf gcc glib2 libsodium json-glib libarchive libgee xz gobject-introspection"
  17. # Check if this package manager is available
  18. pm_pacman_detect() {
  19. command -v pacman &>/dev/null
  20. }
  21. # Get list of missing dependencies
  22. pm_pacman_get_missing_deps() {
  23. local -a missing=()
  24. for pkg in $PACMAN_DEPS; do
  25. if ! pacman -Q "$pkg" &>/dev/null; then
  26. missing+=("$pkg")
  27. fi
  28. done
  29. echo "${missing[*]}"
  30. }
  31. # Install missing dependencies
  32. pm_pacman_install_missing_deps() {
  33. local missing=$(pm_pacman_get_missing_deps)
  34. if [[ -z "$missing" ]]; then
  35. log_info "All dependencies are already installed"
  36. return 0
  37. fi
  38. log_step "Installing packages via pacman: ${missing}"
  39. local sudo=""
  40. if ! is_root; then
  41. sudo=$(get_sudo)
  42. fi
  43. local pacman_opts="--needed --noconfirm"
  44. if [[ -n "$sudo" ]]; then
  45. $sudo pacman -Sy $pacman_opts $missing
  46. else
  47. pacman -Sy $pacman_opts $missing
  48. fi
  49. }