82 lines
2.5 KiB
Bash
Executable file
82 lines
2.5 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.18.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";;
|
|
1.17.6) new_sum="de00bf818cda9e4712e9b3438c9c3d4f8318beb598d11abb0ba9d515883f6320";;
|
|
1.18) new_sum="63e5cab48f97c63dc2737eb35582316acf77084d109ac0571651cedaf40987c0";;
|
|
1.18.2) new_sum="b76e590857060fdc575a37d4204c15df33de6d23e49d5cf9bdce93083e4dcddb";;
|
|
1.18.3) new_sum="cc0e73239f5bc1521de9ddc54f46eb0e69cc41faabe3f468865483bb0f844b68";;
|
|
1.18.4) new_sum="283442519c28f5c24dd8c849ebe0570a3ad92cd94610378b33b2053f60391fdf";;
|
|
*) 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}
|
|
[[ -z "${new_sum}" ]] && { sha256sum ${path_new}|cut -d" " -f1; exit 0; }
|
|
[[ "$(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
|