#!/bin/bash

set -euo pipefail

v="0.14.0"

basedir="${0%/*}"
self="${0##*/}"

url="https://github.com/asdf-vm/asdf/archive/refs/tags/v$v.tar.gz"
dir="$basedir/.tmp"
bin="$dir/$self-$v/bin/$self"

if [ ! -x "$bin" ]
then
  rm -rf "$dir"
  mkdir -p "${dir}"
  curl -L "$url" | tar xfz - -C $dir
fi

export ASDF_DATA_DIR="$dir/asdf-data"

exec "$bin" "${@}"