#!/usr/bin/env bash

# a development environment setup tool.
sudo apt update -qq && sudo apt install -y curl

# sudo install -dm 755 /etc/apt/keyrings
DEST=${1:-/etc/skel}
URI="https://mise.jdx.dev"
KEY_DIR="/usr/share/keyrings"
KEY="${KEY_DIR}/mise-archive-keyring.asc"

curl -fSs ${URI}/gpg-key.pub | sudo tee ${KEY} 1>/dev/null

conf_print_sources() {
  cat <<EOF
Types: deb
URIs: ${URI}/deb/
Suites: stable
Components: main
Signed-By: ${KEY}
EOF
}
conf_print_sources | sudo tee /etc/apt/sources.list-available/mise.sources
sudo ln -sf /etc/apt/sources.list-available/mise.sources /etc/apt/sources.list.d/mise.sources
sudo apt update -qq
sudo apt install -y mise

echo 'eval "$(/usr/bin/mise activate zsh)"' >${DEST}/.zshrc.d/004_mise.zsh
