[arch-general] Script for finding and "moving" older duplicate packages from /var/cache/pacman/pkg
Patrick Brisbin
pbrisbin at gmail.com
Tue Aug 25 14:32:09 UTC 2009
A while back i wrote a similar script which extracts the .PKGINFO file
from each package in one's cache. slow, but I think this is a more
accurate way to compare versions.
as-is, it will cp $N versions back from installed packages (inclusive)
to $WD/saveme, where N and WD are defined in the script.
i use it to save the N version, clean out my cache, then move them back.
but i think you could easily modify it to suit your usage case
instead of moving N versions to saveme you could echo the filename into
a saveme.lst, then mv anything not in saveme.lst to your oldpkg
directory.
or you could just take my little .PKGINFO / awk trickery and merge it
into your script...
or you could just ignore me and go with mod times :).
anyways, more info is always better, right? i've attached the script for
you to peruse.
thanks,
pat
On 08/25/09 at 12:51am, David C. Rankin wrote:
> On Monday 24 August 2009 11:51:45 pm David C. Rankin wrote:
> >
> <snip>
> > The script for finding and moving older duplicate packages is named fduppkg and is fairly self-explanitory. Running without arguments gives the options:
> >
>
> BASH never fails to amaze me, 3116 element array to handle the packages, and BASH never batted an eye. It just kept on trucking....
>
> [00:41 archangel:/home/david/scripts/file] # ./fdup-archpkg -v
>
> <big snip>
>
> ${SARRAY[3114]} zenity-2.26.0-1-x86_64.pkg.tar.gz
> Search filename: zenity
> Search Architecture: x86_64
> Duplicate filename: zenity
> Duplicate Architecture: x86_64
> Keeping: /var/cache/pacman/pkg/zenity-2.26.0-2-x86_64.pkg.tar.gz
> Duplicate found: 1
> Search filename: zenity
> Search Architecture: x86_64
> Duplicate filename: zenity
> Duplicate Architecture: x86_64
> `/var/cache/pacman/pkg/zenity-2.26.0-1-x86_64.pkg.tar.gz' -> `/home/backup/pkg-old/zenity-2.26.0-1-x86_64.pkg.tar.gz'
> removed `/var/cache/pacman/pkg/zenity-2.26.0-1-x86_64.pkg.tar.gz'
> Duplicate found: 2
>
> ${SARRAY[3116]} zip-3.0-1-x86_64.pkg.tar.gz
> Search filename: zip
> Search Architecture: x86_64
> Duplicate filename: zip
> Duplicate Architecture: x86_64
> Keeping: /var/cache/pacman/pkg/zip-3.0-1-x86_64.pkg.tar.gz
> Duplicate found: 1
>
> Done!
>
> [00:43 archangel:/home/david/scripts/file] # du -hcs /var/cache/pacman/pkg/
> 3.0G /var/cache/pacman/pkg/
> 3.0G total
> [00:48 archangel:/home/david/scripts/file] # du -hcs /home/backup/pkg-old/
> 5.2G /home/backup/pkg-old/
> 5.2G total
>
> There's an extra 5.2G back ;-)
>
> --
> David C. Rankin, J.D.,P.E.
> Rankin Law Firm, PLLC
> 510 Ochiltree Street
> Nacogdoches, Texas 75961
> Telephone: (936) 715-9333
> Facsimile: (936) 715-9339
> www.rankinlawfirm.com
--
patrick brisbin
-------------- next part --------------
#!/bin/bash
#
# pbrisbin 2009
#
###
N=3 # how may versions to keep -- includes installed
PD="/var/cache/pacman/pkg"
WD="/tmp/pacclean"
rm -rf $WD
mkdir -p $WD/saveme
LC_ALL="C"
pushd $WD &>/dev/null || exit 1
for package in $(find $PD -name *.pkg.tar.gz | sort -r); do
gunzip < $package | tar -xf - .PKGINFO || exit 1
file="$package"
name="$(awk '/^pkgname/ {print $3}' .PKGINFO)"
vers="$(awk '/^pkgver/ {print $3}' .PKGINFO)"
echo "$name $vers $file" >> $WD/all.lst
done
popd &>/dev/null || exit 1
pacman -Qq | while read pack; do
grep -m $N ^$pack\ $WD/all.lst | awk '{print $3}' | while read file; do
cp -av $file $WD/saveme/
done
done
echo "up to $N versions of each installed package are now in $WD/saveme"
echo "please verify everything you want is there before clearing your cache"
exit 0
More information about the arch-general
mailing list