Last active
January 27, 2021 08:04
-
-
Save blademainer/854f994c26198774916d438da8c35201 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -x | |
version="$1" | |
INSTALL_DIR="/usr/local" | |
os="`uname -s`" | |
arc="`uname -m`" | |
curl "https://golang.org/dl/" > dl.html | |
[ -z "`cat dl.html`" ] && exit -1 | |
#cat dl.html | grep -i "$os" | grep "64" | grep -i ".tar.gz" | grep -o "href=\".*\"" | grep -oE "https://(\w|\.|\/|-)+" > result.tmp | |
cat dl.html | grep -i "$os" | grep "64" | grep -i ".tar.gz" | grep -o "href=\".*\"" | grep -oE "\".*\"" | grep -oE "[^\"]+" > result.tmp | |
[ -z "`cat result.tmp`" ] && echo "not found pkg!" && exit -1 | |
rm -f dl.html | |
url="`cat result.tmp | head -n 1`" | |
if [ "____${version}" != "____" ]; then | |
url="`cat result | grep $version`" | |
fi | |
if [[ "$url" == /* ]]; then | |
url="https://golang.org$url" | |
fi | |
echo "url====$url" | |
v=`echo "$url" | grep -Eo "go(\d|\.)+\d+"` | |
echo "version===$v" | |
TARGET=$INSTALL_DIR/$v | |
echo "target===$TARGET" | |
sudo mkdir -p ${TARGET} | |
sudo chmod -R 777 ${TARGET} | |
curl -L "$url" > /tmp/go.tar.gz | |
sudo tar -zxvf /tmp/go.tar.gz -C "${TARGET}" | |
sudo rm -f /usr/local/go | |
sudo ln -s ${TARGET}/go /usr/local/go | |
if [ -n "`cat /etc/profile | grep -E 'export\s+GOROOT='`" ]; then | |
cat /etc/profile | sed "s/export *GOROOT=.*//g" > /tmp/profile | |
sudo mv /etc/profile /etc/profile.`date '+%s'` | |
sudo mv /tmp/profile /etc/profile | |
fi | |
echo "echo 'export GOROOT=/usr/local/go' >> /etc/profile" | sudo sh | |
source /etc/profile | |
rm -f /tmp/go.tar.gz | |
rm -f result.tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
USAGE