2929fi
3030
3131# If using submodules, we need to read proper subhook root
32- if [[ -f " $git_root /.git" ]]; then
32+ if [[ -f " ${ git_root} /.git" ]]; then
3333 IFS=" : "
3434 while read -r name value
3535 do
36- if [[ $name == " gitdir" ]]; then
37- submodule_hookdir=$value
36+ if [[ " $name " == " gitdir" ]]; then
37+ submodule_hookdir=" $value "
3838 fi
39- done < " $git_root /.git"
39+ done < " ${ git_root} /.git"
4040 if [[ ! -z " $submodule_hookdir " ]]; then
41- subhook_root=" $git_root / $ submodule_hookdir /hooks/commit_hooks"
41+ subhook_root=" ${ git_root} / ${ submodule_hookdir} /hooks/commit_hooks"
4242 fi
4343fi
4444
4545# Decide if we want puppet-lint
46- CHECK_PUPPET_LINT=" enabled"
46+ CHECK_PUPPET_LINT=${CHECK_PUPPET_LINT :- " enabled" }
4747if [[ -e ${subhook_root} /config.cfg ]] ; then
4848 source " ${subhook_root} /config.cfg"
4949fi
@@ -57,13 +57,13 @@ SAVEIFS=$IFS
5757IFS=$( echo -en " \n\b" )
5858
5959if [ $CHECK_ALL ]; then
60- files_to_check=$( find $git_root -path $ git_root /.git -prune -o -print)
60+ files_to_check=$( find " $git_root " -path " ${ git_root} /.git" -prune -o -print)
6161else
6262 files_to_check=$( git diff --cached --name-only --diff-filter=ACM)
6363fi
6464
6565# On cygwin/windows, puppet is a symlink to native puppet install, which needs windows paths.
66- if [ " $OSTYPE " == " cygwin" ] && file -L $( which puppet) 2> /dev/null | grep -q ' DOS batch file' && type cygpath > /dev/null 2>&1 ; then
66+ if [[ " $OSTYPE " == " cygwin" ] ] && file -L $( which puppet) 2> /dev/null | grep -q ' DOS batch file' && type cygpath > /dev/null 2>&1 ; then
6767 USE_NATIVE=" YES"
6868fi
6969for changedfile in $files_to_check ; do
@@ -75,13 +75,13 @@ for changedfile in $files_to_check; do
7575 fi
7676 # check puppet manifest syntax
7777 if type puppet > /dev/null 2>&1 ; then
78- if [[ $( echo " $changedfile " | grep -q ' \.*\. epp$' ; echo $? ) -eq 0 ]] ; then
78+ if echo " $changedfile " | grep -iq ' \.epp$' ; then
7979 ${subhook_root} /puppet_epp_syntax_check.sh " $changedfile "
8080 RC=$?
8181 if [[ " $RC " -ne 0 ]]; then
8282 failures=$(( failures + 1 ))
8383 fi
84- elif [[ $( echo " $changedfile " | grep -q ' \.*\. pp$' ; echo $? ) -eq 0 ]] ; then
84+ elif echo " $changedfile " | grep -iq ' \.pp$' ; then
8585 ${subhook_root} /puppet_manifest_syntax_check.sh " $changedfile_native " " " " $USE_PUPPET_FUTURE_PARSER "
8686 RC=$?
8787 if [[ " $RC " -ne 0 ]]; then
@@ -95,7 +95,7 @@ for changedfile in $files_to_check; do
9595 if type ruby > /dev/null 2>&1 ; then
9696 # check erb (template file) syntax
9797 if type erb > /dev/null 2>&1 ; then
98- if [[ $( echo " $changedfile " | grep -q ' \.*. erb$' ; echo $? ) -eq 0 ]] ; then
98+ if echo " $changedfile " | grep -iq ' \.erb$' ; then
9999 ${subhook_root} /erb_template_syntax_check.sh " $changedfile "
100100 RC=$?
101101 if [[ " $RC " -ne 0 ]]; then
@@ -107,7 +107,7 @@ for changedfile in $files_to_check; do
107107 fi
108108
109109 # check hiera data (yaml/yml/eyaml/eyml) syntax
110- if [[ $( echo " $changedfile " | grep -q ' \.*. e\?ya\?ml$' ; echo $? ) -eq 0 ]] ; then
110+ if echo " $changedfile " | grep -iq ' \.e\?ya\?ml$' ; then
111111 ${subhook_root} /yaml_syntax_check.sh " $changedfile "
112112 RC=$?
113113 if [[ " $RC " -ne 0 ]]; then
@@ -116,7 +116,7 @@ for changedfile in $files_to_check; do
116116 fi
117117
118118 # check json (i.e. metadata.json) syntax
119- if [[ $( echo " $changedfile " | grep -q ' \.*. json$' ; echo $? ) -eq 0 ]] ; then
119+ if echo " $changedfile " | grep -iq ' \.json$' ; then
120120 ${subhook_root} /json_syntax_check.sh " $changedfile "
121121 RC=$?
122122 if [[ " $RC " -ne 0 ]]; then
@@ -130,12 +130,16 @@ for changedfile in $files_to_check; do
130130 # puppet manifest styleguide compliance
131131 if [[ " $CHECK_PUPPET_LINT " != " disabled" ]] ; then
132132 if type puppet-lint > /dev/null 2>&1 ; then
133- if [[ $( echo " $changedfile " | grep -q ' \.*\.pp$' ; echo $? ) -eq 0 ]]; then
133+ if echo " $changedfile " | grep -iq ' \.pp$' ; then
134+ if [[ " $failures " -eq 0 ]]; then
134135 ${subhook_root} /puppet_lint_checks.sh " $CHECK_PUPPET_LINT " " $changedfile "
135136 RC=$?
136137 if [[ " $RC " -ne 0 ]]; then
137138 failures=$(( failures + 1 ))
138139 fi
140+ else
141+ echo " Skipping puppet-lint check due to prior errors."
142+ fi
139143 fi
140144 else
141145 echo " puppet-lint not installed. Skipping puppet-lint tests..."
172176
173177# summary
174178if [[ " $failures " -ne 0 ]]; then
175- echo -e " $( tput setaf 1) Error: $failures subhooks failed. Please fix above errors.$( tput sgr0) "
179+ echo -e " $( tput setaf 1) Error: ${ failures} subhooks failed. Please fix above errors.$( tput sgr0) "
176180 exit 1
177181fi
178182
0 commit comments