summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2021-09-20 19:40:51 +0200
committerErich Eckner <git@eckner.net>2021-09-20 19:40:51 +0200
commit5bc944b1038307dd41578bac1b105b9868a2a6fa (patch)
tree35f67a293a2c0223a82b4488e159ce8e384109bf
parentb5ae2750f3353c9d1de89a1e1e56bccf9116ed2e (diff)
downloadarch-mirror-5bc944b1038307dd41578bac1b105b9868a2a6fa.tar.xz
clean-cache: also check size and checksum
-rwxr-xr-xclean-cache29
1 files changed, 29 insertions, 0 deletions
diff --git a/clean-cache b/clean-cache
index d2c9b3c..d580d4c 100755
--- a/clean-cache
+++ b/clean-cache
@@ -7,4 +7,33 @@ find "${mirror_dir}" -type f -printf '%h\n' \
| sort -u \
| while read -r repo_dir; do
paccache -v -r -k 2 -c "${repo_dir}"
+ if [ -z "${repo_dir##*/os/*}" ]; then
+ repo="${repo_dir%%/os/*}"
+ repo="${repo##*/}"
+ else
+ repo="${repo_dir##*/}"
+ fi
+ curl \
+ --resolve 'arch-mirror.home.eckner.net:80:127.0.0.1' \
+ -Ss 'http://arch-mirror.home.eckner.net/'"${repo_dir#${mirror_dir}/}/${repo}"'.db' \
+ | tar -Oxz \
+ | sed -n '
+ /^%\(FILENAME\|CSIZE\|SHA256SUM\)%$/,/^$/p
+ ' \
+ | grep -v '^%.*%$' \
+ | grep -vxF '' \
+ | sed '
+ N;N
+ s@\n@ @g
+ ' \
+ | while read -r file size sum; do
+ [ -f "${repo_dir}/${file}" ] || continue
+ if stat -c'%s' "${repo_dir}/${file}" \
+ | grep -qxF "${size}" \
+ && printf '%s %s/%s\n' "${sum}" "${repo_dir}" "${file}" \
+ | sha256sum -c --quiet; then
+ continue
+ fi
+ rm "${file}"
+ done
done