Skip to content

Commit 3118348

Browse files
committed
Merge pull request #199 from sourceryinstitute/add-yes-to-all-install
Non-interactive install options: -y/--yes-to-all
2 parents 612f019 + 6354a9d commit 3118348

15 files changed

+167
-145
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ script:
158158
ln -fs "$(which gcc-5)" "$HOME/bin/gcc"
159159
ln -fs "$(which g++-5)" "$HOME/bin/g++"
160160
export PATH="$PATH:$HOME/bin"
161-
yes | ./install.sh -i "$HOME/opt/opencoarrays" -j 4 -f "$HOME/bin/gfortran" -c "$HOME/bin/gcc" -C "$HOME/bin/g++"
161+
./install.sh --yes-to-all -i "$HOME/opt/opencoarrays" -j 4 -f "$HOME/bin/gfortran" -c "$HOME/bin/gcc" -C "$HOME/bin/g++"
162162
else
163163
mkdir cmake-build
164164
cd cmake-build

install.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ info "-P (--print-path): ${arg_P}"
166166
info "-U (--print-url): ${arg_U}"
167167
info "-v (--version): ${arg_v}"
168168
info "-V (--print-version): ${arg_V}"
169+
info "-y (--yes-to-all): ${arg_y}"
169170
}
170171
# This file is organized into three sections:
171172
# 1. Command-line argument and environment variable processing.
@@ -239,7 +240,7 @@ source $opencoarrays_src_dir/prerequisites/install-functions/report_results.sh
239240
if [[ "${arg_v}" == "${__flag_present}" || "${arg_V}" == "opencoarrays" ]]; then
240241

241242
# Print script copyright if invoked with -v, -V, or --version argument
242-
cmake_project_line=$(grep project ${opencoarrays_src_dir}/CMakeLists.txt | grep VERSION)
243+
cmake_project_line="$(grep project "${opencoarrays_src_dir}/CMakeLists.txt" | grep VERSION)"
243244
text_after_version_keyword="${cmake_project_line##*VERSION}"
244245
text_before_language_keyword="${text_after_version_keyword%%LANGUAGES*}"
245246
opencoarrays_version=$text_before_language_keyword
@@ -309,8 +310,8 @@ elif [[ "${arg_p:-}" == "ofp" ]]; then
309310
elif [[ ! -z "${arg_p:-}" ]]; then
310311

311312
info "Invoking build script with the following command:"
312-
info "\"${opencoarrays_src_dir}\"/prerequisites/build.sh ${@:-}"
313-
"${opencoarrays_src_dir}"/prerequisites/build.sh ${@:-}
313+
info "\"${opencoarrays_src_dir}\"/prerequisites/build.sh ${*:-}"
314+
"${opencoarrays_src_dir}"/prerequisites/build.sh "${@:-}"
314315

315316
fi
316317
# ____________________________________ End of Main Body ____________________________________________

install.sh-usage

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
-U --print-url [arg] Print download location for specified package.
2020
-v --version Print OpenCoarrays version number.
2121
-V --print-version [arg] Print version number for specified package.
22+
-y --yes-to-all Build non-interactively by assuming affirmative user responses.

prerequisites/build-functions/download_if_necessary.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck shell=bash disable=SC2148
12
# shellcheck source=./ftp-url.sh
23
source "${OPENCOARRAYS_SRC_DIR}/prerequisites/build-functions/ftp-url.sh"
34
# shellcheck source=./set_SUDO_if_needed_to_write_to_directory.sh
@@ -12,14 +13,18 @@ download_if_necessary()
1213
if [[ -f "${download_path}/${url_tail}" || -d "${download_path}/${url_tail}" ]] ; then
1314
info "Found '${url_tail}' in ${download_path}."
1415
info "If it resulted from an incomplete download, building ${package_name} could fail."
15-
info "Would you like to proceed anyway? (Y/n)"
16-
read -r proceed
17-
if [[ "${proceed}" == "n" || "${proceed}" == "N" || "${proceed}" == "no" ]]; then
18-
info "n"
19-
info "Please remove $url_tail and restart the installation to to ensure a fresh download." 1>&2
20-
emergency "Aborting. [exit 80]"
16+
if [[ "${arg_y}" == "${__flag_present}" ]]; then
17+
info "-y or --yes-to-all flag present. Proceeding with non-interactive build."
2118
else
22-
info "y"
19+
info "Would you like to proceed anyway? (Y/n)"
20+
read -r proceed
21+
if [[ "${proceed}" == "n" || "${proceed}" == "N" || "${proceed}" == "no" ]]; then
22+
info "n"
23+
info "Please remove $url_tail and restart the installation to to ensure a fresh download." 1>&2
24+
emergency "Aborting. [exit 80]"
25+
else
26+
info "y"
27+
fi
2328
fi
2429
elif ! type "${fetch}" &> /dev/null; then
2530
# The download mechanism is missing
@@ -45,9 +50,9 @@ download_if_necessary()
4550
args="clone"
4651
elif [[ "${fetch}" == "curl" ]]; then
4752
first_three_characters=$(echo "${package_url}" | cut -c1-3)
48-
if [[ "${first_three_characters}" == "ftp" ]]; then
53+
if [[ "${first_three_characters}" == "ftp" ]]; then
4954
args="-LO -u anonymous:"
50-
elif [[ "${first_three_characters}" == "htt" ]]; then
55+
elif [[ "${first_three_characters}" == "htt" ]]; then
5156
args="-LO"
5257
else
5358
emergency "download_if_necessary.sh: Unrecognized URL."
@@ -64,7 +69,8 @@ download_if_necessary()
6469
info "Download command: \"${fetch}\" ${args:-} ${package_url}"
6570
info "Depending on the file size and network bandwidth, this could take several minutes or longer."
6671
pushd "${download_path}"
67-
"${fetch}" ${args:-} ${package_url}
72+
# args should be an array. Then "${args[@]:-}" will prevent shellcheck from complaining
73+
"${fetch}" ${args:-} "${package_url}"
6874
popd
6975
if [[ ! -z "${arg_B:-}" ]]; then
7076
return

prerequisites/build-functions/set_or_print_default_version.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck shell=bash disable=SC2148
12
# If -p, -D, -P, or -U specifies a package, set default_version
23
# If -V specifies a package, print the default_version and exit with normal status
34
# If -l is present, list all packages and versions and exit with normal status
@@ -15,11 +16,11 @@ set_or_print_default_version()
1516
package_name="${arg_p:-${arg_D:-${arg_P:-${arg_U:-${arg_V}}}}}" # not needed for -l
1617

1718
if [[ "${package_name}" == "ofp" ]]; then
18-
${OPENCOARRAYS_SRC_DIR}/prerequisites/install-ofp.sh "${@}"
19+
"${OPENCOARRAYS_SRC_DIR}/prerequisites/install-ofp.sh" "${@}"
1920
exit 0
20-
fi
21+
fi
2122

22-
[ "${package_name}" == "opencoarrays" ] &&
23+
[ "${package_name}" == "opencoarrays" ] &&
2324
emergency "Please use this script with a previously downloaded opencoarrays source archive. This script does not download opencoarrays "
2425
# This is a bash 3 hack standing in for a bash 4 hash (bash 3 is the lowest common
2526
# denominator because, for licensing reasons, OS X only has bash 3 by default.)

prerequisites/build-functions/set_or_print_downloader.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck shell=bash disable=SC2148
12
# If -p, -P, -U, or -V specifies a package, set fetch variable
23
# If -D specifies a package, print "${fetch}" and exit with normal status
34
# If -l is present, list all packages and versions and exit with normal status
@@ -11,20 +12,20 @@ set_or_print_downloader()
1112
package_name="${arg_p:-${arg_D:-${arg_P:-${arg_U:-${arg_V:-${arg_B}}}}}}"
1213

1314
if [[ "${package_name}" == "ofp" ]]; then
14-
${OPENCOARRAYS_SRC_DIR}/prerequisites/install-ofp.sh "${@}"
15+
"${OPENCOARRAYS_SRC_DIR}/prerequisites/install-ofp.sh" "${@}"
1516
exit 0
16-
fi
17+
fi
1718

18-
# Choose the first available download mechanism, prioritizing first any absolute requirement
19+
# Choose the first available download mechanism, prioritizing first any absolute requirement
1920
# (svn for gcc development branches) and second robustness:
2021
info "Checking available download mechanisms: ftp, wget, and curl."
2122
info "\${package_name}=${package_name} \${arg_b:-\${arg_B:-}}=${arg_b:-${arg_B:-}}"
22-
23+
2324
if [[ "${package_name}" == "gcc" && ! -z "${arg_b:-${arg_B:-}}" ]]; then
2425

