diff options
Diffstat (limited to 'purge.sh')
-rwxr-xr-x | purge.sh | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/purge.sh b/purge.sh new file mode 100755 index 0000000..3601bb5 --- /dev/null +++ b/purge.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +declare -A min +declare -A max + +for i in $* ; do + #fn=$(echo $i | awk -F \; '{print $1;}') + #vers=$(echo $i | awk -F \; '{print $2;}') + + fn=$(echo $i | cut -d \; -f 1) + vers=$(echo $i | cut -d \; -f 2) + + if [ -z "${min[$fn]}" ] ; then + min[$fn]=$vers + elif [ "${min[$fn]}" -gt $vers ] ; then + min[$fn]=$vers + fi + + if [ -z "${max[$fn]}" ] ; then + max[$fn]=$vers + elif [ "${max[$fn]}" -lt $vers ] ; then + max[$fn]=$vers + fi +done + +for i in "${!max[@]}" ; do + ma=${max[$i]} + mi=${min[$i]} + + if [ $ma -gt $mi ] ; then + f=$mi + while [ $f -lt $ma ] ; do + rm ${i}\;$f + f=$(expr $f + 1) + done + fi + + mv ${i}\;$ma $i +done |