AtlatestRepositorycore-channel
core-channel / treebootstrap
1
#!/bin/sh2
set -eu4
root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)6
fetch() {7
manifest=$18
base=$29
override=${3:-}11
while IFS=' ' read -r expected url file rest; do12
case "$expected" in ''|'#'*) continue ;; esac13
[ -z "${rest:-}" ] || { echo "bootstrap: malformed manifest row: $manifest" >&2; exit 1; }14
target="$base/$file"15
source=$url16
[ -z "$override" ] || source=$override17
mkdir -p "$(dirname -- "$target")"19
if [ -f "$target" ]; then20
actual=$(sha256sum "$target" | awk '{print $1}')21
[ "$actual" = "$expected" ] && continue22
echo "bootstrap: cached hash mismatch, fetching $file again" >&223
fi25
tmp="$target.part.$$"26
rm -f "$tmp"27
trap 'rm -f "$tmp"' EXIT HUP INT TERM28
if command -v curl >/dev/null 2>&1; then29
curl --fail --location --silent --show-error "$source" --output "$tmp"30
elif command -v wget >/dev/null 2>&1; then31
wget -q "$source" -O "$tmp"32
else33
echo "bootstrap: curl or wget is required" >&234
exit 135
fi36
actual=$(sha256sum "$tmp" | awk '{print $1}')37
[ "$actual" = "$expected" ] || {38
echo "bootstrap: REFUSING $file: sha256 mismatch; expected $expected, got $actual" >&239
exit 140
}41
mv "$tmp" "$target"42
trap - EXIT HUP INT TERM43
done < "$manifest"44
}46
fetch "$root/seed/MANIFEST" "$root/seed" "${SIGIL_BOOTSTRAP_SEED_URL:-}"47
fetch "$root/toolchain/MANIFEST" "$root/toolchain" "${SIGIL_BOOTSTRAP_ZIG_URL:-}"48
"$root/toolchain/setup.sh"49
echo "bootstrap: channel ready at $root"