Want more features on Pastebin? Sign Up, it's FREE!
Guest

better puppet pre-commit hook

By: a guest on Aug 25th, 2012  |  syntax: Bash  |  size: 0.85 KB  |  views: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2. manifest_syntax() {
  3.     printf "Checking manifest\t$1: "
  4.     $(which puppet) parser validate $1 && printf "Syntax OK\n"
  5. }
  6.  
  7. lint_check() {
  8.     printf "Checking best practices\t$1: "
  9.     $(which puppet-lint) $1 && printf "Syntax OK\n"
  10. }
  11.  
  12. erb_syntax() {
  13.     printf "Checking erb\t\t$1: "
  14.     $(which erb) -x -T - $1 | $(which ruby) -c
  15. }
  16.  
  17. ruby_syntax() {
  18.     printf "Checking ruby\t\t$1: "
  19.     $(which ruby) -rpuppet $1 && printf "Syntax OK\n"
  20. }
  21.  
  22. for i in $(git diff HEAD  --name-only); do
  23.     # switch on file extension
  24.     case $( echo $i |awk -F. '{ print $NF }' ) in
  25.         pp)
  26.             manifest_syntax $i
  27.             lint_check $i
  28.         ;;
  29.         erb)
  30.             erb_syntax $i ;;
  31.         rb)
  32.             ruby_syntax $i ;;
  33.         *)
  34.             printf "$i is something I don't recognize... skipping\n" ;;
  35.     esac
  36. done
clone this paste RAW Paste Data