2526
if type svn &> /dev/null; then
26-
fetch=svn
27-
else
27+
fetch=svn
28+
else
2829
tried="svn"
2930
fi
3031

@@ -39,19 +40,19 @@ set_or_print_downloader()
3940
fi
4041
else
4142
tried="curl, wget, and ftp"
42-
fi
43+
fi
4344

4445
if [[ -z "${fetch:-}" ]]; then
4546
if [[ -z "${arg_B:-}" ]]; then
46-
warning "No available download mechanism. Options tried: ${tried}"
47-
else
48-
emergency "No available download mechanism. Option tried: ${tried}"
47+
warning "No available download mechanism. Options tried: ${tried}"
48+
else
49+
emergency "No available download mechanism. Option tried: ${tried}"
4950
fi
5051
fi
5152

5253
# If a printout of the download mechanism was requested, then print it and exit with normal status
53-
if [[ ! -z "${arg_D}" ]]; then
54-
printf "%s\n" "${fetch}"
54+
if [[ ! -z "${arg_D}" ]]; then
55+
printf "%s\n" "${fetch}"
5556
exit 0
5657
fi
5758
}

prerequisites/build.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ trap cleanup_before_exit EXIT # The signal is specified here. Could be SIGINT, S
5959
export __flag_present=1
6060

6161
# shellcheck disable=SC2154
62-
if [[ "${arg_l}" != "${__flag_present}" &&
63-
"${arg_v}" != "${__flag_present}" &&
62+
if [[ "${arg_l}" != "${__flag_present}" &&
63+
"${arg_v}" != "${__flag_present}" &&
6464
"${arg_h}" != "${__flag_present}" &&
6565
-z "${arg_D:-${arg_p:-${arg_P:-${arg_U:-${arg_V:-${arg_B}}}}}}" ]]; then
6666
help "${__base}: Insufficient arguments. Please pass either -B, -D, -h, -l, -L, -p, -P, -U, -v, -V, or a longer equivalent."
@@ -110,17 +110,20 @@ info "-t (--with-tau): ${arg_t} "
110110
info "-U (--print-url): ${arg_U} "
111111
info "-v (--version): ${arg_v} "
112112
info "-V (--print-version): ${arg_V} "
113+
info "-y (--yes-to-all): ${arg_y} "
113114
}
114115

115116
if [[ -z "${arg_B}" ]]; then
116117
# shellcheck source=./build-functions/set_or_print_default_version.sh
117118
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/set_or_print_default_version.sh"
119+
# shellcheck disable=SC2119
118120
set_or_print_default_version
119121
export version_to_build="${arg_I:-${arg_b:-${default_version}}}"
120122
fi
121123

122124
# shellcheck source=./build-functions/set_or_print_downloader.sh
123125
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/set_or_print_downloader.sh"
126+
# shellcheck disable=SC2119
124127
set_or_print_downloader
125128

126129
# shellcheck source=./build-functions/set_or_print_url.sh
@@ -142,11 +145,11 @@ if [[ -z "${arg_B}" ]]; then
142145
# shellcheck source=./build-functions/unpack_if_necessary.sh
143146
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/unpack_if_necessary.sh"
144147
unpack_if_necessary
145-
148+
146149
# shellcheck source=./build-functions/set_compilers.sh
147150
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/set_compilers.sh"
148151
set_compilers
149-
152+
150153
# shellcheck source=./build-functions/build_and_install.sh
151154
source "${OPENCOARRAYS_SRC_DIR:-}/prerequisites/build-functions/build_and_install.sh"
152155
build_and_install

prerequisites/build.sh-usage

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
-U --print-url [arg] Print URL for package specified in argument.
2222
-v --version Print OpenCoarrays version number.
2323
-V --print-version [arg] Print installation version for package specified in argument.
24+
-y --yes-to-all Build non-interactively by assuming affirmative user responses.

prerequisites/install-binary.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if [[ ! -f "${B3B_USE_CASE:-}/bootstrap.sh" ]]; then
4444
echo "Please set B3B_USE_CASE to the bash3boilerplate use-case directory path."
4545
exit 2
4646
else
47-
# shellcheck source=./prerequisites/use-case/bootstrap.sh
47+
# shellcheck source=./use-case/bootstrap.sh
4848
source "${B3B_USE_CASE}/bootstrap.sh" "$@"
4949
fi
5050
### End of boilerplate -- start user edits below #########################

0 commit comments

Comments
 (0)