1-
21# shellcheck disable=SC2154
3-
4- edit_GCC_download_prereqs_file_if_necessary ()
2+ replace_wget ()
53{
6- __operating_system=$( uname)
7- download_prereqs_file=" ${PWD} /contrib/download_prerequisites"
8-
9- # Grab the line with the first occurence of 'wget'
10- wget_line=` grep wget " ${download_prereqs_file} " | head -1` || true
11-
12- # Check for wget format used before GCC 7
13- if [[ " ${wget_line} " == * " ftp" * ]]; then
14- gcc7_format=" false"
15- wget_command=" ${wget_line%% ftp* } " # grab everything before ftp
16-
17- # Check for wget format adopted in GCC 7
18- elif [[ " ${wget_line} " == * " base_url" * ]]; then
19- gcc7_format=" true"
20- fi
21-
224 # Define a file extension for the download_prerequisites backup
235 backup_extension=" .original"
246 backup_file=" ${download_prereqs_file}${backup_extension} "
@@ -27,97 +9,36 @@ edit_GCC_download_prereqs_file_if_necessary()
279 backup_extension=" "
2810 fi
2911
30- # Modify download_prerequisites if wget is unavailable
31- if type wget & > /dev/null; then
32- info " wget available. Leavingh wget invocations unmodified in the GCC script contrib/download_prerequisites."
33- else
34- info " wget unavailable. Editing GCC contrib/download_prerequisites to replace it with ${gcc_prereqs_fetch} "
35-
36- if [[ ! -z " ${wget_line:- } " ]]; then
37- # Download_prerequisites contains wget so we haven't modified it
38- already_modified_downloader=" false"
39- else
40- # Check whether a backup file already exists
41- if [[ ! -f " ${backup_file} " ]]; then
42- emergency " : gcc contrib/download_prerequisites does not use wget"
43- else
44- already_modified_downloader=" true"
45- fi
46- fi
47-
48- # Only modify download_prerequisites once
49- if [[ ${already_modified_downloader} != " true" ]]; then
50-
51- if [[ " ${gcc7_format} " == " true" ]]; then
52-
53- case " ${gcc_prereqs_fetch} " in
54- " ftp_url" )
55- # Insert a new line after line 2 to include ftp_url.sh as a download option
56- sed -i${backup_extension} -e ' 2 a\' $' \n ' " . ${OPENCOARRAYS_SRC_DIR} /prerequisites/build-functions/ftp_url.sh" $' \n ' " ${download_prereqs_file} "
57- wget_command=' wget --no-verbose -O "${directory}\/${ar}"'
58- ;;
59- " curl" )
60- wget_command=" ${wget_line%% \"\$\{ directory\} * } " # grab everything before "${base_url}
61- wget_command=" wget${wget_command#* wget} " # keep everything from wget forward
62- ;;
63- * )
64- emergency " Unknown download program ${gcc_prereqs_fetch} in edit_GCC_download_prereqs_file_if_necessary.sh"
65- ;;
66- esac
67-
68- else
69- emergency " gcc contrib/download_prerequisites does not use a known URL format"
70- fi
71-
72- arg_string=" ${gcc_prereqs_fetch_args[@]:- } "
73-
74- if [[ ${gcc7_format} == " true" ]]; then
75- case " ${gcc_prereqs_fetch} " in
76- " curl" )
77- arg_string=" ${arg_string} -o "
78- ;;
79- * )
80- debug " if problem downloading, ensure that the gcc download_prerequisites edits are compatible with ${gcc_prereqs_fetch} "
81- ;;
82- esac
83- fi
84- info " Using the following command to replace wget in the GCC download_prerequisites file:"
85- info " sed -i${backup_extension} s/\" ${wget_command} \" /\" ${gcc_prereqs_fetch} ${arg_string} \" / \" ${download_prereqs_file} \" "
86- if [[ " ${__operating_system} " == " Linux" ]]; then
87- sed -i" ${backup_extension} " s/" ${wget_command} " /" ${gcc_prereqs_fetch} ${arg_string} " / " ${download_prereqs_file} "
88- else
89- sed -i " ${backup_extension} " s/" ${wget_command} " /" ${gcc_prereqs_fetch} ${arg_string} " / " ${download_prereqs_file} "
90- fi
91-
92- fi # end if [[ ${already_modified_downloader:-} != "true" ]];
93- fi # end if ! type wget &> /dev/null;
12+ if [[ " ${gcc_prereqs_fetch} " == " ftp_url" ]]; then
13+ # Insert a new line after line 2 to include ftp_url.sh as a download option
14+ sed -i${backup_extension} -e ' 2 a\' $' \n ' " . ${OPENCOARRAYS_SRC_DIR} /prerequisites/build-functions/ftp_url.sh" $' \n ' " ${download_prereqs_file} "
15+ fi
9416
95- if [[ " ${gcc7_format :- } " == " true " ]] ; then
17+ arg_string= " ${gcc_prereqs_fetch_args[@] :- } "
9618
97- # Protect against missing sha512sum command adopted in GCC 7 but unavailable on
98- # 1. Some Linux distributions (e.g., older Lubuntu distributions)
99- # 2. macOS, where the replacement is "shasum -a 512"
19+ info " Using the following command to replace wget in the GCC download_prerequisites file:"
20+ info " sed -i${backup_extension} s/\" ${wget_command} \" /\" ${gcc_prereqs_fetch} ${arg_string} \" / \" ${download_prereqs_file} \" "
21+ if [[ " ${__operating_system} " == " Linux" ]]; then
22+ sed -i" ${backup_extension} " s/wget/" ${gcc_prereqs_fetch} ${arg_string} " / " ${download_prereqs_file} "
23+ else
24+ sed -i " ${backup_extension} " s/wget/" ${gcc_prereqs_fetch} ${arg_string} " / " ${download_prereqs_file} "
25+ fi
26+ }
10027
101- if ! type sha512sum & > /dev/null; then
28+ edit_GCC_download_prereqs_file_if_necessary ()
29+ {
30+ __operating_system=$( uname)
31+ download_prereqs_file=" ${PWD} /contrib/download_prerequisites"
10232
103- info " sha512sum unavailable."
104- case " ${__operating_system} " in
105- " Darwin" )
106- info " Substituting shasum -a 512"
107- sed -i " ${backup_extension} " s/" \"\$ {chksum}sum\" --check" /" shasum -a 512 --check" / " ${download_prereqs_file} "
108- ;;
109- " Linux" )
110- info " Turning off file integrity verification in GCC contrib/download_prerequisites."
111- sed -i" ${backup_extension} " s/" verify=1" /" verify=0" / " ${download_prereqs_file} "
112- ;;
113- * )
114- warning " Unrecognized operating system. Attempting to modify download_prerequisites with a 'sed' command synatax that assumes POSIX compliance."
115- info " Turning off file integrity verification in GCC contrib/download_prerequisites."
116- sed -i " ${backup_extension} " s/" verify=1" /" verify=0" / " ${download_prereqs_file} "
117- ;;
118- esac
33+ # Grab the line with the first occurence of 'wget'
34+ wget_line=` grep wget " ${download_prereqs_file} " | head -1` || true
35+ wget_command=" ${wget_line%% ftp* } " # grab everything before ftp
11936
37+ # Check for wget format used before GCC 7
38+ if [[ ! -z " ${wget_command} " ]]; then
39+ # Check whether wget is available on this system
40+ if ! type wget & > /dev/null; then
41+ replace_wget
12042 fi
121-
12243 fi
12344}
0 commit comments