-
-
Save marcojahn/2cb6e7e878fc19de63de77efaf17e85e to your computer and use it in GitHub Desktop.
Update asdf plugins to their latest versions if necessary
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 sh | |
function update() { | |
for i in `asdf plugin list` | |
do | |
CURRENT_VERSION=`asdf current $i | awk '{print $2}'` | |
LATEST_VERSION=`asdf latest $i` | |
echo "Working with $i current version $CURRENT_VERSION but latest version is $LATEST_VERSION" | |
if [[ $(semver_check $LATEST_VERSION $CURRENT_VERSION) -lt 0 ]]; then | |
echo "Needs to update" | |
asdf install $i $LATEST_VERSION | |
echo "Prearing global value of $i is $LATEST_VERSION" | |
asdf global $i $LATEST_VERSION | |
else | |
echo "No need to update $i." | |
fi | |
done | |
} | |
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