From ff2983c207e6ab2a9381e20312355c42307187f6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 17 Apr 2016 01:56:43 -0400 Subject: Give things more consistent names --- cron-jobs/db-cleanup | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 cron-jobs/db-cleanup (limited to 'cron-jobs/db-cleanup') diff --git a/cron-jobs/db-cleanup b/cron-jobs/db-cleanup new file mode 100755 index 0000000..ffa2601 --- /dev/null +++ b/cron-jobs/db-cleanup @@ -0,0 +1,69 @@ +#!/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")")/db-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 + +EXTRAFLAGS=() +"${CLEANUP_DRYRUN}" && EXTRAFLAGS+=(--dry-run) + +filter=$(mktemp -t "${0##*/}.XXXXXXXXXX") +trap "rm -f -- $(printf %q "$filter")" EXIT + +for _repo in "${PKGREPOS[@]}"; do + for _arch in "${ARCHES[@]}"; do + msg "Getting %s-%s database" "${_repo}" "${_arch}" + + 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|$|*|" >> "$filter" + + done +done + +msg "Removing old files:" + +for POOL in "${PKGPOOLS[@]}" "${SRCPOOLS[@]}"; do + msg2 '%s' "${POOL}" + + rsync "${EXTRAFLAGS[@]}" -va --delete-excluded \ + --include-from="$filter" \ + --exclude="*" \ + "${FTP_BASE}/${POOL}/" \ + "${FTP_BASE}/${POOL}/" +done + +msg "Removing dead symlinks:" +actions=(-print) +"${CLEANUP_DRYRUN}" || actions+=(-delete) +find -L "${FTP_BASE}/" -type l "${actions[@]}" -- cgit v1.2.3-2-g168b From 1f7bbb22ced3495140810b9ec21d93ebb4c161f3 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 17 Apr 2016 02:17:15 -0400 Subject: begone with db-libremessages --- cron-jobs/db-cleanup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cron-jobs/db-cleanup') diff --git a/cron-jobs/db-cleanup b/cron-jobs/db-cleanup index ffa2601..ce0e5f7 100755 --- a/cron-jobs/db-cleanup +++ b/cron-jobs/db-cleanup @@ -15,8 +15,8 @@ trap_exit() { exit 1 } -source "$(dirname "$(readlink -e "$0")")/config" -source "$(dirname "$(readlink -e "$0")")/db-libremessages" +source "$(dirname $(dirname "$(readlink -e "$0")"))/config" +source "$(librelib messages)" # From makepkg set -E -- cgit v1.2.3-2-g168b From f3add3749351c9070e0fbe43f37b5a94ac1e7123 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 17 Apr 2016 13:58:19 -0400 Subject: more config file cleanup --- cron-jobs/db-cleanup | 1 + 1 file changed, 1 insertion(+) (limited to 'cron-jobs/db-cleanup') diff --git a/cron-jobs/db-cleanup b/cron-jobs/db-cleanup index ce0e5f7..12d3615 100755 --- a/cron-jobs/db-cleanup +++ b/cron-jobs/db-cleanup @@ -16,6 +16,7 @@ trap_exit() { } source "$(dirname $(dirname "$(readlink -e "$0")"))/config" +source "$(dirname "$(readlink -e "$0")")/db-cleanup.conf" source "$(librelib messages)" # From makepkg -- cgit v1.2.3-2-g168b