diff options
Diffstat (limited to 'db-cleanup')
-rwxr-xr-x | db-cleanup | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/db-cleanup b/db-cleanup new file mode 100755 index 0000000..57ef36e --- /dev/null +++ b/db-cleanup @@ -0,0 +1,66 @@ +#!/bin/bash +# Syncs pools against themselves using database contents as filter to cleanup +# them up +# License: GPLv3 + +# Principles +# * Get repos dbs contents +# * Make them a include list +# * Rsync pools against themselves removing excluded files +# * Instant cleanup! + +trap_exit() { + echo + error "$@" + exit 1 +} + +source "$(dirname "$(readlink -e "$0")")/config" +source "$(dirname "$(readlink -e "$0")")/libremessages" + +# From makepkg +set -E + +trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT +trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT +trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR + +${CLEANUP_DRYRUN} && EXTRAFLAGS+=" --dry-run" + +for _repo in ${PKGREPOS[@]}; do + for _arch in ${ARCHES[@]}; do + msg "Getting ${_repo}-${_arch} database" + + dbfile="${FTP_BASE}/${_repo}/os/${_arch}/${_repo}${DBEXT}" + + if [ ! -r "${dbfile}" ]; then + warning "Not found" + continue + fi + +# Echo the contents into a filter file + bsdtar tf "${dbfile}" | \ + cut -d'/' -f1 | \ + sort -u | \ + sed "s|$|*|" >> /tmp/${0##*/}.$$.filter + + done +done + +msg "Removing old files:" + +for POOL in ${PKGPOOLS[@]} ${SRCPOOLS[@]}; do + msg2 "${POOL}" + + rsync ${EXTRAFLAGS} -va --delete-excluded \ + --include-from="/tmp/${0##*/}.$$.filter" \ + --exclude="*" \ + ${FTP_BASE}/${POOL}/ \ + ${FTP_BASE}/${POOL}/ +done + +msg "Removing symlinks:" +find -L ${FTP_BASE}/ -type l +${CLEANUP_DRYRUN} || find -L ${FTP_BASE}/ -type l -delete + +exit $? |