1- # /usr/bin/env bash
1+ #! /usr/bin/env bash
22#
33# windows-install.sh
44#
@@ -109,18 +109,19 @@ trap cleanup_before_exit EXIT # The signal is specified here. Could be SIGINT, S
109109# ## Validation (decide what's required for running your script and error out)
110110# ####################################################################
111111
112- [ -z " ${LOG_LEVEL:- } " ] && emergency " Cannot continue without LOG_LEVEL. "
112+ [[ -z " ${LOG_LEVEL:- } " ] ] && emergency " Cannot continue without LOG_LEVEL. "
113113
114114# shellcheck disable=SC2154
115- if [[ " ${arg_d} " == " ${__flag_present} " ]]; then
115+ if [[ " ${arg_d} " == " ${__flag_present} " ]]; then
116116 print_debug_only=7
117- if [ " $(( LOG_LEVEL < print_debug_only )) " -ne 0 ]; then
117+ if [[ " $(( LOG_LEVEL < print_debug_only )) " -ne 0 ] ]; then
118118 debug " Supressing info and debug messages: one of {-l, -v, -P, -U, -V, -D} present."
119119 suppress_info_debug_messages
120120 fi
121121fi
122122
123123# Get linux_distribution name
124+ # shellcheck disable=SC2154
124125{
125126info " __file: ${__file} "
126127info " __dir: ${__dir} "
@@ -144,7 +145,8 @@ info "-V (--version-number): ${arg_V}"
144145
145146# __________ Process command-line arguments and environment variables _____________
146147
147- export this_script=" $( basename " $0 " ) "
148+ this_script=" $( basename " ${0} " ) "
149+ export this_script
148150debug " this_script=\" ${this_script} \" "
149151
150152export install_prefix=" ${arg_i%/:- ${PWD} / prerequisites/ installations} "
@@ -153,17 +155,9 @@ info "install_prefix=\"${install_prefix}\""
153155export num_threads=" ${arg_j} "
154156info " num_threads=\" ${arg_j} \" "
155157
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" )
165159
166- export build_path=" ${OPENCOARRAYS_SRC_DIR%/ } " /prerequisites/builds/opencoarrays/$opencoarrays_version
160+ export build_path=" ${OPENCOARRAYS_SRC_DIR%/ } " /prerequisites/builds/opencoarrays/${ opencoarrays_version}
167161info " build_path=\" ${build_path} \" "
168162
169163export CMAKE=" ${arg_m:- cmake} "
@@ -173,7 +167,7 @@ verify_this_is_ubuntu()
173167 if [[ ${__os} != " Linux" ]]; then
174168 emergency " ${__os} not supported: this script is intended for use in Windows Subsystem for Linux "
175169 fi
176- linux_standard_base_i=` lsb_release -i`
170+ linux_standard_base_i=$( lsb_release -i)
177171 untrimmed_name=${linux_standard_base_i##* Distributor ID: }
178172 linux_distribution=" ${untrimmed_name// [[:space:]]/ } "
179173 info " Linux distribution: ${linux_distribution} "
@@ -188,16 +182,16 @@ verify_this_is_ubuntu
188182# Ubuntu 16.04 apt-get installs gfortran 5.4.0 or later, which is acceptable for many uses of OpenCoarrays
189183verify_acceptable_release_number ()
190184{
191- linux_standard_base_r=` lsb_release -r`
185+ linux_standard_base_r=$( lsb_release -r)
192186 untrimmed_name=${linux_standard_base_r##* Release: }
193187 release_number=" ${untrimmed_name// [[:space:]]/ } "
194188 major_release=" ${release_number%% .* } "
195189 minor_release=" ${release_number##* .} "
196190 info " Release: ${major_release} .${minor_release} "
197- if [[ $major_release -lt 16 ]]; then
191+ if [[ ${ major_release} -lt 16 ]]; then
198192 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
201195 emergency " Please upgrade to Windows Subsystem for Linux (WSL) Ubuntu 16.04 or later."
202196 fi
203197 fi
@@ -206,7 +200,7 @@ verify_acceptable_release_number
206200
207201if [[ " ${arg_V} " == " ${__flag_present} " ]]; then
208202 # Print just the version number
209- info " $opencoarrays_version "
203+ info " ${ opencoarrays_version} "
210204
211205elif [[ " ${arg_v} " == " ${__flag_present} " ]]; then
212206
@@ -227,19 +221,19 @@ else
227221 export FC=${arg_f:- gfortran}
228222 export CC=${arg_c:- gcc}
229223 export CXX=${arg_C:- g++}
230-
224+
231225 # Check for and, if necessary, install OpenCoarrays prerequisites
232226
233- if ! type " $CMAKE " >& /dev/null; then
227+ if ! type " ${ CMAKE} " >& /dev/null; then
234228 sudo apt-get install cmake
235229 fi
236- if ! type " $CXX " >& /dev/null; then
230+ if ! type " ${ CXX} " >& /dev/null; then
237231 sudo apt-get install g++
238232 fi
239- if ! type " $FC " >& /dev/null; then
233+ if ! type " ${FC} " >& /dev/null; then
240234 sudo apt-get install gfortran
241235 fi
242-
236+
243237 if ! type mpifort >& /dev/null; then
244238 sudo apt-get install mpich
245239 fi
@@ -268,34 +262,34 @@ else
268262 fi
269263 }
270264 set_SUDO_if_needed_to_write_to_install_dir
271-
265+
272266 # Install OpenCoarrays
273267
274- if [[ -d " $build_path " ]]; then
275- rm -rf " $build_path "
268+ if [[ -d " ${ build_path} " ]]; then
269+ rm -rf " ${ build_path} "
276270 fi
277- mkdir -p " $build_path "
278- cd " $build_path "
271+ mkdir -p " ${ build_path} "
272+ cd " ${ build_path} " || exit 25
279273 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} "
282276 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} "
285279 info " Installing OpenCoarrays with the following command:"
286280 info " ${SUDO:- } make install"
287281 ${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
289283 info " OpenCoarrays has been installed in"
290- info " $install_prefix "
284+ info " ${ install_prefix} "
291285 else
292286 info " Something went wrong. OpenCoarrays is not in the expected location:"
293- emergency " $install_prefix "
287+ emergency " ${ install_prefix} "
294288 fi
295289 # 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)
297291 if [[ -z " ${loopback_line:- } " ]]; then
298292 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} "
300294 fi
301295fi
0 commit comments