Last active
December 6, 2019 19:33
-
-
Save wshearn/74cb727ccfcb44e59889d63db2551abc to your computer and use it in GitHub Desktop.
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 | |
set -e | |
usage() | |
{ | |
echo "GVM is a simple golang version manager written in bash." | |
echo "$(basename $0) -v <version>" | |
} | |
while getopts ":v:h" opt; do | |
case ${opt} in | |
h) | |
usage | |
exit 0 | |
;; | |
v) | |
WANTED=${OPTARG} | |
;; | |
esac | |
done | |
if [[ -z ${WANTED} ]]; then | |
usage | |
exit 1 | |
fi | |
if [[ ! -d ${HOME}/sdk/go${WANTED} ]]; then | |
echo "Runtime not found. Installing..." | |
go get golang.org/dl/go${WANTED} | |
go${WANTED} download | |
fi | |
pushd ${HOME}/sdk > /dev/null | |
rm -f active | |
ln -s go${WANTED} active | |
popd > /dev/null | |
if [[ ${PATH} != *"${HOME}/sdk/active/bin"* ]]; then | |
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" | |
echo "Runtime set, add it to your path" | |
echo "export PATH=\${PATH}:\${HOME}/sdk/active/bin" | |
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple usage: