Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kkirsche
Created February 11, 2022 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkirsche/c0da32873ef2cbd94996617677369c90 to your computer and use it in GitHub Desktop.
Save kkirsche/c0da32873ef2cbd94996617677369c90 to your computer and use it in GitHub Desktop.
ASDF Version Checker / Updater
#!/usr/bin/env bash
set -eu -o pipefail;
function check {
PLUGINS=$(asdf plugin list)
echo "Plugin Current Latest"
for plugin in ${PLUGINS}; do
LATEST_VERSION=$(asdf latest ${plugin})
CURRENT_VERSION=$(asdf current ${plugin}| perl -lne 'print $& if /((\d+\.){2}\d+(-otp-\d+)?)/')
if [[ "${LATEST_VERSION}" != "${CURRENT_VERSION}" ]]; then
echo "${plugin} ${CURRENT_VERSION} ${LATEST_VERSION}"
fi
done
}
function update {
PLUGINS=$(asdf plugin list)
for plugin in ${PLUGINS}; do
if [[ ${plugin} == "nodejs" ]]; then
continue
fi
LATEST_VERSION=$(asdf latest ${plugin})
CURRENT_VERSION=$(asdf current ${plugin}| perl -lne 'print $& if /((\d+\.){2}\d+(-otp-\d+)?)/')
if [[ "${LATEST_VERSION}" != "${CURRENT_VERSION}" ]]; then
echo "Installing ${plugin} ${LATEST_VERSION}"
asdf install ${plugin} ${LATEST_VERSION}
echo "Setting global ${plugin} version to ${LATEST_VERSION}"
asdf global ${plugin} ${LATEST_VERSION}
echo "Uninstalling ${plugin} ${CURRENT_VERSION}"
asdf uninstall ${plugin} ${CURRENT_VERSION}
fi
done
}
echo "Checking for outdated versions…"
check | column -t -s' '
echo "Updating outdated versions…"
update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment