#!/usr/bin/env bash
set -euo pipefail

export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
if ! command -v rustup >/dev/null; then
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
fi
toolchain="$(sed -n 's/^channel = "\([^"]*\)"/\1/p' rust-toolchain.toml)"
rustup toolchain install "$toolchain" --profile minimal --component rust-src,rustfmt --target wasm32-unknown-unknown
if ! command -v wasm-pack >/dev/null; then
    cargo install wasm-pack --version 0.15.0 --locked
fi
if ! command -v go >/dev/null; then
    sudo apt-get update -qq
    sudo apt-get install -y golang-go
fi
if ! command -v git-lfs >/dev/null; then
    sudo apt-get update -qq
    sudo apt-get install -y git-lfs
fi
git lfs install --local
git lfs pull --include="docs/public/models/sponza.glb"
npm ci
amp orb services ensure
