From 51e733fdb525e1c1e9392aa4c3a0b882a6433ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Reynolds?= Date: Wed, 23 Nov 2011 13:19:35 -0300 Subject: Cleanup script + New config vars --- db-cleanup | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 db-cleanup (limited to 'db-cleanup') diff --git a/db-cleanup b/db-cleanup new file mode 100755 index 0000000..0c093c2 --- /dev/null +++ b/db-cleanup @@ -0,0 +1,63 @@ +#!/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 $0)/config +source $(dirname $0)/local_config +source $(dirname $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 ${ARCHREPOS[@]}; do + for _arch in ${ARCHARCHES[@]}; 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.$PID.filter + + done +done + +msg "Removing old files:" + +for POOL in ${PKGPOOLS[@]} ${SRCPOOLS[@]}; do + msg2 "${POOL}" + + rsync ${EXTRAFLAGS} -va --delete-excluded \ + --include-from="${dbfile}" \ + --exclude="*" \ + ${FTP_BASE}/${POOL}/ \ + ${FTP_BASE}/${POOL}/ +done + +exit $? -- cgit v1.2.3-2-g168b From ee7bba114de818df23196edb7d0d785217b7a332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Reynolds?= Date: Wed, 23 Nov 2011 13:24:00 -0300 Subject: DRYRUN check --- db-cleanup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'db-cleanup') diff --git a/db-cleanup b/db-cleanup index 0c093c2..b12e9c1 100755 --- a/db-cleanup +++ b/db-cleanup @@ -26,7 +26,7 @@ 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" +${CLEANUP_DRYRUN} && EXTRAFLAGS+=" --dry-run" for _repo in ${ARCHREPOS[@]}; do for _arch in ${ARCHARCHES[@]}; do -- cgit v1.2.3-2-g168b From 4a31562deb872713acae3d17f0f638edd0c4158e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Reynolds?= Date: Wed, 23 Nov 2011 13:43:04 -0300 Subject: Fixed errors in logic --- db-cleanup | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'db-cleanup') diff --git a/db-cleanup b/db-cleanup index b12e9c1..72790f1 100755 --- a/db-cleanup +++ b/db-cleanup @@ -28,8 +28,8 @@ trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR ${CLEANUP_DRYRUN} && EXTRAFLAGS+=" --dry-run" -for _repo in ${ARCHREPOS[@]}; do - for _arch in ${ARCHARCHES[@]}; do +for _repo in ${PKGREPOS[@]}; do + for _arch in ${ARCHES[@]}; do msg "Getting ${_repo}-${_arch} database" dbfile="${FTP_BASE}/${_repo}/os/${_arch}/${_repo}${DBEXT}" @@ -43,7 +43,7 @@ for _repo in ${ARCHREPOS[@]}; do bsdtar tf "${dbfile}" | \ cut -d'/' -f1 | \ sort -u | \ - sed "s|$|*|" >> /tmp/$0.$PID.filter + sed "s|$|*|" >> /tmp/$0.$$.filter done done @@ -54,7 +54,7 @@ for POOL in ${PKGPOOLS[@]} ${SRCPOOLS[@]}; do msg2 "${POOL}" rsync ${EXTRAFLAGS} -va --delete-excluded \ - --include-from="${dbfile}" \ + --include-from="/tmp/$0.$$.filter" \ --exclude="*" \ ${FTP_BASE}/${POOL}/ \ ${FTP_BASE}/${POOL}/ -- cgit v1.2.3-2-g168b From 7a2f916a360b16c3649622d9f04c6424aab8f32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Reynolds?= Date: Sat, 20 Oct 2012 16:25:07 -0300 Subject: Remove broken symlinks after cleanup --- db-cleanup | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'db-cleanup') diff --git a/db-cleanup b/db-cleanup index 72790f1..904c06e 100755 --- a/db-cleanup +++ b/db-cleanup @@ -60,4 +60,8 @@ for POOL in ${PKGPOOLS[@]} ${SRCPOOLS[@]}; do ${FTP_BASE}/${POOL}/ done +msg "Removing symlinks:" +find -L ${FTP_BASE}/ -type l +${CLEANUP_DRYRUN} || find -L ${FTP_BASE}/ -type l -delete + exit $? -- cgit v1.2.3-2-g168b From 6a093f1dc6bd5398115544dd229b520f9432e122 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 31 Dec 2013 15:49:06 -0500 Subject: use `readlink -e` on $0 --- db-cleanup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'db-cleanup') diff --git a/db-cleanup b/db-cleanup index 904c06e..c6e4f1c 100755 --- a/db-cleanup +++ b/db-cleanup @@ -15,9 +15,9 @@ trap_exit() { exit 1 } -source $(dirname $0)/config -source $(dirname $0)/local_config -source $(dirname $0)/libremessages +source "$(dirname "$(readlink -e "$0")")/config" +source "$(dirname "$(readlink -e "$0")")/local_config" +source "$(dirname "$(readlink -e "$0")")/libremessages" # From makepkg set -E -- cgit v1.2.3-2-g168b From 877eaef7357c5ca171e15de16ffce055da68af2f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 31 Dec 2013 16:06:19 -0500 Subject: remove unnecessary loadings of local_config --- db-cleanup | 1 - 1 file changed, 1 deletion(-) (limited to 'db-cleanup') diff --git a/db-cleanup b/db-cleanup index c6e4f1c..364f400 100755 --- a/db-cleanup +++ b/db-cleanup @@ -16,7 +16,6 @@ trap_exit() { } source "$(dirname "$(readlink -e "$0")")/config" -source "$(dirname "$(readlink -e "$0")")/local_config" source "$(dirname "$(readlink -e "$0")")/libremessages" # From makepkg -- cgit v1.2.3-2-g168b From 7e93af9ef087cd048dd42cef71328ec7f75e885c Mon Sep 17 00:00:00 2001 From: Parabola Date: Sun, 5 Jan 2014 04:21:24 +0000 Subject: fix use of $0 in db-cleanup --- db-cleanup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'db-cleanup') diff --git a/db-cleanup b/db-cleanup index 904c06e..841800b 100755 --- a/db-cleanup +++ b/db-cleanup @@ -43,7 +43,7 @@ for _repo in ${PKGREPOS[@]}; do bsdtar tf "${dbfile}" | \ cut -d'/' -f1 | \ sort -u | \ - sed "s|$|*|" >> /tmp/$0.$$.filter + sed "s|$|*|" >> /tmp/${0##*/}.$$.filter done done @@ -54,7 +54,7 @@ for POOL in ${PKGPOOLS[@]} ${SRCPOOLS[@]}; do msg2 "${POOL}" rsync ${EXTRAFLAGS} -va --delete-excluded \ - --include-from="/tmp/$0.$$.filter" \ + --include-from="/tmp/${0##*/}.$$.filter" \ --exclude="*" \ ${FTP_BASE}/${POOL}/ \ ${FTP_BASE}/${POOL}/ -- cgit v1.2.3-2-g168b