bootstrap: Switch package list to tsv

Package list is now a single tab separated list. That should make
several automations in the future much simpler.

The table is built as follows:
`Name   Description Source  Target`

with one line per package. Source denotes official repositories or AUR,
and target is kept for future potential of creating different
deployments per target automatically (e.g. different package list for
desktop and server, and so on).

There is an updater script `bootstrap/update_package_list.sh` which will
automatically populate the table, removing uninstalled packages, adding
new ones and (making its best attempt to be) keeping the selected
targets as they are.

The git commit hook comparing installed and committed packages has also
been rewritten to use the new table and be a little simpler overall.

Fixes #2.
This commit is contained in:
Marty Oehme 2022-03-09 11:13:45 +01:00
parent 0a9271ffe8
commit 280fab6ad3
Signed by: Marty
GPG key ID: B7538B8F50A1C800
6 changed files with 374 additions and 356 deletions

View file

@ -0,0 +1,61 @@
#!/usr/bin/env bash
BOOTSTRAP_DIR=~/.dotfiles/bootstrap
OUTPUT=${BOOTSTRAP_DIR}/packages.tsv
pkg_all=$(pacman -Qqett | grep -v "$(pacman -Qqg base-devel)")
pkg_repo=$(pacman -Qqn)
pkg_aur=$(pacman -Qqm)
# tsv file:
# packagename, description, source, target
# toot a toot manager A D
if [ -f "${OUTPUT}_TEMP" ]; then
rm "${OUTPUT}_TEMP"
fi
touch "${OUTPUT}_TEMP"
# create new package list
for pkg in $pkg_all; do
source=""
if $(echo "$pkg_repo" | grep -F -q -x "$pkg"); then
source="R"
elif $(echo "$pkg_aur" | grep -F -q -x "$pkg"); then
source="A"
else
echo "ERROR: The package $pkg could not be found in repositories or AUR."
exit 1
fi
desc=$(pacman -Qs "$pkg" | grep -A1 --color "local/$pkg\s" | tail -n1)
#remove leading whitespace
desc="${desc#"${desc%%[![:space:]]*}"}"
target=""
if [ -f "$OUTPUT" ]; then
found_line=$(grep -e "^$pkg" "$OUTPUT")
fi
if [ -n "$found_line" ]; then
target=$(echo "$found_line" | cut -f4)
printf "Updating pkg: %s:%s from: %s, for: %s\n" "$pkg" "$desc" "$source" "$target"
else
printf "Adding pkg: %s:%s from: %s, for: %s\n" "$pkg" "$desc" "$source" "$target"
fi
printf "%s\t%s\t%s\t%s\n" "$pkg" "$desc" "$source" "$target" >>"${OUTPUT}_TEMP"
done
# notify on any removed packages
if [ -f "$OUTPUT" ]; then
while read -r line; do
if ! echo "$line" | cut -f1 | xargs -I _ grep -F -q -x _ <(echo "$pkg_all"); then
printf "REMOVED: %s" "$line"
fi
done <<<$(tail +2 "$OUTPUT")
fi
# actually write to file
cat <(printf "Name\tDescription\tSource\tTarget\n") "${OUTPUT}_TEMP" >"$OUTPUT"
rm "${OUTPUT}_TEMP"