Skip to content

Commit cf99c2e

Browse files
author
Damian Rouson
committed
Edit GCC download_prerequisites for macOS
Since sometime during the development of GCC 7, GCC's download_prerequisites script verifies the integrity of downloaded prerequisite tar balls using "sha512sum" by default. On macOS, this should be "shasum -a 512". This commit adjusts the OpenCoarrays edit_GCC_download_prereqs_file_if_necessary.sh script so it can edit the download_prerequisites script to make the file verification work on macOS.
1 parent 48d7eee commit cf99c2e

File tree

2 files changed

+63
-37
lines changed

2 files changed

+63
-37
lines changed

install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ info "-l (--list-packages): ${arg_l}"
161161
info "-m (--with-cmake): ${arg_m}"
162162
info "-M (--with-mpi): ${arg_M}"
163163
info "-n (--no-color): ${arg_n}"
164+
info "-o (--only-download): ${arg_o}"
164165
info "-p (--package): ${arg_p}"
165166
info "-P (--print-path): ${arg_P}"
166167
info "-U (--print-url): ${arg_U}"
Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
# Make the build directory, configure, and build
1+
22
# shellcheck disable=SC2154
33

44
edit_GCC_download_prereqs_file_if_necessary()
55
{
6-
# Only modify download_prerequisites if wget is unavailable
7-
if type wget &> /dev/null; then
8-
info "wget available. Invoking unmodified GCC script contrib/download_prerequisites."
9-
else
10-
info "wget unavailable. Editing GCC contrib/download_prerequisites to replace it with ${gcc_prereqs_fetch}"
6+
__operating_system=$(uname)
7+
download_prereqs_file="${PWD}/contrib/download_prerequisites"
118

12-
download_prereqs_file="${PWD}/contrib/download_prerequisites"
13-
14-
# Define a file extension for the download_prerequisites backup
15-
backup_extension=".original"
16-
backup_file="${download_prereqs_file}${backup_extension}"
17-
if [[ -f ${backup_file} ]]; then
18-
# Prevent overwriting an existing backup:
19-
backup_extension=""
20-
fi
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+
22+
# Define a file extension for the download_prerequisites backup
23+
backup_extension=".original"
24+
backup_file="${download_prereqs_file}${backup_extension}"
25+
if [[ -f ${backup_file} ]]; then
26+
# Prevent overwriting an existing backup:
27+
backup_extension=""
28+
fi
29+
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}"
2135

22-
# Grab the line with the first occurence of 'wget'
23-
wget_line=`grep wget "${download_prereqs_file}" | head -1` || true
2436
if [[ ! -z "${wget_line:-}" ]]; then
2537
# Download_prerequisites contains wget so we haven't modified it
2638
already_modified_downloader="false"
@@ -36,14 +48,8 @@ edit_GCC_download_prereqs_file_if_necessary()
3648
# Only modify download_prerequisites once
3749
if [[ ${already_modified_downloader} != "true" ]]; then
3850

39-
# Check for wget format used before GCC 7
40-
if [[ "${wget_line}" == *"ftp"* ]]; then
41-
gcc7_format="false"
42-
wget_command="${wget_line%%ftp*}" # grab everything before ftp
51+
if [[ "${gcc7_format}" == "true" ]]; then
4352

44-
# Check for wget format adopted in GCC 7
45-
elif [[ "${wget_line}" == *"base_url"* ]]; then
46-
gcc7_format="true"
4753
case "${gcc_prereqs_fetch}" in
4854
"ftp_url")
4955
# Insert a new line after line 2 to include ftp_url.sh as a download option
@@ -74,25 +80,44 @@ edit_GCC_download_prereqs_file_if_necessary()
7480
debug "if problem downloading, ensure that the gcc download_prerequisites edits are compatible with ${gcc_prereqs_fetch}"
7581
;;
7682
esac
77-
# Protect against missing sha512sum command adopted in GCC 7 (not available by default on Lubuntu Linux)
78-
if ! type sha512sum &> /dev/null; then
79-
info "sha512sum unavailable. Turning off file integrity verification in GCC contrib/download_prerequisites."
80-
if [[ "$(uname)" == "Linux" ]]; then
81-
# Adjust for non-POSIX OS
82-
sed -i"${backup_extension}" s/"verify=1"/"verify=0"/ "${download_prereqs_file}"
83-
else
84-
sed -i "${backup_extension}" s/"verify=1"/"verify=0"/ "${download_prereqs_file}"
85-
fi
86-
fi
8783
fi
88-
info "Using the following command to replacing wget in the GCC download_prerequisites file:"
84+
info "Using the following command to replace wget in the GCC download_prerequisites file:"
8985
info "sed -i${backup_extension} s/\"${wget_command}\"/\"${gcc_prereqs_fetch} ${arg_string} \"/ \"${download_prereqs_file}\""
90-
if [[ "$(uname)" == "Linux" ]]; then
86+
if [[ "${__operating_system}" == "Linux" ]]; then
9187
sed -i"${backup_extension}" s/"${wget_command}"/"${gcc_prereqs_fetch} ${arg_string} "/ "${download_prereqs_file}"
9288
else
9389
sed -i "${backup_extension}" s/"${wget_command}"/"${gcc_prereqs_fetch} ${arg_string} "/ "${download_prereqs_file}"
9490
fi
9591

9692
fi # end if [[ ${already_modified_downloader:-} != "true" ]];
97-
fi # end if ! type wget &> /dev/null;
93+
fi # end if ! type wget &> /dev/null;
94+
95+
if [[ "${gcc7_format:-}" == "true" ]]; then
96+
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"
100+
101+
if ! type sha512sum &> /dev/null; then
102+
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
119+
120+
fi
121+
122+
fi
98123
}

0 commit comments

Comments
 (0)