29
29
fi
30
30
31
31
# If using submodules, we need to read proper subhook root
32
- if [[ -f " $git_root /.git" ]]; then
32
+ if [[ -f " ${ git_root} /.git" ]]; then
33
33
IFS=" : "
34
34
while read -r name value
35
35
do
36
- if [[ $name == " gitdir" ]]; then
37
- submodule_hookdir=$value
36
+ if [[ " $name " == " gitdir" ]]; then
37
+ submodule_hookdir=" $value "
38
38
fi
39
- done < " $git_root /.git"
39
+ done < " ${ git_root} /.git"
40
40
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"
42
42
fi
43
43
fi
44
44
45
45
# Decide if we want puppet-lint
46
- CHECK_PUPPET_LINT=" enabled"
46
+ CHECK_PUPPET_LINT=${CHECK_PUPPET_LINT :- " enabled" }
47
47
if [[ -e ${subhook_root} /config.cfg ]] ; then
48
48
source " ${subhook_root} /config.cfg"
49
49
fi
@@ -57,13 +57,13 @@ SAVEIFS=$IFS
57
57
IFS=$( echo -en " \n\b" )
58
58
59
59
if [ $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)
61
61
else
62
62
files_to_check=$( git diff --cached --name-only --diff-filter=ACM)
63
63
fi
64
64
65
65
# 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
67
67
USE_NATIVE=" YES"
68
68
fi
69
69
for changedfile in $files_to_check ; do
@@ -75,13 +75,13 @@ for changedfile in $files_to_check; do
75
75
fi
76
76
# check puppet manifest syntax
77
77
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
79
79
${subhook_root} /puppet_epp_syntax_check.sh " $changedfile "
80
80
RC=$?
81
81
if [[ " $RC " -ne 0 ]]; then
82
82
failures=$(( failures + 1 ))
83
83
fi
84
- elif [[ $( echo " $changedfile " | grep -q ' \.*\. pp$' ; echo $? ) -eq 0 ]] ; then
84
+ elif echo " $changedfile " | grep -iq ' \.pp$' ; then
85
85
${subhook_root} /puppet_manifest_syntax_check.sh " $changedfile_native " " " " $USE_PUPPET_FUTURE_PARSER "
86
86
RC=$?
87
87
if [[ " $RC " -ne 0 ]]; then
@@ -95,7 +95,7 @@ for changedfile in $files_to_check; do
95
95
if type ruby > /dev/null 2>&1 ; then
96
96
# check erb (template file) syntax
97
97
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
99
99
${subhook_root} /erb_template_syntax_check.sh " $changedfile "
100
100
RC=$?
101
101
if [[ " $RC " -ne 0 ]]; then
@@ -107,7 +107,7 @@ for changedfile in $files_to_check; do
107
107
fi
108
108
109
109
# 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
111
111
${subhook_root} /yaml_syntax_check.sh " $changedfile "
112
112
RC=$?
113
113
if [[ " $RC " -ne 0 ]]; then
@@ -116,7 +116,7 @@ for changedfile in $files_to_check; do
116
116
fi
117
117
118
118
# 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
120
120
${subhook_root} /json_syntax_check.sh " $changedfile "
121
121
RC=$?
122
122
if [[ " $RC " -ne 0 ]]; then
@@ -130,12 +130,16 @@ for changedfile in $files_to_check; do
130
130
# puppet manifest styleguide compliance
131
131
if [[ " $CHECK_PUPPET_LINT " != " disabled" ]] ; then
132
132
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
134
135
${subhook_root} /puppet_lint_checks.sh " $CHECK_PUPPET_LINT " " $changedfile "
135
136
RC=$?
136
137
if [[ " $RC " -ne 0 ]]; then
137
138
failures=$(( failures + 1 ))
138
139
fi
140
+ else
141
+ echo " Skipping puppet-lint check due to prior errors."
142
+ fi
139
143
fi
140
144
else
141
145
echo " puppet-lint not installed. Skipping puppet-lint tests..."
172
176
173
177
# summary
174
178
if [[ " $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) "
176
180
exit 1
177
181
fi
178
182
0 commit comments