blob: 79c5383207324f7eae5c58abe074c164130a72a1 [file] [log] [blame]
Brian Silverman7d89e282021-11-17 17:36:54 -08001#!/bin/bash
2
3set -euo pipefail
4
5use_github_host=0
6
7while getopts "v:gh" opt; do
8 case "$opt" in
9 "v") llvm_version="$OPTARG";;
10 "g") use_github_host=1;;
11 "h") echo "Usage:"
12 echo "-v - Version of clang+llvm to use"
13 echo "-g - Use github to download releases"
14 exit 2
15 ;;
16 "?") echo "invalid option: -$OPTARG"; exit 1;;
17 esac
18done
19
20if ! [[ "${llvm_version:-}" ]]; then
21 echo "Usage: ${BASH_SOURCE[0]} -v llvm_version"
22 exit 1
23fi
24
25tmp_dir="$(mktemp -d)"
26
27cleanup() {
28 rc=$?
29 rm -rf "${tmp_dir}"
30 exit $rc
31}
32trap 'cleanup' INT HUP QUIT TERM EXIT
33
34llvm_host() {
35 local url_base="releases.llvm.org/${llvm_version}"
36 output_dir="${tmp_dir}/${url_base}"
37 wget --compression gzip --recursive --level 1 --directory-prefix="${tmp_dir}" \
38 --accept-regex "clang%2bllvm.*tar.xz$" "http://${url_base}/"
39}
40
41github_host() {
42 output_dir="${tmp_dir}"
43 (
44 cd "${output_dir}"
45 curl -s "https://api.github.com/repos/llvm/llvm-project/releases/tags/llvmorg-${llvm_version}" | \
46 jq .assets[].browser_download_url | \
47 tee ./urls.txt | \
48 grep 'clang%2Bllvm.*tar.xz"$' | \
49 tee ./filtered_urls.txt | \
50 xargs -n1 curl -L -O
51 )
52}
53
54if (( use_github_host )); then
55 github_host
56else
57 llvm_host
58fi
59
60echo ""
61echo "===="
62echo "Checksums for clang+llvm distributions are:"
63find "${output_dir}" -type f -name '*.xz' -exec shasum -a 256 {} \; | \
64 sed -e "s@${output_dir}/@@" | \
65 awk '{ printf "\"%s\": \"%s\",\n", $2, $1 }'