Skip to content

Instantly share code, notes, and snippets.

@hcartiaux
Last active May 30, 2026 01:41
Show Gist options
  • Select an option

  • Save hcartiaux/2cb9f3f8fc4f58c004413cfa029b4dfb to your computer and use it in GitHub Desktop.

Select an option

Save hcartiaux/2cb9f3f8fc4f58c004413cfa029b4dfb to your computer and use it in GitHub Desktop.
Fetch all AUR commit diffs in a given time window
#!/usr/bin/env bash
################################################################################
# aur-diff.sh - fetch all AUR commit diffs in a given time window
#
################################################################################
set -euo pipefail
# Default configuration
AUR_META_URL="https://aur.archlinux.org/packages-meta-v1.json.gz"
AUR_GIT_MIRROR="https://github.com/archlinux/aur.git"
OUTPUT_DIR="./output"
WORK_DIR="./work"
print_usage()
{
cat <<EOF
NAME
aur-diff.sh - fetch all AUR commit diffs in a given time window
SYNOPSIS
aur-diff.sh <begin_datetime> <end_datetime> [options]
DESCRIPTION
aur-diff.sh fetches all AUR commit diffs in a given time window,
and save them in the output directory for further analysis.
ARGUMENTS
begin_datetime
Start of the time window
end_datetime
End of the time window
Formats: "2025-08-01", "2025-08-01T14:00:00",
"2025-08-01T14:00:00+02:00", Unix timestamp
OPTIONS
-o | --output-dir <dir>
Output directory for per-package diff files
(default: stdout — all diffs merged to stdout)
-w | --work-dir <dir>
Working directory for git clones (default: /tmp/aur-diff-XXXX)
-h | --help
Show this help
EXAMPLES
# All commit diffs for the past 24 hours
./aur-diff.sh "\$(date -d '24 hours ago' --iso-8601=seconds)" "\$(date --iso-8601=seconds)"
# Specific window, save commit diff to a specific directory
./aur-diff.sh 2026-05-01 2026-05-31 -o ./aur-diff-2026-05
CONTACT
Hyacinthe Cartiaux <hyacinthe@archlinux.org>
EOF
}
function fail { echo "[FAIL] $*" 1>&2 && exit 1; }
function info { echo ":: $*"; }
function check_cmd {
local program="${1}"
command -v "${program}" > /dev/null 2>&1 || fail "'${program}' is not installed"
}
function check_depends {
check_cmd curl
check_cmd git
check_cmd jq
check_cmd gzip
}
function ts_to_iso() {
local raw="${1}"
if [[ "${raw}" =~ ^[0-9]+$ ]]; then
date -d "@${raw}" --iso-8601=seconds
else
date -d "${raw}" --iso-8601=seconds
fi
}
function ts_to_unix() {
local raw="${1}"
if [[ "${raw}" =~ ^[0-9]+$ ]]; then
echo "${raw}"
else
date -d "${raw}" +%s
fi
}
function get_package_commits() {
local pkg="${1}"
local pkg_repo_dir="${WORK_DIR}/repos/${pkg}"
git clone --quiet --single-branch \
--branch "${pkg}" \
--shallow-since="${BEGIN_ISO}" \
-- "${AUR_GIT_MIRROR}" "${pkg_repo_dir}" 2>/dev/null || true
local -a commits=()
mapfile -t commits < <(git -C "${pkg_repo_dir}" log \
--after="${BEGIN_ISO}" \
--before="${END_ISO}" \
--format="%H" 2>/dev/null || true)
if [[ "${#commits[@]}" -gt 0 ]]; then
{
for sha in "${commits[@]}"; do
git -C "${pkg_repo_dir}" show --patch-with-stat "${sha}"
echo
done
} > "${OUTPUT_DIR}/${pkg}.diff"
fi
}
# Check for parameters
if [[ $# -lt 2 ]]; then
print_usage
exit 0
fi
BEGIN_RAW="${1}"; shift
END_RAW="${1}"; shift
while [ $# -ge 1 ]; do
case "${1}" in
-o | --output-dir) shift; OUTPUT_DIR="${1}"; ;;
-w | --work-dir) shift; WORK_DIR="${1}"; ;;
-h | --help) print_usage; exit 0 ;;
*) fail "Unsupported parameter. Use -h for help." ;;
esac
shift
done
check_depends
BEGIN_ISO=$( ts_to_iso "${BEGIN_RAW}") || fail "Invalid begin datetime: '${BEGIN_RAW}'"
END_ISO=$( ts_to_iso "${END_RAW}") || fail "Invalid end datetime: '${END_RAW}'"
BEGIN_UNIX=$(ts_to_unix "${BEGIN_RAW}") || fail "Cannot convert begin datetime to unix"
END_UNIX=$( ts_to_unix "${END_RAW}") || fail "Cannot convert end datetime to unix"
if [[ "${BEGIN_UNIX}" -ge "${END_UNIX}" ]]; then
fail "begin_datetime (${BEGIN_ISO}) must be strictly before end_datetime (${END_ISO})"
fi
info "Time window: ${BEGIN_ISO} - ${END_ISO}"
info " ${BEGIN_UNIX} - ${END_UNIX}"
# Working directory set-up
mkdir -p "${WORK_DIR}"
info "Work directory: ${WORK_DIR}"
cleanup() {
info "Cleaning up ${WORK_DIR}"
echo rm -rf -- "${WORK_DIR}"
}
trap cleanup EXIT
# Output directory
if [[ -n "${OUTPUT_DIR}" ]]; then
mkdir -p "${OUTPUT_DIR}"
info "Output directory: ${OUTPUT_DIR}"
fi
# Fetch / decompress AUR metadata
META_JSON="${WORK_DIR}/packages-meta-v1.json"
info "Downloading AUR metadata from ${AUR_META_URL} ..."
curl -fsSL -- "${AUR_META_URL}" | gzip -d > "${META_JSON}"
info "Metadata downloaded"
info "Filtering packages modified between unix ${BEGIN_UNIX} and ${END_UNIX} ..."
mapfile -t PKGS < <(
jq -r --argjson begin "${BEGIN_UNIX}" --argjson end "${END_UNIX}" \
"[.[] | select(.LastModified >= \$begin and .LastModified <= \$end)] \
| map(.PackageBase) | unique | .[]" "${META_JSON}"
)
info "${#PKGS[@]} packages were modified in the time window"
for i in "${!PKGS[@]}"; do
info "[$((i + 1))/${#PKGS[@]}] Downloading ${PKGS[$i]} commits"
get_package_commits "${PKGS[$i]}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment