This commit is contained in:
2022-09-26 06:40:53 -04:00

View File

@@ -1,18 +1,6 @@
#!/bin/bash #!/bin/bash
uname_m=$(uname -m)
goarch='amd64'
if [[ $uname_m == 'arm64' || $uname_m == 'aarch64' ]]; then
goarch='arm64'
fi
goos='linux'
if [[ $(uname) == 'Darwin' ]]; then
goos='darwin'
fi
valid='false'
exists='false'
list_versions() { list_versions() {
echo "valid options:" echo "installed versions:"
for i in "$HOME"/.go/go1*; do basename "$i"; done for i in "$HOME"/.go/go1*; do basename "$i"; done
echo "" echo ""
} }
@@ -21,8 +9,7 @@ install_version() {
check_valid $1 check_valid $1
if [[ $valid != 'true' ]]; then if [[ $valid != 'true' ]]; then
echo "invalid version $1" echo "invalid version $1"
echo "using" echo "using $(go version)"
go version
exit 1 exit 1
fi fi
@@ -49,23 +36,28 @@ check_valid() {
valid='true' valid='true'
fi fi
} }
check_exists() { check_exists() {
if [[ -d $HOME/.go/$1 ]]; then if [[ -d $HOME/.go/$1 ]]; then
exists='true' exists='true'
fi fi
} }
check_exists $1 remove_version() {
if [[ $1 == '' ]]; then check_exists $1
list_versions if [[ $exists == 'true' ]]; then
echo "using" if [[ $current_link == $1 ]]; then
go version echo "cannot remove version $1 because it is currently in use"
exit 1 else
elif [[ $1 == 'install' ]]; then rm -rf $HOME/.go/$1
install_version $2 echo "removed version $1"
elif [[ $exists == 'true' ]]; then fi
link_version $1 else
else echo "version $1 not installed"
fi
}
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 $1
@@ -78,12 +70,48 @@ else
fi fi
else else
echo "invalid version $1" echo "invalid version $1"
echo "using" echo "using $(go version)"
go version
exit 1 exit 1
fi fi
}
mkdir -p "$HOME/.go/downloads"
current_link=$(basename $(readlink $HOME/.go/go))
uname_m=$(uname -m)
goarch='amd64'
if [[ $uname_m == 'arm64' || $uname_m == 'aarch64' ]]; then
goarch='arm64'
fi
goos='linux'
if [[ $(uname) == 'Darwin' ]]; then
goos='darwin'
fi
valid='false'
exists='false'
check_exists $1
if [[ $1 == '' ]]; then
list_versions
elif [[ $1 == 'list' ]]; then
list_versions
elif [[ $1 == 'remove' ]]; then
remove_version $2
elif [[ $1 == 'uninstall' ]]; then
remove_version $2
elif [[ $1 == 'install' ]]; then
install_version $2
elif [[ $1 == 'use' ]]; then
check_exists $2
if [[ $exists == true ]]; then
link_version $2
else
prompt_install $2
fi
elif [[ $exists == 'true' ]]; then
link_version $1
else
prompt_install $1
fi fi
echo "using" echo "using $(go version)"
go version