Use script-framework for output

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-10-07 14:40:16 +02:00
parent 7b558ee084
commit 7d4e6a5871
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -1,18 +1,18 @@
#!/bin/bash #!/bin/bash
set -euo pipefail set -euo pipefail
source ${HOME}/bin/script_framework.sh
TARGET="${HOME}/.local/share/arch-package-index" TARGET="${HOME}/.local/share/arch-package-index"
# Check for pacman (and with it for Archlinux) # Check for pacman (and with it for Archlinux)
which pacman >/dev/null 2>&1 || { which pacman >/dev/null 2>&1 || {
echo "Tool 'pacman' not found: This script only works for Archlinux" >&2 fail "Tool 'pacman' not found: This script only works for Archlinux"
exit 1
} }
# Check for comm to be installed # Check for comm to be installed
which comm >/dev/null 2>&1 || { which comm >/dev/null 2>&1 || {
echo "Please install 'comm' utility" >&2 fail "Please install 'comm' utility"
exit 1
} }
# Ensure the target dir exists # Ensure the target dir exists
@ -21,12 +21,19 @@ mkdir -p ${TARGET}
# CD into target dir # CD into target dir
pushd ${TARGET} >/dev/null 2>&1 pushd ${TARGET} >/dev/null 2>&1
if ! [ -d .git ]; then
step "Initializing empty git dir"
git init -q
fi
[ -f groups.txt ] || { [ -f groups.txt ] || {
echo "No groups.txt found, creating one with 'base' group." warn "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..." warn "You might want to edit your ${TARGET}/groups.txt and add more groups installed on your system..."
echo "base" >groups.txt echo "base" >groups.txt
} }
step "Collecting installed packages..."
# Collect packages not contained in groups # Collect packages not contained in groups
pacman -Qgq $(cat groups.txt) | sort >group-packages.txt pacman -Qgq $(cat groups.txt) | sort >group-packages.txt
@ -38,19 +45,17 @@ comm -23 non-group-packages.txt official-packages.txt >aur-packages.txt
# Remove temporary stores # Remove temporary stores
rm group-packages.txt non-group-packages.txt rm group-packages.txt non-group-packages.txt
echo "Package files updated" >&2 info "Package files updated"
if [ -d '.git' ]; then step "Creating update commit..."
echo "Git directory found, creating update commit" >&2
git_files=( git_files=(
aur-packages.txt aur-packages.txt
groups.txt groups.txt
official-packages.txt official-packages.txt
) )
git add "${git_files[@]}" git add "${git_files[@]}"
git commit --no-gpg-sign -m 'Update from arch-package-index' "${git_files[@]}" git commit -q --no-gpg-sign -m 'Update from arch-package-index' "${git_files[@]}"
fi
popd >/dev/null 2>&1 popd >/dev/null 2>&1