#! /bin/bash

FIND_FILE="/etc/profile"

echo "Go sdk downloading..."

wget https://dl.google.com/go/go1.21.6.linux-amd64.tar.gz

tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz


echo "export GOROOT=/usr/local/go"
if [ `grep -c "export GOROOT=/usr/local/go" $FIND_FILE` -ne '0' ];then
  echo ""
else
  echo -e "export GOROOT=/usr/local/go \n" >> /etc/profile
fi

echo 'export PATH=$PATH:$GOROOT/bin'
if [ `grep -c 'export PATH=$PATH:$GOROOT/bin' $FIND_FILE` -ne '0' ];then
  echo ""
else
  echo -e 'export PATH=$PATH:$GOROOT/bin \n' >> /etc/profile
fi

source /etc/profile

go version

go env -w GO111MODULE=on

go env -w  GOPROXY=https://goproxy.cn,direct
