diff options
author | Marcelo Leitner <mrl@mandriva.com> | 2007-06-15 19:35:49 +0000 |
---|---|---|
committer | Marcelo Leitner <mrl@mandriva.com> | 2007-06-15 19:35:49 +0000 |
commit | 58486e5ef83ac76bc02a30e76726354a3bb9d278 (patch) | |
tree | 7018950f3f3189c6d149e5cd56b778f558c1c9e1 /iurt_cache_cleaner.sh | |
parent | 3e575f117c3aa90db6947d7dead9a64a6058d6d0 (diff) | |
download | iurt-58486e5ef83ac76bc02a30e76726354a3bb9d278.tar iurt-58486e5ef83ac76bc02a30e76726354a3bb9d278.tar.gz iurt-58486e5ef83ac76bc02a30e76726354a3bb9d278.tar.bz2 iurt-58486e5ef83ac76bc02a30e76726354a3bb9d278.tar.xz iurt-58486e5ef83ac76bc02a30e76726354a3bb9d278.zip |
- Added the script that will be executed on n3 in order to clean iurt cache.
Diffstat (limited to 'iurt_cache_cleaner.sh')
-rwxr-xr-x | iurt_cache_cleaner.sh | 117 |
1 files changed, 117 insertions, 0 deletions
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 |