#!/bin/bash

mkdir -p ~/install/tilt ~/.local/bin
cd ~/install/tilt

KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check
chmod +x kubectl
cp ./kubectl ~/.local/bin/kubectl

################################################################################

CTLPTL_URL=$(curl -s "https://api.github.com/repos/tilt-dev/ctlptl/releases/latest" \
    | jq -r '.assets.[] | select(.name | test("linux.x86_64.tar.gz")).browser_download_url')

curl -fsSL "$CTLPTL_URL" | tar -xz -C ~/.local/bin ctlptl
# chmod +x ~/.local/bin/ctlptl

################################################################################

TILT_URL=$(curl -s "https://api.github.com/repos/tilt-dev/tilt/releases/latest" \
    | jq -r '.assets.[] | select(.name | test("linux.x86_64.tar.gz")).browser_download_url')

curl -fsSL "$TILT_URL" | tar -xz -C ~/.local/bin tilt
# chmod +x ~/.local/bin/tilt
cd -

echo "Version of ctlptl = $(ctlptl version)"
echo "Version of tilt = $(tilt version)"
echo "Version of kubectl:"
kubectl version
