automatic cleanup of outdated packets in /var/cache/fou4s/packages/*
Lars Ellenberg <[email protected]> Sun, 11 Jul 2004 13:23:27 +0200
| Newsgroups | gmane.linux.suse.fou4s.devel |
|---|---|
| Message-ID | <[email protected]> |
maybe the attached script is of some use to some of you. what it does: for one particular ARCH and VERSION, scanns all directories in /var/cache/fou4s/*/$ARCH/update/$VERSION/rpm/* for files named "*.rpm", sort by name, version, release, and throws away everything which is not the latest. [currently this is rm -i, so you have to comfirm it] this even works "cross server", so if you downloaded once apache2-2.0.48-9 from SomeServer, and it therefore ended up in .../SomeServer/*/*, and later you changed servers, and apache2-2.0.48-128 ended up in .../OtherServer/*/*, the -9 thing will still be recognized as outdated, and removed. hope this helps to recover some disc space :) Lars Ellenberg example run: --------------- latest is: apache2-2.0.48-128.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : apache2-2.0.48-124.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? --------------- latest is: cups-client-1.1.19-91.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : cups-client-1.1.19-85.i586.patch.rpm [./ftp-suse.uni-freiburg.de/i386/update/9.0/rpm/i586] ? --------------- latest is: cvs-1.11.6-83.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : cvs-1.11.6-81.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? delete : cvs-1.11.6-79.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? delete : cvs-1.11.6-73.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: dhcp-server-3.0.1rc12-71.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : dhcp-server-3.0.1rc12-70.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? --------------- latest is: gaim-0.67-67.i586.patch.rpm [./ftp-suse.uni-freiburg.de/i386/update/9.0/rpm/i586] delete : gaim-0.67-65.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: gnome-filesystem-0.1-117.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] delete : gnome-filesystem-0.1-80.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: k_athlon-2.4.21-202.i586.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : k_athlon-2.4.21-166.i586.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: k_deflt-2.4.21-231.i586.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : k_deflt-2.4.21-215.i586.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? delete : k_deflt-2.4.21-202.i586.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? --------------- latest is: kdelibs3-3.1.4-51.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : kdelibs3-3.1.4-49.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? delete : kdelibs3-3.1.4-38.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: kernel-source-2.4.21-231.i586.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : kernel-source-2.4.21-215.i586.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? delete : kernel-source-2.4.21-202.i586.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? delete : kernel-source-2.4.21-166.i586.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: kopete-0.7.3-8.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] delete : kopete-0.7.3-1.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: mc-4.6.0-327.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : mc-4.6.0-210.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: neon-0.23.9-113.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : neon-0.23.9-110.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? --------------- latest is: openssh-3.7.1p2-113.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : openssh-3.7.1p2-18.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: openssl-0.9.7b-133.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : openssl-0.9.7b-71.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: openssl-devel-0.9.7b-133.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : openssl-devel-0.9.7b-71.i586.patch.rpm [./ftp-suse.uni-freiburg.de/i386/update/9.0/rpm/i586] ? --------------- latest is: sharutils-4.2c-718.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : sharutils-4.2c-632.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? --------------- latest is: subversion-0.27.0-209.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : subversion-0.27.0-207.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? --------------- latest is: tcpdump-3.7.2-85.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : tcpdump-3.7.2-82.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: XFree86-4.3.0.1-46.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : XFree86-4.3.0.1-43.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? delete : XFree86-4.3.0.1-29.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: XFree86-server-4.3.0.1-46.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : XFree86-server-4.3.0.1-29.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ? --------------- latest is: xine-lib-0.99.rc0a-115.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : xine-lib-0.99.rc0a-113.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] ? --------------- latest is: yast2-packagemanager-2.8.36-1.i586.patch.rpm [./ftp.gwdg.de/i386/update/9.0/rpm/i586] delete : yast2-packagemanager-2.8.35-0.i586.patch.rpm [./ftp-suse.uni-freiburg.de_/i386/update/9.0/rpm/i586] ?
fou4s-cleanup
(text/plain, 2.5 KB)
BASE_DIR=/var/cache/fou4s/packages
ARCH=i386
VER=9.0
cd $BASE_DIR
CLEAN_DIRS=`find ./*/$ARCH/update/$VER/rpm/* -type d -maxdepth 0`
#
# helper functions
#
sort_by_version_release() {
# note that I _expect_ release to be numeric...
# so if you have releases that contain alphas, this may not work.
# anything/ name- version- release extension
sed -ne '
s,^\(.*\)/\([^/]*-\)\([^-]\+-\)\([0-9]\+\)\(\.[^-]*\)$,\1|\2|\
\3\
|\4|\5,p' \
| sed -ne '
1~3h ; # hold it
; # insert space separators around version numbers
2~3{s/\([0-9]\+\)/ \1 /g;H;}
; # and print it
3~3{H;x;s/'$'\\\n''//g;p;}' \
| sort -t "|" -k 4,4nr |
# the even fields are numeric parts of the version/release
# the odd fields are non numeric, but should be used for
# sorting, too, since it could be 2.05b, 0.9.7c etc...
# non existing fields are ignored, I truncate at 25 ;)
sort -t " " -s \
-k2,2nr -k3,3r -k4,4nr -k5,5r -k6,6nr -k7,7r -k8,8nr -k9,9r \
-k10,10nr -k11,11r -k12,12nr -k13,13r -k14,14nr -k15,15r \
-k16,16nr -k17,17r -k18,18nr -k19,19r -k20,20nr -k21,21r -k22,22nr \
-k23,23r -k24,24nr -k25,25r \
| sort -t "|" -s -k 2,2 \
| sed 's,|,/,; s/[ |]//g;'
}
split_dir_name_version_extension() {
sed -ne 's,^\(.*\)/\([^/]*\)-\([^-]*\)-\([^-.]*\).\(.*\)$,\1\t\2\t\3\t\4\t\5,p'
}
list_and_delete_outdated()
{
latext_dir='';
latest_name='';
latest_ext='';
latest_full='';
current_full='';
did_header=false
while read dir name version release ext ; do
current_full=$name-$version-$release.$ext
if [[ $name == $latest_name && $ext == $latest_ext ]]; then
# some paranoia checks
if [[ $dir/$current_full -nt $latest_dir/$latest_full ]] ; then
echo " -- "
echo "don't know what to do:"
ls -l $dir/$current_full $latest_dir/$latest_full
echo " -- "
# maybe double check version and release, and ...
else
if ! $did_header ; then
echo "---------------"
echo -e "latest is: $latest_full\t[$latest_dir]"
did_header=true
fi
# once you are convinced that this doe work,
# just remove unconditionally...
# rm "$dir/$current_full"
echo -e "delete : $current_full\t[$dir] ?"
# confirmation from stderr, since stdin is the file names ...
rm -i "$dir/$current_full" <&2
fi
else
did_header=false
latest_dir=$dir
latest_name=$name
latest_ext=$ext
latest_full=$current_full
fi
done
}
#
# MAIN program
#
find $CLEAN_DIRS -type f -name "*.rpm" |
sort_by_version_release |
split_dir_name_version_extension |
list_and_delete_outdated