36 lines
1020 B
Bash
36 lines
1020 B
Bash
#!/bin/bash
|
|
# Install all packages from this machine via pacman.
|
|
# --needed skips already-installed packages.
|
|
# Only leaf packages are listed; dependencies are pulled in automatically.
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
PACKAGE_FILE="$SCRIPT_DIR/packages.txt"
|
|
|
|
if [[ ! -f "$PACKAGE_FILE" ]]; then
|
|
echo "Error: $PACKAGE_FILE not found"
|
|
exit 1
|
|
fi
|
|
|
|
# Read packages from file, skipping blank lines and comments
|
|
mapfile -t packages < <(grep -v '^\s*#' "$PACKAGE_FILE" | grep -v '^\s*$')
|
|
|
|
if [[ ${#packages[@]} -eq 0 ]]; then
|
|
echo "No packages found in $PACKAGE_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Installing ${#packages[@]} packages..."
|
|
skipped=()
|
|
for pkg in "${packages[@]}"; do
|
|
if pacman -Si "$pkg" &>/dev/null || pacman -Sg "$pkg" &>/dev/null; then
|
|
sudo pacman -S --needed --noconfirm "$pkg"
|
|
else
|
|
echo "Skipping '$pkg': not found in repositories"
|
|
skipped+=("$pkg")
|
|
fi
|
|
done
|
|
|
|
if [[ ${#skipped[@]} -gt 0 ]]; then
|
|
echo "Skipped ${#skipped[@]} package(s): ${skipped[*]}"
|
|
fi
|