Created
March 6, 2018 05:48
-
-
Save someburner/c86bef2352d83b46ffe754c689f08d62 to your computer and use it in GitHub Desktop.
install go
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
#!/bin/bash | |
TARNAME="go1.10.linux-amd64" | |
PREFIX=/usr/local | |
ensure_root() { if [[ "$EUID" -ne 0 ]]; then echo "Please run with sudo"; exit 1; fi } | |
ensure_root; | |
if [[ -f $TARNAME.tar.gz ]]; then | |
echo "$TARNAME.tar.gz exists."; | |
echo "_IF_ you wish to _re_download, _then_ press ctrl+c and delete the file first."; | |
sleep 1; echo '.'; sleep 1; echo '.'; echo "using $TARNAME.tar.gz"; | |
else | |
wget https://dl.google.com/go/$TARNAME.tar.gz | |
! [[ $? -eq 0 ]] && rm -f $TARNAME.tar.gz && echo "Download failed" && exit 1; | |
fi | |
if [[ -d $PREFIX/go ]]; then | |
echo "$PREFIX/go exists. Please remove it first if you wish to reinstall"; | |
exit 1; | |
else | |
tar -C /usr/local -xzf $TARNAME.tar.gz | |
fi | |
source $HOME/.bashrc | |
if [[ -z "$(cat $HOME/.bashrc | grep in_path)" ]]; then | |
echo 'Adding utils to path' | |
echo 'in_path() { echo "$PATH"|grep -q "$1" && echo "Found $1" && return 0; return 1; }' >> $HOME/.bashrc; | |
echo 'add_to_path() { in_path "$1"; if ! [[ $? -eq 0 ]]; then export PATH=$PATH:$1; fi; }' >> $HOME/.bashrc; | |
echo 'add_to_path "/usr/local/go/bin"' >> $HOME/.bashrc | |
fi | |
echo "done"; | |
echo 'Please manually run the following (copy/paste it):'; | |
echo; | |
echo 'source ~/.bashrc'; | |
echo; | |
echo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment