#!/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