Created
October 10, 2022 14:39
-
-
Save comdotlinux/17cb87a055f0e2873448a04397416c30 to your computer and use it in GitHub Desktop.
A Shell script to find and update tools in .tool-versions from asdf
This file contains 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 | |
SCRIPT_PATH=$(dirname "$0") | |
echo "-- adding plugins --" | |
grep -v '^ *#' < "$SCRIPT_PATH/.tool-versions" | while IFS= read -r line | |
do | |
asdf plugin add "$(echo "$line" | awk '{print $1}')" | |
done | |
echo "-- updating plugins --" | |
asdf plugin update --all | |
echo "-- installing currently used plugin versions --" | |
asdf install | |
INTERACTIVE=yes | |
if [[ $# -eq 1 ]] && [[ "x${1}" = "x-n" ]] ; then | |
INTERACTIVE=no | |
fi | |
if [[ "${INTERACTIVE}" = "yes" ]] ; then | |
read -r -n 1 -p "Make all current versions global? [Y/y/anyCharacterToSkip] : " ANSWER | |
fi | |
echo "" | |
if [[ "${INTERACTIVE}" = "no" ]] || [[ "x${ANSWER,,}" = "xy" ]] ; then | |
while IFS= read -r line | |
do | |
plugin_name=$(echo "${line}" | awk '{print $1}') | |
plugin_version=$(echo "${line}" | awk '{print $2}') | |
asdf global ${plugin_name} ${plugin_version} | |
done < <(grep -v '^ *#' < "${SCRIPT_PATH}/.tool-versions" | awk 'NF > 0') | |
fi | |
sleep 1 | |
if [[ "${INTERACTIVE}" = "yes" ]] ; then | |
read -r -n 1 -p "Check For Version Updates? [Y/y/anyCharacterToSkip] : " ANSWER | |
fi | |
echo "" | |
if [[ "${INTERACTIVE}" = "no" ]] || [[ "x${ANSWER,,}" = "xy" ]] ; then | |
echo "--- Update Notice! ----" | |
# shellcheck disable=SC2066 | |
update_command="sed -i" | |
while IFS= read -r line | |
do | |
plugin_name=$(echo "${line}" | awk '{print $1}') | |
plugin_version=$(echo "${line}" | awk '{print $2}') | |
if [[ "x${plugin_name}" == "xjava" ]] ; then | |
some_latest_versions=$(asdf list all "${plugin_name}" 2>&1 | grep "temurin-17" | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -3 | tr '\n' ' ') | |
the_latest_version=$(asdf list all "${plugin_name}" 2>&1 | grep "temurin-17" | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -1) | |
else | |
some_latest_versions=$(asdf list all "${plugin_name}" 2>&1 | grep -i -v beta | grep -i -v alpha | grep -v '${{PACKAGE_VERSION}}' | grep -i -v rc | grep -i -v pre-dev | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -3 | tr '\n' ' ') | |
the_latest_version=$(asdf list all "${plugin_name}" 2>&1 | grep -i -v beta | grep -i -v alpha | grep -v '${{PACKAGE_VERSION}}' | grep -i -v rc | grep -i -v pre-dev | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -1) | |
fi | |
echo "'${plugin_name}' currently using '${plugin_version}', some newer versions : ${some_latest_versions}" | |
if [[ "x${plugin_version}" != "x${the_latest_version}" ]] ; then | |
echo "'${plugin_name}' Update using: sed -i '/${plugin_name}/s/${plugin_version}/${the_latest_version}/' .tool-versions" | |
update_command="$update_command -e '/${plugin_name}/s/${plugin_version}/${the_latest_version}/'" | |
fi | |
echo "--" | |
done < <(grep -v '^ *#' < "${SCRIPT_PATH}/.tool-versions" | awk 'NF > 0') | |
echo "-- Or all in one go --" | |
echo "$update_command .tool-versions" | |
echo "--- Disclaimer! Only Update if you have time to test! ---" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment