Skip to content

Instantly share code, notes, and snippets.

@mvisonneau
Created June 24, 2015 14:20
Show Gist options
  • Save mvisonneau/43616468a51a27c1cc4e to your computer and use it in GitHub Desktop.
Save mvisonneau/43616468a51a27c1cc4e to your computer and use it in GitHub Desktop.
Puppetfile version checker
#!/bin/bash
###########
OK='\033[0;32m'
NOK='\033[0;31m'
NC='\033[0m'
vercomp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 0
fi
done
return 0
}
grep -v "^#" $1 | grep '^mod' | while read i; do
version=`echo $i | cut -d',' -f2 | sed -e 's/^ //' -e 's/^"//' -e 's/"$//'`;
if [ ! -z "$version" ]; then
module=`echo $i | cut -d'"' -f2 | sed -e "s/\//-/g"` ;
latest_version=`curl https://forgeapi.puppetlabs.com:443/v3/modules/$module 2>/dev/null | grep version | head -n 1 | cut -d'"' -f4`
if vercomp $version $latest_version ; then
printf "${NOK}NOK${NC} - ${module} |${version}-${latest_version}|\n";
else
printf "${OK}OK${NC} - ${module} |${version}-${latest_version}|\n";
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment