set -euo pipefail
. "$(dirname "$0")/lib.sh"
[ "${ASDF_INSTALL_TYPE:-version}" = "version" ] ||
fail "only released versions can be installed, not refs — build from source with cargo instead"
version="${ASDF_INSTALL_VERSION:?ASDF_INSTALL_VERSION is not set}"
dest="${ASDF_DOWNLOAD_PATH:?ASDF_DOWNLOAD_PATH is not set}"
triple="$(target_triple)"
archive="meebis-${triple}.tar.xz"
url="$REPO/releases/download/v${version}/${archive}"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
echo "meebis: downloading $url"
fetch "$url" "$tmp/$archive" ||
fail "could not download v${version} for ${triple} — check that the version exists at $REPO/releases"
if fetch "$url.sha256" "$tmp/$archive.sha256" 2>/dev/null; then
want="$(cut -d' ' -f1 <"$tmp/$archive.sha256")"
got="$(sha256_of "$tmp/$archive")"
[ "$want" = "$got" ] || fail "checksum mismatch for $archive (expected $want, got $got)"
else
echo "meebis: warning: no published checksum for $archive — installing unverified" >&2
fi
mkdir -p "$dest"
tar -xJf "$tmp/$archive" -C "$dest" --strip-components=1 ||
fail "could not extract $archive (is xz support available to tar?)"
[ -f "$dest/meebis" ] || fail "the archive did not contain a meebis binary"