1
- # /usr/bin/env bash
1
+ #! /usr/bin/env bash
2
2
#
3
3
# windows-install.sh
4
4
#
@@ -109,18 +109,19 @@ trap cleanup_before_exit EXIT # The signal is specified here. Could be SIGINT, S
109
109
# ## Validation (decide what's required for running your script and error out)
110
110
# ####################################################################
111
111
112
- [ -z " ${LOG_LEVEL:- } " ] && emergency " Cannot continue without LOG_LEVEL. "
112
+ [[ -z " ${LOG_LEVEL:- } " ] ] && emergency " Cannot continue without LOG_LEVEL. "
113
113
114
114
# shellcheck disable=SC2154
115
- if [[ " ${arg_d} " == " ${__flag_present} " ]]; then
115
+ if [[ " ${arg_d} " == " ${__flag_present} " ]]; then
116
116
print_debug_only=7
117
- if [ " $(( LOG_LEVEL < print_debug_only )) " -ne 0 ]; then
117
+ if [[ " $(( LOG_LEVEL < print_debug_only )) " -ne 0 ] ]; then
118
118
debug " Supressing info and debug messages: one of {-l, -v, -P, -U, -V, -D} present."
119
119
suppress_info_debug_messages
120
120
fi
121
121
fi
122
122
123
123
# Get linux_distribution name
124
+ # shellcheck disable=SC2154
124
125
{
125
126
info " __file: ${__file} "
126
127
info " __dir: ${__dir} "
@@ -144,7 +145,8 @@ info "-V (--version-number): ${arg_V}"
144
145
145
146
# __________ Process command-line arguments and environment variables _____________
146
147
147
- export this_script=" $( basename " $0 " ) "
148
+ this_script=" $( basename " ${0} " ) "
149
+ export this_script
148
150
debug " this_script=\" ${this_script} \" "
149
151
150
152
export install_prefix=" ${arg_i%/:- ${PWD} / prerequisites/ installations} "
@@ -153,17 +155,9 @@ info "install_prefix=\"${install_prefix}\""
153
155
export num_threads=" ${arg_j} "
154
156
info " num_threads=\" ${arg_j} \" "
155
157
156
- set_opencoarrays_version ()
157
- {
158
- cmake_project_line=" $( grep project " ${OPENCOARRAYS_SRC_DIR} /CMakeLists.txt" | grep VERSION) "
159
- text_after_version_keyword=" ${cmake_project_line##* VERSION} "
160
- text_before_language_keyword=" ${text_after_version_keyword%% LANGUAGES* } "
161
- opencoarrays_version=$text_before_language_keyword
162
- export opencoarrays_version=" ${opencoarrays_version// [[:space:]]/ } "
163
- }
164
- set_opencoarrays_version
158
+ opencoarrays_version=$( sed -n ' /[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{1,\}/{s/^\([^.]*\)\([0-9]\{1,\}\(\.[0-9]\{1,\}\)\{1,\}\)\(.*\)/\2/p;q;}' " ${OPENCOARRAYS_SRC_DIR%/ } /.VERSION" )
165
159
166
- export build_path=" ${OPENCOARRAYS_SRC_DIR%/ } " /prerequisites/builds/opencoarrays/$opencoarrays_version
160
+ export build_path=" ${OPENCOARRAYS_SRC_DIR%/ } " /prerequisites/builds/opencoarrays/${ opencoarrays_version}
167
161
info " build_path=\" ${build_path} \" "
168
162
169
163
export CMAKE=" ${arg_m:- cmake} "
@@ -173,7 +167,7 @@ verify_this_is_ubuntu()
173
167
if [[ ${__os} != " Linux" ]]; then
174
168
emergency " ${__os} not supported: this script is intended for use in Windows Subsystem for Linux "
175
169
fi
176
- linux_standard_base_i=` lsb_release -i`
170
+ linux_standard_base_i=$( lsb_release -i)
177
171
untrimmed_name=${linux_standard_base_i##* Distributor ID: }
178
172
linux_distribution=" ${untrimmed_name// [[:space:]]/ } "
179
173
info " Linux distribution: ${linux_distribution} "
@@ -188,16 +182,16 @@ verify_this_is_ubuntu
188
182
# Ubuntu 16.04 apt-get installs gfortran 5.4.0 or later, which is acceptable for many uses of OpenCoarrays
189
183
verify_acceptable_release_number ()
190
184
{
191
- linux_standard_base_r=` lsb_release -r`
185
+ linux_standard_base_r=$( lsb_release -r)
192
186
untrimmed_name=${linux_standard_base_r##* Release: }
193
187
release_number=" ${untrimmed_name// [[:space:]]/ } "
194
188
major_release=" ${release_number%% .* } "
195
189
minor_release=" ${release_number##* .} "
196
190
info " Release: ${major_release} .${minor_release} "
197
- if [[ $major_release -lt 16 ]]; then
191
+ if [[ ${ major_release} -lt 16 ]]; then
198
192
emergency " Please upgrade to Windows Subsystem for Linux (WSL) Ubuntu 16.04 or later."
199
- elif [[ $major_release -eq 16 ]]; then
200
- if [[ $minor_release -lt " 04" ]]; then
193
+ elif [[ ${ major_release} -eq 16 ]]; then
194
+ if [[ ${ minor_release} -lt " 04" ]]; then
201
195
emergency " Please upgrade to Windows Subsystem for Linux (WSL) Ubuntu 16.04 or later."
202
196
fi
203
197
fi
@@ -206,7 +200,7 @@ verify_acceptable_release_number
206
200
207
201
if [[ " ${arg_V} " == " ${__flag_present} " ]]; then
208
202
# Print just the version number
209
- info " $opencoarrays_version "
203
+ info " ${ opencoarrays_version} "
210
204
211
205
elif [[ " ${arg_v} " == " ${__flag_present} " ]]; then
212
206
@@ -227,19 +221,19 @@ else
227
221
export FC=${arg_f:- gfortran}
228
222
export CC=${arg_c:- gcc}
229
223
export CXX=${arg_C:- g++}
230
-
224
+
231
225
# Check for and, if necessary, install OpenCoarrays prerequisites
232
226
233
- if ! type " $CMAKE " >& /dev/null; then
227
+ if ! type " ${ CMAKE} " >& /dev/null; then
234
228
sudo apt-get install cmake
235
229
fi
236
- if ! type " $CXX " >& /dev/null; then
230
+ if ! type " ${ CXX} " >& /dev/null; then
237
231
sudo apt-get install g++
238
232
fi
239
- if ! type " $FC " >& /dev/null; then
233
+ if ! type " ${FC} " >& /dev/null; then
240
234
sudo apt-get install gfortran
241
235
fi
242
-
236
+
243
237
if ! type mpifort >& /dev/null; then
244
238
sudo apt-get install mpich
245
239
fi
@@ -268,34 +262,34 @@ else
268
262
fi
269
263
}
270
264
set_SUDO_if_needed_to_write_to_install_dir
271
-
265
+
272
266
# Install OpenCoarrays
273
267
274
- if [[ -d " $build_path " ]]; then
275
- rm -rf " $build_path "
268
+ if [[ -d " ${ build_path} " ]]; then
269
+ rm -rf " ${ build_path} "
276
270
fi
277
- mkdir -p " $build_path "
278
- cd " $build_path "
271
+ mkdir -p " ${ build_path} "
272
+ cd " ${ build_path} " || exit 25
279
273
info " Configuring OpenCoarrays with the following command:"
280
- info " FC=\" $FC \" CC=\" $CC \" \" $CMAKE \" \" $OPENCOARRAYS_SRC_DIR \" -DCMAKE_INSTALL_PREFIX=\" $install_prefix \" "
281
- FC=" $FC " CC=" $CC " " $CMAKE " " $OPENCOARRAYS_SRC_DIR " -DCMAKE_INSTALL_PREFIX=" $install_prefix "
274
+ info " FC=\" ${FC} \" CC=\" ${CC} \" \" ${ CMAKE} \" \" ${ OPENCOARRAYS_SRC_DIR} \" -DCMAKE_INSTALL_PREFIX=\" ${ install_prefix} \" "
275
+ FC=" ${FC} " CC=" ${CC} " " ${ CMAKE} " " ${ OPENCOARRAYS_SRC_DIR} " -DCMAKE_INSTALL_PREFIX=" ${ install_prefix} "
282
276
info " Building OpenCoarrays with the following command:"
283
- info " make -j $arg_j "
284
- make -j $ arg_j
277
+ info " make -j ${ arg_j} "
278
+ make -j " ${ arg_j} "
285
279
info " Installing OpenCoarrays with the following command:"
286
280
info " ${SUDO:- } make install"
287
281
${SUDO:- } make install
288
- if [[ -f " $install_prefix " /lib/libcaf_mpi.a && -f " ${install_prefix} /bin/caf" && -f " ${install_prefix} /bin/cafrun" ]]; then
282
+ if [[ -f " ${ install_prefix} " /lib/libcaf_mpi.a && -f " ${install_prefix} /bin/caf" && -f " ${install_prefix} /bin/cafrun" ]]; then
289
283
info " OpenCoarrays has been installed in"
290
- info " $install_prefix "
284
+ info " ${ install_prefix} "
291
285
else
292
286
info " Something went wrong. OpenCoarrays is not in the expected location:"
293
- emergency " $install_prefix "
287
+ emergency " ${ install_prefix} "
294
288
fi
295
289
# See http://stackoverflow.com/questions/31057694/gethostbyname-fail-after-switching-internet-connections/31222970
296
- loopback_line=` grep $ NAME /etc/hosts`
290
+ loopback_line=$( grep " ${ NAME} " /etc/hosts)
297
291
if [[ -z " ${loopback_line:- } " ]]; then
298
292
info " To ensure the correct functioning of MPI, please add the following line to your /etc/hosts file:"
299
- info " 127.0.0.1 $NAME "
293
+ info " 127.0.0.1 ${ NAME} "
300
294
fi
301
295
fi
0 commit comments