bootstrap: Split packages into stable and testing lists

Split the lists into two, with testing getting automatically updated on
packages added (and removed, but only if the package to be removed is
*not* in stable packages already).

This way, I can always be sure that I have my stable setup in the
repository, but packages that I am temporarily testing have a place
without being forgotten and I can more easily change them around until
they find a place in stable or get thrown out.
This commit is contained in:
Marty Oehme 2023-01-16 18:47:47 +01:00
parent d56d0148f6
commit 1a05ea8445
Signed by: Marty
GPG key ID: 73BA40D5AFAF49C9
4 changed files with 43 additions and 27 deletions

View file

@ -1,16 +1,18 @@
#!/usr/bin/env bash
BOOTSTRAP_DIR=~/.dotfiles/bootstrap
OUTPUT=${BOOTSTRAP_DIR}/packages.tsv
BOOTSTRAP_DIR=${BOOTSTRAP_DIR:-$(pwd)/bootstrap}
INPUTFILES=$(find "${BOOTSTRAP_DIR}" -type f -name 'packages*.tsv')
OUTPUTFILE=${BOOTSTRAP_DIR}/packages_testing.tsv
pkg_all=$(pacman -Qqett | grep -v "$(pacman -Qqg base-devel)")
pkg_repo=$(pacman -Qqn)
pkg_aur=$(pacman -Qqm)
while getopts "nvh" opt; do
while getopts "nvhf:" opt; do
case "$opt" in
n) DRYRUN=true ;;
v) VERBOSE=true ;;
f) OUTPUTFILE="$OPTARG" ;;
h | *)
{
printf "\nUpdate the list of installed packages.\n\nWill compare packages committed to the dotfile repository\nand those currently installed (on an Arch system, using pacman).\nUpdates the list of committed packages in repository\nand prints out the differences as a diff.\n\nOptions:\n\n\t-h\tDisplay this help.\n\t-v\tShow verbose information.\n\t-n\tPrint out changes without changing anything (dry-run).\n"
@ -20,6 +22,13 @@ while getopts "nvh" opt; do
esac
done
# get all existing written packages
if [ -n "$INPUTFILES" ]; then
INPUT=$(cat $INPUTFILES | grep -v -e '^Name Description Source Target' | sort)
else
INPUT=""
fi
print_msg() {
# shellcheck disable=2059
[ -n "$VERBOSE" ] && printf "$@"
@ -29,10 +38,10 @@ print_msg() {
# packagename, description, source, target
# toot a toot manager A D
if [ -f "${OUTPUT}_TEMP" ]; then
rm "${OUTPUT}_TEMP"
if [ -f "${OUTPUTFILE}_TEMP" ]; then
rm "${OUTPUTFILE}_TEMP"
fi
touch "${OUTPUT}_TEMP"
touch "${OUTPUTFILE}_TEMP"
# create new package list
for pkg in $pkg_all; do
@ -52,9 +61,7 @@ for pkg in $pkg_all; do
desc="${desc#"${desc%%[![:space:]]*}"}"
target=""
if [ -f "$OUTPUT" ]; then
found_line=$(grep -e "^$pkg" "$OUTPUT")
fi
found_line=$(echo "$INPUT" | grep -e "^$pkg")
if [ -n "$found_line" ]; then
target=$(echo "$found_line" | cut -f4)
print_msg "Updating pkg: %s:%s from: %s, for: %s\n" "$pkg" "$desc" "$source" "$target"
@ -62,26 +69,29 @@ for pkg in $pkg_all; do
print_msg "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"
printf "%s\t%s\t%s\t%s\n" "$pkg" "$desc" "$source" "$target" >>"${OUTPUTFILE}_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\n" "$line"
fi
done <<<"$(tail +2 $OUTPUT)"
fi
while read -r line; do
if ! echo "$line" | cut -f1 | xargs -I _ grep -F -q -x _ <(echo "$pkg_all"); then
printf "REMOVED: %s\n" "$line"
fi
done <<<"<(echo $INPUT | tail +2)"
# show file changes
if [ -f "$OUTPUT" ] && [ -f "$OUTPUT"_TEMP ]; then
changes=$(diff --color=always -y --suppress-common-lines "$OUTPUT" "$OUTPUT"_TEMP | tail -n+2)
if [ -f "$OUTPUTFILE"_TEMP ]; then
changes=$(diff --color=always -y --suppress-common-lines <(echo "$INPUT") <(sort "$OUTPUTFILE"_TEMP | tail -n+2))
printf "FILE CHANGES:\n=============\n%s" "$changes"
fi
# actually write to file
# actually write changes to file
if [ -z "$DRYRUN" ]; then
cat <(printf "Name\tDescription\tSource\tTarget\n") "${OUTPUT}_TEMP" >"$OUTPUT"
while IFS= read -r line; do
sed -i -e "/^${line//\//\\/}$/d" "$OUTPUTFILE"_TEMP
done <<< "$INPUT"
cat <(printf "Name\tDescription\tSource\tTarget\n") "${OUTPUTFILE}_TEMP" > "$OUTPUTFILE"
fi
rm "${OUTPUT}_TEMP"
rm "${OUTPUTFILE}_TEMP"