raz / src / boot.sh

46 lines · 2.1 KiB · executable · raw · history · last change de634aad

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.
18set -e
19read tag sum < BOOT
20v=${tag#v}
21t=raz-$v-linux-x86_64.tar.gz
22d=build/boot
23repo=ldiaz94/raz
24mkdir -p $d
25if [ ! -f $d/$t ] && [ -f site/public/download/$t ]; then
26 cp site/public/download/$t $d/$t
27fi
28if [ ! -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
36fi
37# macOS has shasum, not sha256sum
38if command -v sha256sum >/dev/null; then got=$(sha256sum < $d/$t); else got=$(shasum -a 256 < $d/$t); fi
39if [ "${got%% *}" != "$sum" ]; then
40 echo "boot: $d/$t isn't $tag's tarball: its SHA-256 isn't BOOT's" >&2
41 exit 1
42fi
43rm -rf $d/raz-$v-linux-x86_64
44tar -xzf $d/$t -C $d
45cp $d/raz-$v-linux-x86_64/raz $d/raz
46ln -sfn ../../lib $d/lib