| 1 | #!/bin/sh |
| 2 | # The compiler that builds src/: the release BOOT names, by its tag and |
| 3 | # its tarball's SHA-256. A release's tarball is the same, byte for byte, |
| 4 | # wherever it is made (the Makefile's dist), so the sum pins the very |
| 5 | # compiler; and since that release was built by the one before it, back |
| 6 | # to v0.19.0, which the Pascal seed built (git has it at that tag), |
| 7 | # raz can always be built again from source alone. |
| 8 | # |
| 9 | # The tarball is taken from build/boot/ if it is there; else from the |
| 10 | # website's downloads in this checkout, site/public/download/, where |
| 11 | # every release is kept; else from the GitHub release, by curl, or by |
| 12 | # gh's REST API where the repository is private and gh has a token; else |
| 13 | # from the website, which serves the same bytes. A machine with no |
| 14 | # network and no site/public has it put there by hand. The sum is |
| 15 | # checked whichever it came from. Its raz goes to build/boot/raz, with |
| 16 | # this repository's lib/ beside it, since src/ is built against today's |
| 17 | # library. Run from the repository root, by make. |
| 18 | set -e |
| 19 | read tag sum < BOOT |
| 20 | v=${tag#v} |
| 21 | t=raz-$v-linux-x86_64.tar.gz |
| 22 | d=build/boot |
| 23 | repo=ldiaz94/raz |
| 24 | mkdir -p $d |
| 25 | if [ ! -f $d/$t ] && [ -f site/public/download/$t ]; then |
| 26 | cp site/public/download/$t $d/$t |
| 27 | fi |
| 28 | if [ ! -f $d/$t ]; then |
| 29 | if ! curl -fsSL -o $d/$t https://github.com/$repo/releases/download/$tag/$t 2>/dev/null; then |
| 30 | id=$(gh api repos/$repo/releases/tags/$tag --jq ".assets[] | select(.name == \"$t\") | .id" 2>/dev/null) && |
| 31 | [ -n "$id" ] && |
| 32 | gh api -H 'Accept: application/octet-stream' repos/$repo/releases/assets/$id >$d/$t 2>/dev/null || |
| 33 | curl -fsSL -o $d/$t https://raz.lucela.org/download/$t 2>/dev/null || |
| 34 | { rm -f $d/$t; echo "boot: can't fetch $t; put it in $d" >&2; exit 1; } |
| 35 | fi |
| 36 | fi |
| 37 | # macOS has shasum, not sha256sum |
| 38 | if command -v sha256sum >/dev/null; then got=$(sha256sum < $d/$t); else got=$(shasum -a 256 < $d/$t); fi |
| 39 | if [ "${got%% *}" != "$sum" ]; then |
| 40 | echo "boot: $d/$t isn't $tag's tarball: its SHA-256 isn't BOOT's" >&2 |
| 41 | exit 1 |
| 42 | fi |
| 43 | rm -rf $d/raz-$v-linux-x86_64 |
| 44 | tar -xzf $d/$t -C $d |
| 45 | cp $d/raz-$v-linux-x86_64/raz $d/raz |
| 46 | ln -sfn ../../lib $d/lib |