Update Trac ticket URLs to point to GitLab
[ghc.git] / mk / get-win32-tarballs.sh
1 #!/usr/bin/env bash
2
3 tarball_dir='ghc-tarballs'
4 missing_files=0
5
6 # see #12502
7 if test -z "$FIND"; then FIND="find"; fi
8
9 fail() {
10 echo >&2
11 echo "$1" >&2
12 exit 1
13 }
14
15 download_file() {
16 local file_url="$1"
17 local dest_file="$2"
18 local description="$3"
19 local extra_curl_opts="$4"
20 local backup_url="$5"
21 local dest_dir="$(dirname $dest_file)"
22
23 if ! test -f "${dest_file}"
24 then
25 local curl_cmd="curl -f -L ${file_url} -o ${dest_file} --create-dirs -# ${extra_curl_opts}"
26 if test -n "${backup_url}"; then
27 local curl_cmd_bnk="curl -f -L ${backup_url} -o ${dest_file} --create-dirs -# ${extra_curl_opts}"
28 else
29 local curl_cmd_bnk="true"
30 fi
31
32 if test "$download" = "0"
33 then
34 echo "ERROR: Missing ${description}" >&2
35 echo "${file_url}"
36 missing_files=1
37 return
38 else
39 echo "Downloading ${description} to ${dest_dir}..."
40 $curl_cmd || echo "Checking repo.msys2.org instead of Haskell.org..." && $curl_cmd_bnk || {
41 rm -f "${dest_file}"
42 fail "ERROR: Download failed."
43 exit 1
44 }
45 fi
46 fi
47
48 local sig_file="${dest_file}.sig"
49 if test "$sigs" = "1" -a ! -f "$sig_file"
50 then
51 echo "Downloading ${description} (signature) to ${dest_dir}..."
52 local curl_cmd="curl -f -L ${file_url}.sig -o ${sig_file} --create-dirs -# ${extra_curl_opts}"
53 if test -n "${backup_url}"; then
54 local curl_cmd_bnk="curl -f -L ${backup_url} -o ${sig_file} --create-dirs -# ${extra_curl_opts}"
55 else
56 local curl_cmd_bnk="true"
57 fi
58 $curl_cmd || echo "Checking repo.msys2.org instead of Haskell.org..." && $curl_cmd_bnk || {
59 rm -f "${dest_file}.sig"
60 fail "ERROR: Download failed."
61 exit 1
62 }
63 fi
64
65 if test "$verify" = "1"
66 then
67 grep "${dest_file}$" mk/win32-tarballs.md5sum | md5sum --quiet -c - ||
68 fail "ERROR: ${description} appears to be corrupted, please delete it and try again."
69 fi
70 }
71
72 download_mingw() {
73 local mingw_base_url_primary="https://downloads.haskell.org/~ghc/mingw"
74 local mingw_base_url_secondary="http://repo.msys2.org/mingw"
75
76 if test "$mingw_arch" = "sources"
77 then
78 mingw_url_tmp=`echo "$1" | sed -e 's/-any\.pkg\.tar\.xz/\.src\.tar\.gz/' \
79 -e 's/-sources-/-/' \
80 -e 's/-libwinpthread-git-/-winpthreads-git-/' `
81 local mingw_url="${mingw_base_url_primary}/${mingw_url_tmp}"
82 local mingw_url_backup="${mingw_base_url_secondary}/${mingw_url_tmp}"
83 else
84 local mingw_url="${mingw_base_url_primary}/$1"
85 local mingw_url_backup="${mingw_base_url_secondary}/$1"
86 fi
87
88 local mingw_toolchain="$(basename $mingw_url)"
89 local mingw_w64="${tarball_dir}/${tarball_dest_dir}/${mingw_toolchain}"
90
91 download_file "${mingw_url}" "${mingw_w64}" "${mingw_toolchain}" "" "${mingw_url_backup}"
92
93 # Mark the tree as needing updates by deleting the folder
94 if test -d inplace/mingw && test inplace/mingw -ot "$mingw_w64" ; then
95 echo "In-tree MinGW-w64 tree requires updates..."
96 rm -rf inplace/mingw
97 fi
98 }
99
100 download_tarballs() {
101 local package_prefix="mingw-w64"
102 local format_url="/${mingw_arch}/${package_prefix}-${mingw_arch}"
103
104 download_mingw "${format_url}-crt-git-5.0.0.4795.e3d96cb1-1-any.pkg.tar.xz"
105 download_mingw "${format_url}-winpthreads-git-5.0.0.4850.d1662dc7-1-any.pkg.tar.xz"
106 download_mingw "${format_url}-headers-git-5.0.0.4966.1eee2140-1-any.pkg.tar.xz"
107 download_mingw "${format_url}-libwinpthread-git-5.0.0.4850.d1662dc7-1-any.pkg.tar.xz"
108 download_mingw "${format_url}-zlib-1.2.8-9-any.pkg.tar.xz"
109 download_mingw "${format_url}-isl-0.18-1-any.pkg.tar.xz"
110 download_mingw "${format_url}-mpfr-3.1.6-1-any.pkg.tar.xz"
111 download_mingw "${format_url}-gmp-6.1.2-1-any.pkg.tar.xz"
112 download_mingw "${format_url}-binutils-2.29.1-1-any.pkg.tar.xz"
113 download_mingw "${format_url}-libidn2-2.0.4-1-any.pkg.tar.xz"
114 download_mingw "${format_url}-gcc-7.2.0-1-any.pkg.tar.xz"
115
116 # Upstream is unfortunately quite inconsistent in naming
117 if test "$mingw_arch" != "sources"; then
118 download_mingw "${format_url}-mpc-1.0.3-2-any.pkg.tar.xz"
119 download_mingw "${format_url}-gcc-libs-7.2.0-1-any.pkg.tar.xz"
120 else
121 local format_url="${mingw_base_url}/${mingw_arch}/${package_prefix}"
122 download_mingw "${format_url}-i686-mpc-1.0.3-2.src.tar.gz"
123 download_mingw "${format_url}-x86_64-mpc-1.0.3-2.src.tar.gz"
124 fi
125
126 if ! test "$missing_files" = "0"
127 then
128 exit 2
129 fi
130 }
131
132 download_i386() {
133 mingw_arch="i686"
134 tarball_dest_dir="mingw-w64/x86"
135 download_tarballs
136 }
137
138 download_x86_64() {
139 mingw_arch="x86_64"
140 tarball_dest_dir="mingw-w64/x86_64"
141 download_tarballs
142 }
143
144 download_sources() {
145 mingw_arch="sources"
146 tarball_dest_dir="mingw-w64/sources"
147 download_tarballs
148 }
149
150 sync_binaries_and_sources() {
151 gpg --recv-key 5F92EFC1A47D45A1
152
153 # ensure sources are downloaded
154 sigs=1
155 download_i386
156 download_x86_64
157 verify=0
158 download_sources
159
160 for f in $($FIND ghc-tarballs/mingw-w64 -iname '*.sig'); do
161 echo "Verifying $f"
162 gpg --verify $f
163 done
164
165 md5sum `$FIND ghc-tarballs -type f -a -not -iname '*.sig'` >| mk/win32-tarballs.md5sum
166 chmod -R ugo+rX ghc-tarballs
167
168 rsync -av ghc-tarballs/mingw-w64/* downloads.haskell.org:public_html/mingw
169 for f in $($FIND ghc-tarballs/mingw-w64); do
170 curl -XPURGE http://downloads.haskell.org/~ghc/mingw/$f
171 done
172 }
173
174 show_hashes_for_binaries() {
175 $FIND ghc-tarballs/ -iname "*.*" | xargs md5sum | grep -v "\.sig" | sed -s "s/\*//"
176 }
177
178 usage() {
179 echo "$0 - Download GHC mingw toolchain tarballs"
180 echo
181 echo "Usage: $0 <action> [<arch>]"
182 echo
183 echo "Where <action> is one of,"
184 echo ""
185 echo " download download the necessary tarballs for the given architecture"
186 echo " fetch download the necessary tarballs for the given architecture but doesn't verify their md5."
187 echo " verify verify the existence and correctness of the necessary tarballs"
188 echo " hash generate md5 hashes for inclusion in win32-tarballs.md5sum"
189 echo " sync upload packages downloaded with 'fetch mirror' to haskell.org"
190 echo ""
191 echo "and <arch> is one of i386, x86_64,all or mirror (which includes sources)"
192 }
193
194 case $1 in
195 download)
196 download=1
197 verify=1
198 sigs=0
199 ;;
200 fetch)
201 download=1
202 verify=0
203 ;;
204 verify)
205 download=0
206 verify=1
207 ;;
208 sync)
209 download=1
210 verify=0
211 sync=1
212 ;;
213 hash)
214 show_hashes_for_binaries
215 exit 1
216 ;;
217 *)
218 usage
219 exit 1
220 ;;
221 esac
222
223 case $2 in
224 i386)
225 download_i386
226 ;;
227 x86_64)
228 download_x86_64
229 ;;
230 all)
231 download_i386
232 download_x86_64
233 ;;
234 mirror)
235 sigs=1
236 download_i386
237 download_x86_64
238 verify=0
239 download_sources
240 show_hashes_for_binaries
241 ;;
242 *)
243 if test "$sync" = "1"; then
244 sync_binaries_and_sources
245 else
246 usage
247 exit 1
248 fi
249 ;;
250 esac