Skip to content

Instantly share code, notes, and snippets.

@scgilardi
Created January 6, 2022 14:53
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 scgilardi/6f0f8516e00898fdae937d92d02cd92e to your computer and use it in GitHub Desktop.
Save scgilardi/6f0f8516e00898fdae937d92d02cd92e to your computer and use it in GitHub Desktop.
Script to install "latest" (or other "desired") version of all asdf plugins and make them "current"
#!/usr/bin/env bash
# adapted from:
# https://gist.github.com/developer-guy/4de4e2ff2eaa31633a0fef719c92eada
# 2021-12-18
function update() {
asdf update > /dev/null 2>&1
echo asdf `asdf --version`
for i in `asdf plugin list`; do
CURRENT_VERSION=`asdf current $i | awk '{print $2}'`
echo "$i $CURRENT_VERSION"
DESIRED_VERSION=`desired_version $i`
if [ -n "$DESIRED_VERSION" ]; then
if [[ $(semver_check $DESIRED_VERSION $CURRENT_VERSION) -gt 0 ]]; then
echo " Installing $i $DESIRED_VERSION"
asdf install $i $DESIRED_VERSION
echo " Setting global $i to $DESIRED_VERSION"
asdf global $i $DESIRED_VERSION
fi
else
echo " (no desired version specified)"
fi
done
}
function desired_version () {
case $1 in
java)
asdf list all java | grep "zulu-\d" | sort -V | tail -1
;;
rust)
echo stable
;;
*)
asdf latest $1 2> /dev/null
;;
esac
}
function semver_check() {
# sort low->high then pick the last one (highest)
local HV; HV=$(echo -e "$1\n$2" |sort -V |tail -1)
# They're not the same and $1 is not the high version = -1
[[ "$1" != "$2" && "$1" != "$HV" ]] && echo -1 && return
# 0 = they're the same; 1 = not the same
[[ "$1" == "$2" ]]; echo $?
}
function main() {
update
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment