Skip to content

Instantly share code, notes, and snippets.

@airtonix
Last active August 13, 2023 08:40
Show Gist options
  • Save airtonix/1031cd7b4e9745c73b385204f7a9688d to your computer and use it in GitHub Desktop.
Save airtonix/1031cd7b4e9745c73b385204f7a9688d to your computer and use it in GitHub Desktop.
General Purpose ASDF bootstrapper

ASDF Bootstrapper

faceroll tooling management.

Auto install plugins for tooling described in a .tool-versions file, then install the tooling.

First steps

  • copy setup.sh into the root of your project
  • chmod +x ./setup.sh
  • commit it
  • run it

Next Steps

  • determine your tooling: ie: node, rust and yarn
  • create a .tool-versions in your project (next to the ./setup.sh)
nodejs 18.17.0
rust 1.71.1
yarn 1.22.19
  • run setup.sh again
#!/usr/bin/env bash
#
# Custom plugins not found in the asdf-vm shortcode repo can be described with appropriate ENVAR:
#
# ASDF_PLUGINS=(nodejs pnpm bats) \
# ASDF_PLUGIN_URL_nodejs=https://some.url/for/your/plugin.git \
# ./setup.sh
#
set -e
[ $(command -v git) ] || {
echo "πŸ“›πŸ“¦ Missing git"
exit 1
}
[ $(command -v curl) ] || {
echo "πŸ“›πŸ“¦ Missing curl"
exit 1
}
# Local vars
ASDF_VERSION=${ASDF_VERSION:-v0.8.1}
ASDF_HOME=$HOME/.asdf
ASDF_BIN=$ASDF_HOME/asdf.sh
#
# Helper to idempotently add strings to target files
#
append_uniquely() {
if ! grep -q "$2" "$1"; then
echo "====> ✍ Writing \"$2\" into \"$1\" "
echo "${2}" >>$1
fi
}
case "${SHELL}" in
/bin/bash)
SHELL_PROFILE=~/.bashrc
SHELL_NAME="bash"
;;
/bin/zsh)
SHELL_PROFILE=~/.zshrc
SHELL_NAME="zsh"
;;
esac
echo "=> πŸ’ [ASDF] install with plugins"
if [ ! -f "$ASDF_BIN" ]; then
echo "===> ‡️ ASDF not detected ... installing"
git clone https://github.com/asdf-vm/asdf.git "$ASDF_HOME" --branch $ASDF_VERSION
[ ! command -v asdf ] &>/dev/null && {
echo "====> βš•οΈ adding to shell profile"
append_uniquely "$SHELL_PROFILE" ". $ASDF_HOME/asdf.sh"
append_uniquely "$SHELL_PROFILE" ". $ASDF_HOME/completions/asdf.bash"
}
fi
source "$ASDF_BIN"
for plugin in $(cut -d' ' -f1 ./.tool-versions)
do
echo "
==> πŸ’ [ASDF] Ensure ${plugin} plugin"
if [ -d "$ASDF_HOME/plugins/${plugin}" ]; then
echo "===> πŸ“¦ attempting upgrade"
asdf plugin-update "${plugin}"
else
echo "===> 🌐 installing"
plugin_url_var=ASDF_PLUGIN_URL_${plugin//-/_}
plugin_url="${!plugin_url_var}"
if [ ${!plugin_url_var+x} ]; then
echo "====> πŸ’ [${plugin}] installed from ${plugin_url}"
fi
asdf plugin-add "${plugin}" "${plugin_url}"
fi
done
echo "==> πŸ’ [ASDF] install tools"
asdf install
echo "==> πŸ’ [ASDF] reshim globals"
asdf reshim
echo "==> πŸ’ [ASDF] Done βœ…"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment