https://github.com/wikimedia/operations-puppet
Raw File
Tip revision: 40346945c72c45e12bf704e1a5eb09674f171fba authored by andrewbogott on 04 February 2015, 18:59:11 UTC
Give James Douglas deployment rights.
Tip revision: 4034694
linter
#!/bin/bash

usage ()
{
  echo "${0} -- linting puppet files"
  echo ''
  echo '        * Without an argument it lints mod files in "git status"'
  echo '        * $1 can also be a path directive to find .pp files under'
  echo '        * $1 as "site" lints site.pp explicitly.'
  echo ''
  exit
}

bold=`/usr/bin/tput -T xterm-256color setaf bold`
normal=`/usr/bin/tput -T xterm-256color setaf sgr0`

which puppet-lint 2>&1 >/dev/null || {
  echo "puppet-lint not installed.";
  if [ "$1" = "-h" ]; then exit 0;
  else usage; exit 1; fi;
}

if [ "$1" == "-h" ]
  then
    usage
    exit 0
fi

if [ "$1" == "site" ]
  then
    pfiles="manifests/site.pp"
elif [ "$#" -gt 0 ]
  then
    pfiles=`find ${1}/* | grep .pp`
else
  pfiles=`git status | grep modified | awk '{print $3}'`
fi

if [ ${#pfiles[@]} -eq 0 ]; then
  echo "No files found to lint"
fi

linter () {
  tmp=`mktemp -u /tmp/%s.XXXX`
  for file in ${@}
    do
      puppet-lint $file > $tmp
      if [ -s $tmp ]
        then
          echo "${bold}${file}${normal}"
          grep --color -E '^|WARNING|ERROR' $tmp
          printf '%0.1s' "-"{1..60}; echo ""
      fi
    rm $tmp
  done
}

linter $pfiles
back to top