get go by minor

This commit is contained in:
2023-04-07 07:25:53 -04:00
parent f75a27c89f
commit 27fbca8f75

View File

@@ -6,7 +6,7 @@ list_versions() {
} }
install_version() { install_version() {
check_valid $1 check_valid_patch $1
if [[ $valid != 'true' ]]; then if [[ $valid != 'true' ]]; then
echo "invalid version $1" echo "invalid version $1"
echo "using $(go version)" echo "using $(go version)"
@@ -31,7 +31,13 @@ link_version() {
fi fi
} }
check_valid() { check_valid_minor() {
if [[ $1 =~ go1\.[0-9]{1,2} ]]; then
valid='true'
fi
}
check_valid_patch() {
if [[ $1 =~ go1\.[0-9]{1,2}\.[0-9]{1,2} ]]; then if [[ $1 =~ go1\.[0-9]{1,2}\.[0-9]{1,2} ]]; then
valid='true' valid='true'
fi fi
@@ -57,10 +63,20 @@ remove_version() {
fi fi
} }
get_latest_patch_for_minor() {
version=$(curl -s "https://go.dev/dl/?mode=json" | grep -o "$1.*.linux-amd64.tar.gz" | head -n 1 | tr -d '\r\n' | sed 's/[.]linux-amd64[.]tar[.]gz//')
if [[ $version == '' ]]; then
echo "could not determine latest version for $1. Only n-1 are supported by this feature."
exit 1
else
echo "latest $1 patch: $version"
fi
}
prompt_install() { prompt_install() {
echo "$1 not found in $HOME/.go" echo "$1 not found in $HOME/.go"
list_versions list_versions
check_valid $1 check_valid_patch $1
if [[ $valid == 'true' ]]; then if [[ $valid == 'true' ]]; then
echo "attempt to download and install? [y/n]" echo "attempt to download and install? [y/n]"
@@ -68,11 +84,22 @@ prompt_install() {
if [[ $input == 'y' ]]; then if [[ $input == 'y' ]]; then
install_version $1 install_version $1
fi fi
else
check_valid_minor $1
if [[ $valid == 'true' ]]; then
get_latest_patch_for_minor $1
check_exists $version
if [[ $exists == 'true' ]]; then
link_version $version
else
prompt_install $version
fi
else else
echo "invalid version $1" echo "invalid version $1"
echo "using $(go version)" echo "using $(go version)"
exit 1 exit 1
fi fi
fi
} }
mkdir -p "$HOME/.go/downloads" mkdir -p "$HOME/.go/downloads"
@@ -89,6 +116,8 @@ fi
valid='false' valid='false'
exists='false' exists='false'
version=''
check_exists $1 check_exists $1
if [[ $1 == '' ]]; then if [[ $1 == '' ]]; then
list_versions list_versions