103 lines
3.7 KiB
Bash
Executable File
103 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Bootstrap the pinned toolchain (Calepin + Typst) into tools/.
|
|
# Idempotent: skips downloads when the binaries are already in place.
|
|
# Supports x86_64 Linux and Windows (run through Git Bash / MSYS2).
|
|
set -euo pipefail
|
|
|
|
# Pinned toolchain -- bump both binaries together and re-verify checksums.
|
|
calepin_version="0.0.61"
|
|
typst_version="0.15.1"
|
|
# Typst publishes no .sha256 assets; these digests come from the official
|
|
# release metadata (GitHub asset digests of the downloads below).
|
|
typst_sha256_linux="a6d077d0a95eed5a2eba715b2dae06be954f624ccbf85758a03f389ded33118c"
|
|
typst_sha256_windows="19ce3551153c2fe7ee9fa2f95208310c8f4d3209fedb699e0333faf8913f6736"
|
|
|
|
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
tools="$root/tools"
|
|
|
|
if [ "$(uname -m)" != "x86_64" ]; then
|
|
echo "error: unsupported architecture $(uname -m), pinned binaries are x86_64" >&2
|
|
exit 1
|
|
fi
|
|
|
|
case "$(uname -s)" in
|
|
Linux*)
|
|
exe=""
|
|
calepin_name="calepin-x86_64-unknown-linux-gnu.tar.xz"
|
|
typst_name="typst-x86_64-unknown-linux-musl.tar.xz"
|
|
typst_sha256="$typst_sha256_linux"
|
|
;;
|
|
MINGW*|MSYS*|CYGWIN*)
|
|
exe=".exe"
|
|
calepin_name="calepin-x86_64-pc-windows-msvc.zip"
|
|
typst_name="typst-x86_64-pc-windows-msvc.zip"
|
|
typst_sha256="$typst_sha256_windows"
|
|
;;
|
|
*)
|
|
echo "error: unsupported operating system $(uname -s)" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Extract a single binary from a zip into tools/. The zip may or may not nest
|
|
# it in a top-level directory. Git Bash ships no unzip, so fall back to the
|
|
# bsdtar.exe bundled with Windows 10+.
|
|
install_zip_binary() {
|
|
local archive="$1" bin="$2"
|
|
local tmp="$tools/.extract"
|
|
rm -rf "$tmp"
|
|
mkdir -p "$tmp"
|
|
if command -v unzip >/dev/null 2>&1; then
|
|
unzip -q -o "$archive" -d "$tmp"
|
|
else
|
|
local wintar=""
|
|
if command -v cygpath >/dev/null 2>&1; then
|
|
wintar="$(cygpath -u "${SYSTEMROOT:-C:/Windows}")/System32/tar.exe"
|
|
fi
|
|
if [ -z "$wintar" ] || [ ! -x "$wintar" ]; then
|
|
echo "error: extracting $archive needs unzip or Windows tar.exe" >&2
|
|
return 1
|
|
fi
|
|
"$wintar" -xf "$archive" -C "$tmp"
|
|
fi
|
|
local found
|
|
found="$(find "$tmp" -type f -name "$bin" -print -quit)"
|
|
if [ -z "$found" ]; then
|
|
echo "error: $bin not found in $archive" >&2
|
|
return 1
|
|
fi
|
|
mv "$found" "$tools/$bin"
|
|
rm -rf "$tmp"
|
|
}
|
|
|
|
mkdir -p "$tools"
|
|
|
|
if [ ! -x "$tools/calepin$exe" ]; then
|
|
# Calepin publishes .sha256 assets next to its downloads.
|
|
base="https://github.com/vincentarelbundock/calepin/releases/download/v$calepin_version"
|
|
curl -fsSLo "$tools/$calepin_name" "$base/$calepin_name"
|
|
curl -fsSLo "$tools/$calepin_name.sha256" "$base/$calepin_name.sha256"
|
|
(cd "$tools" && sha256sum -c "$calepin_name.sha256")
|
|
if [ "$exe" ]; then
|
|
install_zip_binary "$tools/$calepin_name" "calepin.exe"
|
|
else
|
|
tar -xJf "$tools/$calepin_name" -C "$tools" --strip-components=1 "${calepin_name%.tar.xz}/calepin"
|
|
fi
|
|
rm "$tools/$calepin_name" "$tools/$calepin_name.sha256"
|
|
fi
|
|
|
|
if [ ! -x "$tools/typst$exe" ]; then
|
|
curl -fsSLo "$tools/$typst_name" "https://github.com/typst/typst/releases/download/v$typst_version/$typst_name"
|
|
echo "$typst_sha256 $typst_name" > "$tools/$typst_name.sha256"
|
|
(cd "$tools" && sha256sum -c "$typst_name.sha256")
|
|
if [ "$exe" ]; then
|
|
install_zip_binary "$tools/$typst_name" "typst.exe"
|
|
else
|
|
tar -xJf "$tools/$typst_name" -C "$tools" --strip-components=1 "${typst_name%.tar.xz}/typst"
|
|
fi
|
|
rm "$tools/$typst_name" "$tools/$typst_name.sha256"
|
|
fi
|
|
|
|
"$tools/calepin$exe" --version
|
|
"$tools/typst$exe" --version
|