Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest golang download #11

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions libexec/goenv-install
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@
# Bomb out if we hit an error, ever
set -e

# helper functions
function download_url_exist() {
local url="$1"
curl -L --output /dev/null --silent --head --fail "$url"
}

function download_url() {
local version="$1"
local platform="$2"
local arch="$3"
local extra="$4"

# newer versions are at http://storage.googleapis.com/golang
# older versions are at http://go.googlecode.com/files

local base_url_new="https://storage.googleapis.com/golang"
local base_url_old="http://go.googlecode.com/files"

download="${base_url_new}/go${version}.${platform}-${arch}${extra}.tar.gz"
if download_url_exist $download ;
then
echo $download
return
fi

download="${base_url_old}/go${version}.${platform}-${arch}${extra}.tar.gz"
echo $download
}

# Verbose output in debug mode
[ -n "$GOENV_DEBUG" ] && {
set -x
Expand All @@ -33,8 +62,9 @@ else
fi

if [ "$platform" = "darwin" ]; then
# Since go version 1.2, osx packages were subdivided into 10.6 and 10.8
if [ "$version" = "1.2" -o "$version" \> "1.2" ]; then
extra=""
# Between go versions 1.2 through 1.4.3, osx packages were subdivided into 10.6 and 10.8
if [ "$version" = "1.2" -o \( "$version" \> "1.2" -a "$version" \< "1.4.3" \) ]; then
if [ "$(uname -r)" \> "12" ]; then
extra="-osx10.8"
else
Expand All @@ -44,15 +74,16 @@ if [ "$platform" = "darwin" ]; then
fi

# URL to download from
download="https://go.googlecode.com/files/go${version}.${platform}-${arch}${extra}.tar.gz"
download=$(download_url $version $platform $arch $extra)
echo "Downloading: $download"

# Can't get too clever here
set +e

# Download binary tarball and install
# Linux downloads are formatted differently from OS X
(
curl -s -f "$download" > "/tmp/go${version}.${platform}-${arch}.tar.gz" && \
curl -L -s -f "$download" > "/tmp/go${version}.${platform}-${arch}.tar.gz" && \
tar zxvf "/tmp/go${version}.${platform}-${arch}.tar.gz" --strip-components 1 && \
rm "/tmp/go${version}.${platform}-${arch}.tar.gz"
) || \
Expand Down