Keep only 4 latest versions of each package SA-588
[git-tools-moved-to-github.git] / update-archive / symclean.sh
1 #!/bin/bash
2 # Get a list of package files that can be moved out
3
4 echo "Now in `pwd` going to $1"
5 cd $1
6 echo "Landed in  `pwd` "
7 echo "File count:"
8 ls *.deb | wc -l
9 # exit 9
10
11
12 KEEPGEN=4   # how many generations to keep of each package
13
14 KEEP="/tmp/packs.keep"
15 MOVE="/tmp/packs.move"
16 rm -f $KEEP
17 rm -f $MOVE
18
19 PRODS=`ls *.deb| cut -d'_' -f1 | sort -u`
20 for P in $PRODS
21 do
22    for V in `ls -rt ${P}_*.deb | tail -$KEEPGEN  | cut -d'_' -f2 `
23    do
24        echo ${P}_${V} >> $KEEP
25    done
26 done
27
28 ls *.deb | cut -d'_' -f1-2 | grep -v -f $KEEP > $MOVE
29
30 for M in `cat $MOVE`
31 do
32     echo "Removing"
33     ls ${M}_*
34     rm ${M}_*
35 done
36
37 # rm -f $KEEP
38 #rm -f $MOVE