Last active
December 30, 2015 08:19
-
-
Save k-popov/7801645 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
M2DIR=~/.m2 | |
MAXAGE="864000" # 10 days in sec | |
NOW="`date +%s`" | |
MAXOLD="$(($NOW - $MAXAGE))" # files older than this will be removed. See further | |
# get list or artifact ID's prependede with group | |
find $M2DIR -iname "*.pom" \ | |
| xargs dirname | xargs dirname \ # dirname twice gives a directory 1 level up the version | |
| sort | uniq \ | |
| while read ARTIFACT; do | |
# get number of available versions | |
VERSIONS_NUM="`ls -1 ${ARTIFACT} | wc -l`" | |
# skip this artifact if only one version is present | |
test "$VERSIONS_NUM" -le 1 && continue | |
# if several versions found, remove all older than $MAXAGE from NOW leaving latest in place | |
for VERSION in `ls -t -1 ${ARTIFACT} | tail -n +2`; do | |
TARGET="$ARTIFACT/$VERSION" | |
MTIME="`stat --printf %Y $TARGET`" | |
test "$MTIME" -le "$MAXOLD" && echo "Removing $TARGET" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment