scripts/build-go.sh
2019-08-20 20:38:28 +02:00

73 lines
1.6 KiB
Bash
Executable file

#!/bin/bash
set -e
set -x
if [ $(id -u) -ne 0 ]; then
echo "error: this script must be run as root">&2
exit 1
fi
install_dir="/usr/local"
go_dir="${install_dir}/go"
url="https://github.com/golang/go/archive"
v14="go1.4.3"
v14_sum="65e8d2ea08447f02f8b6ab63778e4d98586ac4fd676401dae0eda494c7829965"
bootstrap="${install_dir}/bootstrap-${v14}"
tgz14="${v14}.tar.gz"
path_v14="${install_dir}/${tgz14}"
new="go1.12.9"
new_sum="c31433aa0bb01856c812d40a91336e25cbce2e50800eb9fe88a7adf0305f1a5b"
tgznew="${new}.tar.gz"
path_new="${install_dir}/${tgznew}"
rm -rf ${go_dir}
if [[ ! -d "${bootstrap}" ]]; then
wget -q ${url}/${tgz14} -O ${path_v14}
if [[ "$(sha256sum ${path_v14}|cut -d" " -f1)" != "${v14_sum}" ]]; then
echo "error: wrong checksum: ${path_v14}">&2
exit 1
fi
tar xfz ${path_v14} -C ${install_dir}
mv ${install_dir}/go-${v14} ${bootstrap}
fi
wget -q ${url}/${tgznew} -O ${path_new}
if [[ "$(sha256sum ${path_new}|cut -d" " -f1)" != "${new_sum}" ]]; then
echo "error: wrong checksum: ${path_new}">&2
exit 1
fi
tar xfz ${path_new} -C ${install_dir}
mv ${install_dir}/go-${new} ${go_dir}
export CGO_ENABLED=0
if [[ ! -x "${bootstrap}/bin/go" ]]; then
cd ${bootstrap}/src
./make.bash &> /dev/null
fi
export GOROOT_BOOTSTRAP=${bootstrap}
[[ "$(uname -m)" == "x86_64" ]] && export GOARCH=amd64 || export GOARCH=386
cd ${go_dir}/src
./make.bash &> /dev/null
export GOROOT=${go_dir}
export PATH=${PATH}:${GOROOT}/bin:~/go/bin
cat <<EOF
add this to your .bashrc/.profile:
export CGO_ENABLED=${CGO_ENABLED}
export GOPATH=~/go
export GOROOT=${GOROOT}
export GO111MODULE=on
export PATH=\${PATH}:${GOROOT}:~/go/bin
EOF
go version