4
4
# shellcheck disable=SC2154
5
5
set_or_print_downloader ()
6
6
{
7
-
8
7
# Verify requirements
9
8
[ ! -z " ${arg_D} " ] && [ ! -z " ${arg_p:- ${arg_P:- ${arg_U:- ${arg_V:- ${arg_B} } } } } " ] &&
10
9
emergency " Please pass only one of {-B, -D, -p, -P, -U, -V} or a longer equivalent (multiple detected)."
@@ -14,48 +13,45 @@ set_or_print_downloader()
14
13
if [[ " ${package_name} " == " ofp" ]]; then
15
14
${OPENCOARRAYS_SRC_DIR} /prerequisites/install-ofp.sh " ${@ } "
16
15
exit 0
17
- fi
18
- if [[ $( uname) == " Darwin" ]]; then
19
- wget_or_curl=curl
20
- ftp_or_curl=curl
16
+ fi
17
+
18
+ # Choose the first available download mechanism, prioritizing first any absolute requirement
19
+ # (svn for gcc development branches) and second robustness:
20
+ info " Checking available download mechanisms: ftp, wget, and curl."
21
+ info " \$ {package_name}=${package_name} \$ {arg_b:-\$ {arg_B:-}}=${arg_b:- ${arg_B:- } } "
22
+
23
+ if [[ " ${package_name} " == " gcc" && ! -z " ${arg_b:- ${arg_B:- } } " ]]; then
24
+
25
+ if type svn & > /dev/null; then
26
+ fetch=svn
27
+ else
28
+ tried=" svn"
29
+ fi
30
+
31
+ elif type curl & > /dev/null; then
32
+ fetch=curl
33
+ elif type wget & > /dev/null; then
34
+ fetch=wget
35
+ elif type ftp & > /dev/null; then
36
+ if [[ " ${package_name} " == " gcc" || " ${package_name} " == " wget" || " ${package_name} " == " make" ||
37
+ " ${package_name} " == " bison" || " ${package_name} " == " m4" ]]; then
38
+ fetch=ftp-url
39
+ fi
21
40
else
22
- wget_or_curl= wget
23
- ftp_or_curl=ftp-url
24
- fi
25
- if [[ " ${package_name} " == " gcc " ]]; then
26
- if [[ -z " ${arg_b :- ${ arg_B:- } } " ]]; then
27
- gcc_fetch= " ${ftp_or_curl} "
28
- else
29
- gcc_fetch= " svn "
41
+ tried= " curl, wget, and ftp "
42
+ fi
43
+
44
+ if [[ -z " ${fetch :- } " ]]; then
45
+ 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} "
30
49
fi
31
50
fi
32
- # This is a bash 3 hack standing in for a bash 4 hash (bash 3 is the lowest common
33
- # denominator because, for licensing reasons, OS X only has bash 3 by default.)
34
- # See http://stackoverflow.com/questions/1494178/how-to-define-hash-tables-in-bash
35
- package_fetch=(
36
- " gcc:${gcc_fetch-} "
37
- " wget:${ftp_or_curl-} "
38
- " cmake:${wget_or_curl-} "
39
- " mpich:${wget_or_curl-} "
40
- " flex:${wget_or_curl-} "
41
- " bison:${ftp_or_curl-} "
42
- " pkg-config:${wget_or_curl-} "
43
- " make:${ftp_or_curl-} "
44
- " m4:${ftp_or_curl-} "
45
- " subversion:${wget_or_curl-} "
46
- )
47
- for package in " ${package_fetch[@]} " ; do
48
- KEY=" ${package%%:* } "
49
- VALUE=" ${package##*: } "
50
- if [[ " ${package_name} " == " ${KEY} " ]]; then
51
- # We recognize the package name so we set the download mechanism:
52
- fetch=${VALUE}
53
- # If a printout of the download mechanism was requested, then print it and exit with normal status
54
- [[ ! -z " ${arg_D} " ]] && printf " %s\n" " ${fetch} " && exit 0
55
- break # exit the for loop
56
- fi
57
- done
58
- if [[ -z " ${fetch:- } " ]]; then
59
- emergency " Package ${package_name:- } not recognized. Use --l or --list-packages to list the allowable names."
51
+
52
+ # 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} "
55
+ exit 0
60
56
fi
61
57
}
0 commit comments