Last active
April 20, 2022 21:07
-
-
Save someburner/ede93ee7c549208d638d52ae6a8d7b45 to your computer and use it in GitHub Desktop.
Bootstrap go
This file contains 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
#!/bin/bash | |
############ SETTINGS ############ | |
PREFIX=/usr | |
_GOVERS="1.18.1" | |
PATCH_CERTS=0 | |
################################## | |
set -e | |
set -x | |
ensure_root() { if [[ "$EUID" -ne 0 ]]; then echo "Please run as root"; exit 1; fi } | |
ensure_root; | |
[[ -d $PREFIX/bin/go ]] && echo "$PREFIX/bin/go exists, remove it first" && exit 1; | |
export CGO_ENABLED=0 | |
echo "Get bootstrapper.." | |
if ! [[ -d $PREFIX/bin/go ]]; then | |
mkdir -p $PREFIX/bin/go/bootstrap && cd $PREFIX/bin/go/bootstrap | |
wget https://storage.googleapis.com/golang/go1.4.3.src.tar.gz | |
tar zxf go1.4.3.src.tar.gz | |
mv go go1.4 | |
else | |
cd $PREFIX/bin/go/bootstrap | |
fi; | |
echo "Compile bootstrapper.." | |
cd ./go1.4/src | |
if ! [[ -f .bootstrapped ]]; then | |
./make.bash | |
! [[ $? -eq 0 ]] && exit 1; | |
echo "successfuly built bootstrapper (go1.4)" | |
touch .bootstrapped | |
fi | |
if ! [[ -f .built$_GOVERS ]]; then | |
echo "Building go$_GOVERS" | |
cd $PREFIX/bin/go | |
wget https://redirector.gvt1.com/edgedl/go/go$_GOVERS.src.tar.gz | |
tar zxf go$_GOVERS.src.tar.gz -C $PREFIX/bin | |
cd $PREFIX/bin/go/src | |
if [[ $PATCH_CERTS -eq 1 ]]; then | |
if ! [[ -f .dlcerts ]]; then | |
echo "Downloading ca-bundle.crt" | |
wget -O $PREFIX/ssl/certs/ca-certificates.crt https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt | |
! [[ $? -eq 0 ]] && exit 1; | |
echo "Got cert bundle ok." | |
touch .dlcerts | |
fi | |
if ! [[ -f .patch_crt ]]; then | |
echo "Patching crypto/x509/root_linux.go with ca-bundle.crt location" | |
sed -i 's,\/etc\/ssl\/certs\/ca-certificates.crt,'"$PREFIX"'\/ssl\/certs\/ca-certificates.crt,g' ./crypto/x509/root_linux.go | |
! [[ $? -eq 0 ]] && exit 1; | |
echo "Patched root_linux.go" | |
touch .patch_crt | |
fi | |
fi | |
GOROOT_BOOTSTRAP=$PREFIX/bin/go/bootstrap/go1.4 ./make.bash | |
! [[ $? -eq 0 ]] && exit 1; | |
touch .built$_GOVERS | |
echo "successfuly built go compiler v$_GOVERS" | |
echo; | |
echo "Go compiler returned no errors. Congrats." | |
echo "Go v$_GOVERS has been installed." | |
echo; | |
fi | |
#if ! [[ -d $HOME/go ]]; then | |
# mkdir -p $HOME/go; | |
# echo "Created go work dir: $HOME/go"; | |
#fi | |
echo "Make sure $PREFIX/bin/go/bin is in your PATH." | |
echo "To test, run 'go version'"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment