Created
January 6, 2022 14:53
-
-
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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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