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