From 7b558ee084b2da2cd177a195bd6e10f3e5968426 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 7 Oct 2018 14:30:15 +0200 Subject: [PATCH] Add collector script for installed arch packages Signed-off-by: Knut Ahlers --- bin/arch-package-index | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 bin/arch-package-index diff --git a/bin/arch-package-index b/bin/arch-package-index new file mode 100755 index 0000000..15ab3fe --- /dev/null +++ b/bin/arch-package-index @@ -0,0 +1,56 @@ +#!/bin/bash +set -euo pipefail + +TARGET="${HOME}/.local/share/arch-package-index" + +# Check for pacman (and with it for Archlinux) +which pacman >/dev/null 2>&1 || { + echo "Tool 'pacman' not found: This script only works for Archlinux" >&2 + exit 1 +} + +# Check for comm to be installed +which comm >/dev/null 2>&1 || { + echo "Please install 'comm' utility" >&2 + exit 1 +} + +# Ensure the target dir exists +mkdir -p ${TARGET} + +# CD into target dir +pushd ${TARGET} >/dev/null 2>&1 + +[ -f groups.txt ] || { + echo "No groups.txt found, creating one with 'base' group." + echo "You might want to edit your ${TARGET}/groups.txt and add more groups installed on your system..." + echo "base" >groups.txt +} + +# Collect packages not contained in groups +pacman -Qgq $(cat groups.txt) | sort >group-packages.txt + +# Collect packages +comm -23 <(pacman -Qeq | sort) group-packages.txt >non-group-packages.txt +comm -23 <(pacman -Qeqn | sort) group-packages.txt >official-packages.txt +comm -23 non-group-packages.txt official-packages.txt >aur-packages.txt + +# Remove temporary stores +rm group-packages.txt non-group-packages.txt + +echo "Package files updated" >&2 + +if [ -d '.git' ]; then + echo "Git directory found, creating update commit" >&2 + + git_files=( + aur-packages.txt + groups.txt + official-packages.txt + ) + + git add "${git_files[@]}" + git commit --no-gpg-sign -m 'Update from arch-package-index' "${git_files[@]}" +fi + +popd >/dev/null 2>&1