#!/usr/bin/env bash
set -euxo pipefail
# Pin by hash, updates should update both fields
version=1.29.0
target=x86_64-unknown-linux-gnu
sha256=4acc9acc76d5079515b46346a485974457b5a79893cfb01112423c89aeb5aa10
# Already installed -- rustup verifies its own toolchain downloads from here on.
if [[ -e ~/.cargo/env ]]; then
exit 0
fi
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
curl \
--proto '=https' \
--tlsv1.2 \
-sSf \
-o "$tmp/rustup-init" \
"https://static.rust-lang.org/rustup/archive/$version/$target/rustup-init"
echo "$sha256 $tmp/rustup-init" | sha256sum --check --strict -
chmod +x "$tmp/rustup-init"
"$tmp/rustup-init" -y