#!/usr/bin/env bash set -euo pipefail repo_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) official_file="$repo_root/packages-official.txt" aur_file="$repo_root/packages-aur.txt" install_official=true install_aur=true for arg in "$@"; do case "$arg" in --official-only) install_official=true install_aur=false ;; --aur-only) install_official=false install_aur=true ;; --help|-h) cat <<'EOF' Usage: ./install-pkg.sh [--official-only | --aur-only] Installs packages listed in: - packages-official.txt via pacman - packages-aur.txt via yay or paru EOF exit 0 ;; *) printf 'Unknown argument: %s\n' "$arg" >&2 exit 1 ;; esac done read_packages() { local file=$1 mapfile -t packages < <(grep -vE '^\s*($|#)' "$file") } if [[ "$install_official" == true ]]; then read_packages "$official_file" if (( ${#packages[@]} > 0 )); then sudo pacman -S --needed --noconfirm -- "${packages[@]}" fi fi if [[ "$install_aur" == true ]]; then helper= if command -v yay >/dev/null 2>&1; then helper=yay elif command -v paru >/dev/null 2>&1; then helper=paru else printf 'AUR helper not found. Install yay or paru first.\n' >&2 exit 1 fi read_packages "$aur_file" if (( ${#packages[@]} > 0 )); then "$helper" -S --needed --noconfirm -- "${packages[@]}" fi fi