#!/bin/bash all=($(< packages.txt sed 's/#.*//' | xargs printf -- '%s\n' | sort -u)) grps=($(printf -- '%s\n' "${all[@]}" | sed -n 's/^g://p')) pkgs=($(printf -- '%s\n' "${all[@]}" | sed -n 's/^p://p')) excl=($(printf -- '%s\n' "${all[@]}" | sed -n 's/^x://p')) bads=($(printf -- '%s\n' "${all[@]}" | grep -v '^[gpx]:')) if [[ ${#bads[@]} -gt 0 ]]; then echo ' => Invalid entries in packages.txt' printf ' -> %s\n' "${bads[@]}" exit 1 fi packages_txt() { { if [[ ${#grps[@]} -gt 0 ]]; then pacman -Sgq -- "${grps[@]}"|grep -vFx -f <(printf '%s\n' "${excl[@]}") fi if [[ ${#pkgs[@]} -gt 0 ]]; then printf '%s\n' "${pkgs[@]}" fi } | sort -u } echo ' => In packages.txt, but not installed' comm -13 \ <(pacman -Qq|sort -u) \ <(packages_txt) | sed 's|^| -> |' echo ' => Installed explicitly and not depended on, but not in packages.txt' comm -23 \ <(pacman -Qetq |sort -u) \ <(packages_txt) | sed 's|^| -> |' echo ' => Installed explicitly and only optionally depended on, but not in packages.txt' comm -23 \ <(comm -23 \ <(pacman -Qettq|sort -u) \ <(pacman -Qetq |sort -u)) \ <(packages_txt) | sed 's|^| -> |' echo ' => Installed as dependencies, but only optionally depended on' comm -23 \ <(pacman -Qdttq|sort -u) \ <(pacman -Qdtq |sort -u) | sed 's|^| -> |' echo ' => Installed as dependencies, but not depended on' pacman -Qdtq|sort -u |sed 's|^| -> |'