76 lines
2 KiB
Bash
Executable file
76 lines
2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -e
|
|
errx() { echo "error: $1">&2; exit 1; }
|
|
[[ $(id -u) -ne 0 ]] && errx "this script must be run as root"
|
|
|
|
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}"
|
|
|
|
v="${1-1.17.4}"
|
|
case "${v}" in
|
|
1.16.7) new_sum="07502f16366fbc697b1b09b842d29116e6d6607c9dc42b1d7c54b96f528c7952";;
|
|
1.17.1) new_sum="670ce36e100669f9be572a1603858ce4a64eb4b21a31fa5cdefb778609c40337";;
|
|
1.17.2) new_sum="022fe1f533432a305db705448f50f9a3ea369586dc32d07219b1bc7db1e01577";;
|
|
1.17.4) new_sum="91736588a47917aaa424dfdf482d8efcb44403a768e7a947c272a98881053386";;
|
|
*) errx "no hash found for version ${v}";;
|
|
esac
|
|
|
|
new="go${v}"
|
|
new_dir="${install_dir}/go-${new}"
|
|
tgznew="${new}.tar.gz"
|
|
path_new="${install_dir}/${tgznew}"
|
|
|
|
rm -f ${go_dir}
|
|
|
|
if [[ ! -d "${bootstrap}" ]]; then
|
|
curl -sSL "${url}/${tgz14}" >${path_v14}
|
|
[[ "$(sha256sum ${path_v14}|cut -d" " -f1)" != "${v14_sum}" ]] && errx "wrong checksum: ${path_v14}"
|
|
tar xfz ${path_v14} -C ${install_dir}
|
|
mv ${install_dir}/go-${v14} ${bootstrap}
|
|
fi
|
|
|
|
if [[ ! -d "${new_dir}" ]]; then
|
|
curl -sSL "${url}/${tgznew}" >${path_new}
|
|
[[ "$(sha256sum ${path_new}|cut -d" " -f1)" != "${new_sum}" ]] && errx "wrong checksum: ${path_new}"
|
|
tar xfz ${path_new} -C ${install_dir}
|
|
fi
|
|
|
|
export CGO_ENABLED=0
|
|
|
|
if [[ ! -x "${bootstrap}/bin/go" ]]; then
|
|
cd ${bootstrap}/src
|
|
./make.bash
|
|
fi
|
|
|
|
if [[ ! -x "${new_dir}/bin/go" ]]; then
|
|
export GOROOT_BOOTSTRAP=${bootstrap}
|
|
[[ "$(uname -m)" == "x86_64" ]] && export GOARCH=amd64 || export GOARCH=386
|
|
cd ${new_dir}/src
|
|
./make.bash
|
|
fi
|
|
|
|
ln -s ${new_dir} ${go_dir}
|
|
|
|
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}/bin:~/go/bin
|
|
|
|
EOF
|
|
|
|
go version
|