Created
October 4, 2013 10:25
-
-
Save vStone/6823921 to your computer and use it in GitHub Desktop.
Cleanup old jenkins (plugin) packages
This file contains 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
green='\033[0;32m'; red='\033[0;31m'; | |
reset='\033[0m'; | |
## Keep the haltest # number of versions for each plugin. | |
KEEP_PLUGINS=2 | |
echo "Begin processing..." | |
count=$( ls *.rpm | grep -o "jenkins-plugin-[a-z]\+[0-9a-z-]*[0-9a-z]\+-" | sort | uniq | wc -l ) | |
i=0 | |
while read plugin; do | |
let i++ | |
echo "[ $i/$count ] $plugin" | |
versions=$( ls ${plugin}[0-9]*.rpm | wc -l ) | |
if [ $versions -gt $KEEP_PLUGINS ]; then | |
echo "Plugin: $plugin (Count: $versions)"; | |
remove=( ` ls ${plugin}[0-9]*.rpm | sort -g -t"." -k2,3 | head -n -2 ` ) | |
keep=( ` ls ${plugin}[0-9]*.rpm | sort -g -t"." -k2,3 | tail -n 2 ` ) | |
echo -e "+++ ${green}${keep[@]}${reset}" | |
echo -e "--- ${red}${remove[@]}${reset}" | |
rm "${remove[@]}" | |
fi; | |
done < <( ls *.rpm | grep -o "jenkins-plugin-[a-z]\+[0-9a-z-]*[0-9a-z]\+-" | sort | uniq ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment