#!/bin/sh # Install the talaria CLI from a GitHub release, verified against the # release's checksums.txt (goreleaser `checksum.name_template`, sha256) # before anything is installed. Falls back to `go install` only when the # release has no archive for this platform; a checksum that is missing or # does not match always stops the install (fail closed). # # curl -fsSL https://get.newtalaria.com/cli | sh # # Env: # TALARIA_INSTALL_DIR install directory (default ~/.local/bin) # TALARIA_VERSION release tag, e.g. v0.1.0 (default: latest) # TALARIA_RELEASE_URL download base override (mirrors, testing); the # archive and checksums.txt are read from it set -eu repo="dunatron/new_talaria" bin="talaria" os=$(uname -s | tr '[:upper:]' '[:lower:]') arch=$(uname -m) case "$arch" in x86_64) arch=amd64 ;; aarch64|arm64) arch=arm64 ;; esac case "$os" in linux|darwin) ext="tar.gz" ;; mingw*|msys*|cygwin*) os="windows"; ext="zip" ;; *) echo "unsupported OS ${os}" >&2; exit 1 ;; esac dest="${TALARIA_INSTALL_DIR:-${HOME}/.local/bin}" if [ -n "${TALARIA_RELEASE_URL:-}" ]; then base="${TALARIA_RELEASE_URL%/}" elif [ -n "${TALARIA_VERSION:-}" ]; then base="https://github.com/${repo}/releases/download/${TALARIA_VERSION}" else base="https://github.com/${repo}/releases/latest/download" fi # goreleaser archives.name_template: {{ .ProjectName }}_{{ .Os }}_{{ .Arch }} asset="talaria_${os}_${arch}.${ext}" sums="checksums.txt" sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | awk '{print $1}' else shasum -a 256 "$1" | awk '{print $1}' fi } fetch() { # fetch if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" -o "$2" elif command -v wget >/dev/null 2>&1; then wget -qO "$2" "$1" else return 2 fi } go_fallback() { if command -v go >/dev/null 2>&1; then mkdir -p "$dest" GOBIN="$dest" go install "github.com/${repo}/cli/cmd/talaria@latest" echo "installed ${dest}/${bin} via go install" exit 0 fi echo "No GitHub release archive (${asset}) and no Go toolchain. Build from the repo: make -C cli install" >&2 exit 1 } tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then echo "need curl or wget" >&2 go_fallback fi if ! fetch "${base}/${asset}" "${tmp}/${asset}" 2>/dev/null; then go_fallback fi # From here on the release exists: never fall back, never install unverified. if ! command -v sha256sum >/dev/null 2>&1 && ! command -v shasum >/dev/null 2>&1; then echo "need sha256sum or shasum to verify ${asset}; nothing installed" >&2 exit 1 fi if ! fetch "${base}/${sums}" "${tmp}/${sums}" 2>/dev/null; then echo "could not download ${sums} for ${asset}; refusing to install unverified" >&2 exit 1 fi want=$(awk -v f="$asset" '$2 == f || $2 == "*" f {print $1; exit}' "${tmp}/${sums}") if [ -z "$want" ]; then echo "${asset} is not listed in ${sums}; refusing to install unverified" >&2 exit 1 fi got=$(sha256 "${tmp}/${asset}") if [ "$got" != "$want" ]; then echo "checksum mismatch for ${asset}; nothing installed" >&2 echo "want ${want}" >&2 echo "got ${got}" >&2 exit 1 fi mkdir -p "${tmp}/x" if [ "$ext" = "zip" ]; then unzip -q "${tmp}/${asset}" -d "${tmp}/x" bin="talaria.exe" else tar -xzf "${tmp}/${asset}" -C "${tmp}/x" fi if [ ! -f "${tmp}/x/${bin}" ]; then echo "archive ${asset} did not contain ${bin}" >&2 exit 1 fi mkdir -p "$dest" cp "${tmp}/x/${bin}" "${dest}/${bin}.new" chmod 0755 "${dest}/${bin}.new" mv -f "${dest}/${bin}.new" "${dest}/${bin}" echo "installed ${dest}/${bin} (${asset}, sha256 verified)" # TALARIA_INIT=1 runs app init in the current directory after a verified # install. A failed init does not remove the binary (D19). if [ "${TALARIA_INIT:-}" = "1" ]; then if ! "${dest}/${bin}" init --yes; then echo "talaria is installed. init did not finish. Run talaria init --yes in the project." >&2 fi fi