#!/bin/bash mirror_dir='/srv/http/arch-mirror' find "${mirror_dir}" -type f -printf '%h\n' \ | uniq \ | 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