AtlatestRepositorycore-channel

core-channel / treebootstrap

1#!/bin/sh
2set -eu
3
4root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
5
6fetch() {
7 manifest=$1
8 base=$2
9 override=${3:-}
11 while IFS=' ' read -r expected url file rest; do
12 case "$expected" in ''|'#'*) continue ;; esac
13 [ -z "${rest:-}" ] || { echo "bootstrap: malformed manifest row: $manifest" >&2; exit 1; }
14 target="$base/$file"
15 source=$url
16 [ -z "$override" ] || source=$override
17 mkdir -p "$(dirname -- "$target")"
19 if [ -f "$target" ]; then
20 actual=$(sha256sum "$target" | awk '{print $1}')
21 [ "$actual" = "$expected" ] && continue
22 echo "bootstrap: cached hash mismatch, fetching $file again" >&2
23 fi
25 tmp="$target.part.$$"
26 rm -f "$tmp"
27 trap 'rm -f "$tmp"' EXIT HUP INT TERM
28 if command -v curl >/dev/null 2>&1; then
29 curl --fail --location --silent --show-error "$source" --output "$tmp"
30 elif command -v wget >/dev/null 2>&1; then
31 wget -q "$source" -O "$tmp"
32 else
33 echo "bootstrap: curl or wget is required" >&2
34 exit 1
35 fi
36 actual=$(sha256sum "$tmp" | awk '{print $1}')
37 [ "$actual" = "$expected" ] || {
38 echo "bootstrap: REFUSING $file: sha256 mismatch; expected $expected, got $actual" >&2
39 exit 1
40 }
41 mv "$tmp" "$target"
42 trap - EXIT HUP INT TERM
43 done < "$manifest"
46fetch "$root/seed/MANIFEST" "$root/seed" "${SIGIL_BOOTSTRAP_SEED_URL:-}"
47fetch "$root/toolchain/MANIFEST" "$root/toolchain" "${SIGIL_BOOTSTRAP_ZIG_URL:-}"
48"$root/toolchain/setup.sh"
49echo "bootstrap: channel ready at $root"