@@ -35,13 +35,13 @@ PROJECT_ROOT="$(cd "$SCRIPT_DIR" && realpath "$(git rev-parse --show-toplevel)")
35
35
36
36
# pushd is a silent alternative to the real pushd shell command.
37
37
pushd () {
38
- command pushd " $@ " > /dev/null
38
+ command pushd " $@ " > /dev/null || error " Could not pushd to ' $* ' "
39
39
}
40
40
41
41
# popd is a silent alternative to the real popd shell command.
42
42
# shellcheck disable=SC2120
43
43
popd () {
44
- command popd " $@ " > /dev/null
44
+ command popd > /dev/null || error " Could not restore directory with popd "
45
45
}
46
46
47
47
# cdself changes directory to the directory of the current script. This should
@@ -116,51 +116,62 @@ isdarwin() {
116
116
[[ " ${OSTYPE:- darwin} " == * darwin* ]]
117
117
}
118
118
119
- libsh_bad_dependencies=0
119
+ # We don't need to check dependencies more than once per script, but some
120
+ # scripts call other scripts that also `source lib.sh`, so we set an environment
121
+ # variable after successfully checking dependencies once.
122
+ if [[ " ${CODER_LIBSH_NO_CHECK_DEPENDENCIES:- } " != * t* ]]; then
123
+ libsh_bad_dependencies=0
124
+
125
+ if (( BASH_VERSINFO[0 ] < 4 )) ; then
126
+ libsh_bad_dependencies=1
127
+ log " ERROR: You need at least bash 4.0 to run the scripts in the Coder repo."
128
+ if isdarwin; then
129
+ log " On darwin:"
130
+ log " - brew install bash"
131
+ log " - Restart your terminal"
132
+ fi
133
+ log
134
+ fi
120
135
121
- if (( BASH_VERSINFO[0 ] < 4 )) ; then
122
- libsh_bad_dependencies=1
123
- log " ERROR: You need at least bash 4.0 to run the scripts in the Coder repo."
124
- if isdarwin; then
125
- log " On darwin:"
126
- log " - brew install bash"
127
- log " - Restart your terminal"
136
+ # BSD getopt (which is installed by default on Macs) is not supported.
137
+ if [[ " $( getopt --version) " == * --* ]]; then
138
+ libsh_bad_dependencies=1
139
+ log " ERROR: You need GNU getopt to run the scripts in the Coder repo."
140
+ if isdarwin; then
141
+ log " On darwin:"
142
+ log " - brew install gnu-getopt"
143
+ # shellcheck disable=SC2016
144
+ log ' - Add "$(brew --prefix)/opt/gnu-getopt/bin" to your PATH'
145
+ log " - Restart your terminal"
146
+ fi
147
+ log
128
148
fi
129
- log
130
- fi
131
149
132
- # BSD getopt (which is installed by default on Macs) is not supported.
133
- if [[ " $( getopt --version) " == * --* ]]; then
134
- libsh_bad_dependencies=1
135
- log " ERROR: You need GNU getopt to run the scripts in the Coder repo."
136
- if isdarwin; then
137
- log " On darwin:"
138
- log " - brew install gnu-getopt"
139
- # shellcheck disable=SC2016
140
- log ' - Add "$(brew --prefix)/opt/gnu-getopt/bin" to your PATH'
141
- log " - Restart your terminal"
150
+ # The bash scripts don't call Make directly, but we want to make (ha ha)
151
+ # sure that make supports the features the repo uses. Notably, Macs have an
152
+ # old version of Make installed out of the box that doesn't support new
153
+ # features like ONESHELL.
154
+ #
155
+ # Piping commands directly into `head -n1` may result in ERRPIPE errors, so
156
+ # we capture the version output first before
157
+ make_version_raw=" $( make --version 2> /dev/null) "
158
+ make_version=" $( echo " $make_version_raw " | head -n1 | grep -oE ' ([[:digit:]]+\.){1,2}[[:digit:]]+' ) "
159
+ if [ " ${make_version// .*/ } " -lt 4 ]; then
160
+ libsh_bad_dependencies=1
161
+ log " ERROR: You need at least make 4.0 to run the scripts in the Coder repo."
162
+ if isdarwin; then
163
+ log " On darwin:"
164
+ log " - brew install make"
165
+ # shellcheck disable=SC2016
166
+ log ' - Add "$(brew --prefix)/opt/make/libexec/gnubin" to your PATH (you should Google this first)'
167
+ log " - Restart your terminal"
168
+ fi
169
+ log
142
170
fi
143
- log
144
- fi
145
171
146
- # The bash scripts don't call Make directly, but we want to make (ha ha) sure
147
- # that make supports the features the repo uses. Notably, Macs have an old
148
- # version of Make installed out of the box that doesn't support new features
149
- # like ONESHELL.
150
- make_version=" $( make --version 2> /dev/null | head -n1 | grep -oE ' ([[:digit:]]+\.){1,2}[[:digit:]]+' ) "
151
- if [ " ${make_version// .*/ } " -lt 4 ]; then
152
- libsh_bad_dependencies=1
153
- log " ERROR: You need at least make 4.0 to run the scripts in the Coder repo."
154
- if isdarwin; then
155
- log " On darwin:"
156
- log " - brew install make"
157
- # shellcheck disable=SC2016
158
- log ' - Add "$(brew --prefix)/opt/make/libexec/gnubin" to your PATH (you should Google this first)'
159
- log " - Restart your terminal"
172
+ if [[ " $libsh_bad_dependencies " == 1 ]]; then
173
+ error " Invalid dependencies, see above for more details."
160
174
fi
161
- log
162
- fi
163
175
164
- if [[ " $libsh_bad_dependencies " == 1 ]]; then
165
- error " Invalid dependencies, see above for more details."
176
+ export CODER_LIBSH_NO_CHECK_DEPENDENCIES=true
166
177
fi
0 commit comments