diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-12-16 03:04:24 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-12-16 03:04:24 -0500 |
commit | 9fd6f1931df506210f3724b08be0fde08cc8b89b (patch) | |
tree | 521ca6ff94524ea67ff973d4d8531676f948d511 | |
parent | 3990c562952d8f71da933b1a38ddd7c93f05d36d (diff) |
packages.sh x60rewrite
-rwxr-xr-x | packages.sh | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/packages.sh b/packages.sh index 8296644..88e4ec0 100755 --- a/packages.sh +++ b/packages.sh @@ -1,19 +1,56 @@ -#!/bin/bash +#!/usr/bin/env bash + +# parse packages.txt 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')) -igns=($(printf -- '%s\n' "${all[@]}" | sed -n 's/^i://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 + +# set up tmpdir +tmpdir="$(mktemp --tmpdir -d "${0##*/}.XXXXXXXXXX")" +#trap "cd / && rm -rf -- $(printf '%q' "$tmpdir")" EXIT +cd "$tmpdir" + +# list dependencies +{ + pacman -Sgq -- "${grps[@]}"|grep -vFx -f <(printf '%s\n' "${excl[@]}") + printf '%s\n' "${pkgs[@]}" +} | sort -u > depends.txt +pacman -Qq | sort -u > installed.txt +pseudo() { + while read -r pkg; do + provider=$(pacsift --local --provides "$pkg" <&-|cut -d/ -f2) + if [[ -n "$provider" ]]; then + printf 'provided %s\n' "$pkg" + printf 'provider %s\n' $provider # unquoted + else + printf 'missing %s\n' "$pkg" + fi + done +} +comm -23 depends.txt installed.txt | pseudo > missing-or-provided.txt +sed -n 's/^provided //p' <missing-or-provided.txt |sort -u>provided.txt +sed -n 's/^provider //p' <missing-or-provided.txt |sort -u>provider.txt +sed -n 's/^missing //p' <missing-or-provided.txt |sort -u>missing.txt +cat installed.txt <(comm -12 depends.txt provider.txt)|sort -u>listed.txt +pacman -Qi|sed -n 's/^Depends On\s*://p'|xargs printf '%s\n'|sort -u>all-depends.txt + +# output echo ' => In packages.txt, but not installed' -comm -13 \ - <(pacman -Qq|sort -u) \ - <({ pacman -Sgq -- "${grps[@]}"; printf '%s\n' "${pkgs[@]}"; }|sort -u) | -sed 's|^| -> |' +< "$tmpdir/missing.txt" \ +sed 's|^| -> |' echo ' => Installed explicitly and not depended on, but not in packages.txt' comm -23 \ - <(pacman -Qetq |sort -u) \ - <({ pacman -Sgq -- "${grps[@]}"; printf '%s\n' "${pkgs[@]}"; }|sort -u) | + <(pacman -Qetq|sort -u) \ + "$tmpdir/listed.txt" | sed 's|^| -> |' echo ' => Installed explicitly and only optionally depended on, but not in packages.txt' @@ -21,9 +58,11 @@ comm -23 \ <(comm -23 \ <(pacman -Qettq|sort -u) \ <(pacman -Qetq |sort -u)) \ - <({ pacman -Sgq -- "${grps[@]}"; printf '%s\n' "${pkgs[@]}"; }|sort -u) | + "$tmpdir/listed.txt" | sed 's|^| -> |' +comm -13 depends.txt provider.txt + echo ' => Installed as dependencies, but only optionally depended on' comm -23 \ <(pacman -Qdttq|sort -u) \ @@ -31,4 +70,4 @@ comm -23 \ sed 's|^| -> |' echo ' => Installed as dependencies, but not depended on' -pacman -Qdtq|sort -u |sed 's|^| -> |' +pacman -Qdtq|sort -u|sed 's|^| -> |' |