From 58486e5ef83ac76bc02a30e76726354a3bb9d278 Mon Sep 17 00:00:00 2001 From: Marcelo Leitner Date: Fri, 15 Jun 2007 19:35:49 +0000 Subject: - Added the script that will be executed on n3 in order to clean iurt cache. --- iurt_cache_cleaner.sh | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100755 iurt_cache_cleaner.sh diff --git a/iurt_cache_cleaner.sh b/iurt_cache_cleaner.sh new file mode 100755 index 0000000..1830b35 --- /dev/null +++ b/iurt_cache_cleaner.sh @@ -0,0 +1,117 @@ +#!/bin/bash +# +# Marcelo Ricardo Leitner - Properly clean Iurt cache pool - 20070615 +# + +# Cache topdir +TOPDIR=/export/home/iurt_cache/ + +# Official distros topdir +OFFICIAL_DIR=/mnt/BIG/dis/ + +# Maximum number of days a package is allowed to be in the cache +AGE=4 + +# Email to be notified about wrong uploads +MAILTO=distrib-admin@mandrivalinux.org + + +# +# Remove all packages generated by a given .src.rpm +# +function clean_package() { + distro="$1" + section="$2" + srpm="$3" + + echo -e "Cleaning all packages generated by\n $srpm." + find "$TOPDIR/$distro/$section" -name '*.rpm' ! -name '*.src.rpm' |\ + xargs rpm -qp --qf '%{SOURCERPM} %{name}-%{version}-%{release}.%{arch}.rpm\n' |\ + sed -n "s@^$srpm @$TOPDIR/$distro/$section/@p" |\ + xargs rm -fv "$TOPDIR/$distro/$section/$srpm" +} + +# +# Cleans a released package +# +function clean() { + distro="$1" + section="$2" + srpm="$3" + + echo "Package released. We can remove it now." + clean_package "$distro" "$section" "$srpm" +} + +# +# Cleans an aged package +# +function age_timeout() { + distro="$1" + section="$2" + srpm="$3" + + echo "Package expired. We can remove it now." + clean_package "$distro" "$section" "$srpm" +} + +# +# Send a warn about packages that goes to wrong sections. +# +function wrong_section() { + distro="$1" + section="$2" + srpm="$3" + hits="$4" + + wrong_section=$(echo "$hits" | sed "s@$OFFICIAL_DIR/$distro/SRPMS/@@;s@/$srpm@@") + + echo "Package uploaded to a wrong section!" + echo "It went to $wrong_section while should have hit $section!" + mail -s "Package $srpm uploaded to section for $distro" $MAILTO <<_EOF_ +Distro: $distro +Package: $srpm +Wanted section: $section +Final section: $wrong_section + +It happened again! + +I'm holding it on the cache probably for more $AGE days. +_EOF_ +} + +# +# Search for the .src.rpm's +# +ls "$TOPDIR" |\ +while read distro; do + find -L "$TOPDIR/$distro" -type f -name *.src.rpm |\ + sed "s@$TOPDIR/$distro/@@;s@/\([^/]\+\)\$@ \1@" |\ + while read section srpm; do + echo + echo "Checking $distro/$section/$srpm" + + # Check if the package was released + if [ -e "$OFFICIAL_DIR/$distro/SRPMS/$section/$srpm" ]; then + clean "$distro" "$section" "$srpm" + continue + fi + + # Check for age timeout + z=$(find "$OFFICIAL_DIR/$distro/SRPMS/$section/$srpm" -ctime +$AGE -name "$srpm" 2> /dev/null) + if [ -n "$z" ]; then + age_timeout "$distro" "$section" "$srpm" + continue + fi + + # Check for wrong section + z=$(find "$OFFICIAL_DIR/$distro/SRPMS" -type f -name "$srpm") + if [ -n "$z" ]; then + wrong_section "$distro" "$section" "$srpm" "$z" + continue + fi + + # Package should remain on cache + echo "Package should remain on cache." + done +done -- cgit v1.2.1