From 906480fae444bfc44070836963ca613e438f5abe Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 31 Aug 2017 16:08:11 +0200 Subject: bin/common-functions: remove_old_package_versions: remove older packages in not-newer repositories and not-older packages in newer repositories --- bin/common-functions | 60 +++++++++++++++++++++++++++++++++++++--------------- conf/default.conf | 16 ++++++++++---- 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/bin/common-functions b/bin/common-functions index b1fb9f0..fda2288 100755 --- a/bin/common-functions +++ b/bin/common-functions @@ -393,8 +393,8 @@ ls_master_mirror() { } # remove_old_package_versions $arch $repository $package_file -# removes all older versions of $package_file for architecture $arch in all -# repositories not-older than $repository +# removes all older (not-newer) versions of $package_file for architecture +# $arch in all repositories not-older (newer) than $repository remove_old_package_versions() { @@ -402,32 +402,47 @@ remove_old_package_versions() { local repository="$2" local package="$3" - local delete_repositories - local repo + # repositories in which older packages should be deleted + local delete_older_repositories + # repositories in which not-newer packages should be deleted + local delete_not_newer_repositories if echo "${standalone_package_repositories}" | \ - tr ' ' '\n' | \ grep -qxF "${repository}"; then - delete_repositories="${repository}" + delete_older_repositories="${repository}" + delete_not_newer_repositories='' elif echo "${staging_package_repositories}" | \ - tr ' ' '\n' | \ grep -qxF "${repository}"; then - delete_repositories="${staging_package_repositories}" + delete_older_repositories="${repository}" + delete_not_newer_repositories=$( + echo "${staging_package_repositories}" | \ + grep -vxF "${repository}" + ) || true elif echo "${testing_package_repositories}" | \ - tr ' ' '\n' | \ grep -qxF "${repository}"; then - delete_repositories="${staging_package_repositories} ${testing_package_repositories}" + delete_older_repositories=$( + printf '%s\n' "${staging_package_repositories}" "${repository}" + ) + delete_not_newer_repositories=$( + echo "${testing_package_repositories}" | \ + grep -vxF "${repository}" + ) || true elif echo "${stable_package_repositories}" | \ - tr ' ' '\n' | \ grep -qxF "${repository}"; then - delete_repositories="${staging_package_repositories} ${testing_package_repositories} ${stable_package_repositories}" + delete_older_repositories=$( + printf '%s\n' "${staging_package_repositories}" "${testing_package_repositories}" "${repository}" + ) + delete_not_newer_repositories=$( + echo "${stable_package_repositories}" | \ + grep -vxF "${repository}" + ) || true else @@ -441,22 +456,33 @@ remove_old_package_versions() { trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT { - for repo in ${delete_repositories}; do + for repo in ${delete_older_repositories}; do + echo "do: '${repo}'" >&2 + ls_master_mirror "${arch}/${repo}" | \ + sed ' + /\.pkg\.tar\.xz$/!d + s|-\([^-]\+-[^-]\+\)-\([^-]\+\)$| \1 \2| + /^'"$(str_to_regex "${package%-*-*-*}")"' /!d + s|^|2 '"${arch} ${repo}"' | + ' + done + for repo in ${delete_not_newer_repositories}; do + echo "dnn: '${repo}'" >&2 ls_master_mirror "${arch}/${repo}" | \ sed ' /\.pkg\.tar\.xz$/!d s|-\([^-]\+-[^-]\+\)-\([^-]\+\)$| \1 \2| /^'"$(str_to_regex "${package%-*-*-*}")"' /!d - s|^|1 '"${arch} ${repo}"' | + s|^|0 '"${arch} ${repo}"' | ' done echo "${package%-*}" | \ - sed 's|^.*-\([^-]\+-[^-]\+\)$|0 %cut% %it% %here% \1|' + sed 's|^.*-\([^-]\+-[^-]\+\)$|1 %cut% %it% %here% \1|' } | \ sort -k5V,5 -k1n,1 | \ sed -n ' - /^0 %cut% %it% %here% /q - s/^1 // + /^1 %cut% %it% %here% /q + s/^[02] // s/ \(\S\+\)$/-\1/ p ' > \ diff --git a/conf/default.conf b/conf/default.conf index 731f22c..fcaa39a 100755 --- a/conf/default.conf +++ b/conf/default.conf @@ -68,10 +68,18 @@ straws_that_might_repair_failing_builds=$( webserver_directory='/srv/http' # known package repositories -standalone_package_repositories='build-support gnome-unstable kde-unstable' -stable_package_repositories='community core extra' -testing_package_repositories='community-testing testing' -staging_package_repositories='community-staging staging' +standalone_package_repositories=$( + printf '%s\n' 'build-support' 'gnome-unstable' 'kde-unstable' +) +stable_package_repositories=$( + printf '%s\n' 'community' 'core' 'extra' +) +testing_package_repositories=$( + printf '%s\n' 'community-testing' 'testing' +) +staging_package_repositories=$( + printf '%s\n' 'community-staging' 'staging' +) # possibly pull in custom modifications -- cgit v1.2.3-70-g09d2