#!/bin/sh
# dhai r6s stage 0, served publicly at https://r6.dhai.uk (Cloudflare Worker, verified TLS). No secrets.
# Typed by davidad at an R6S console after the on-card bootstrap set up Wi-Fi:  curl -fsSL https://r6.dhai.uk | sudo sh
# Fetches the fixed bootstrap from the same Worker, checks its sha256, runs it (role from the hostname; Wi-Fi kept).
set -eu
W=e25f5a23d25ffbf8a0da98f89c0680353ede90d268e955dac12324733d0615ea
[ "$(id -u)" = 0 ] || { echo "r6s: FAILED: not root"; echo "r6s: next: type the line exactly, ending in | sudo sh"; exit 1; }
T=$(mktemp /tmp/r6s-bootstrap.XXXXXX); trap 'rm -f "$T"' EXIT
echo "r6s: fetching the fixed bootstrap from r6.dhai.uk"
curl -fsS --max-time 30 --retry 3 --retry-delay 2 -o "$T" https://r6.dhai.uk/bootstrap.sh || { echo "r6s: FAILED: could not fetch https://r6.dhai.uk/bootstrap.sh"; echo "r6s: next: photo of this screen to dhai"; exit 1; }
G=$(sha256sum "$T" | cut -c1-64)
[ "$G" = "$W" ] || { echo "r6s: FAILED: bootstrap checksum $G is not the expected $W"; echo "r6s: next: photo of this screen to dhai"; exit 1; }
sh "$T" "$@" </dev/tty
