From d3acdbed9df0c87463be8bc6f891e045c6994b96 Mon Sep 17 00:00:00 2001 From: Indraniel Das Date: Tue, 1 Jul 2014 18:30:26 -0500 Subject: [PATCH 1/6] + adjust download location for latest version of Go (1.3) - the newest version of Go is at http://golang.org/dl/ --- libexec/goenv-install | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libexec/goenv-install b/libexec/goenv-install index 690fc14..fdbbdbc 100755 --- a/libexec/goenv-install +++ b/libexec/goenv-install @@ -44,7 +44,12 @@ if [ "$platform" = "darwin" ]; then fi # URL to download from -download="https://go.googlecode.com/files/go${version}.${platform}-${arch}${extra}.tar.gz" +if [ "$version" = "1.3" -o "$version" \> "1.3" ]; then + base_url="http://golang.org/dl" +else + base_url="https://go.googlecode.com/files" +fi +download="${base_url}/go${version}.${platform}-${arch}${extra}.tar.gz" # Can't get too clever here set +e @@ -52,7 +57,7 @@ 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" ) || \ From b8785e2f04f3b3f6a88606c328427ed6d16f1691 Mon Sep 17 00:00:00 2001 From: indraniel Date: Wed, 9 Jul 2014 16:23:03 -0500 Subject: [PATCH 2/6] + find the golang download url generically - try to check the following download locations in order 1. http://golang.org/dl 2. http://go.googlecode.com/files Otherwise, bail out with an error message. --- libexec/goenv-install | 46 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/libexec/goenv-install b/libexec/goenv-install index fdbbdbc..df35980 100755 --- a/libexec/goenv-install +++ b/libexec/goenv-install @@ -8,6 +8,45 @@ # Bomb out if we hit an error, ever set -e +# helper functions +function warn() { + printf '\033[0;31m%s\033[0m\n' "$1" >&2 +} + +function die() { + warn "$1" + exit 1 +} + +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://golang.org/dl + # older versions are at http://go.googlecode.com/files + + local base_urls=("http://golang.org/dl" "http://go.googlecode.com/files") + local download="" + + for base_url in "${base_urls[@]}" + do + download="${base_url}/go${version}.${platform}-${arch}${extra}.tar.gz" + if download_url_exist $download ; + then + echo $download + return + fi + done + die "[err] Couldn't find download url for golang version '$version'" +} + # Verbose output in debug mode [ -n "$GOENV_DEBUG" ] && { set -x @@ -44,12 +83,7 @@ if [ "$platform" = "darwin" ]; then fi # URL to download from -if [ "$version" = "1.3" -o "$version" \> "1.3" ]; then - base_url="http://golang.org/dl" -else - base_url="https://go.googlecode.com/files" -fi -download="${base_url}/go${version}.${platform}-${arch}${extra}.tar.gz" +download=$(download_url $version $platform $arch $extra) # Can't get too clever here set +e From c78ef5890c8a8c1acf596f7c0c45fdee47d6acc5 Mon Sep 17 00:00:00 2001 From: indraniel Date: Wed, 9 Jul 2014 16:31:00 -0500 Subject: [PATCH 3/6] + alternative way to get golang download url generically - looks like the http://go.googlecode.com/ doesn't respect HEAD requests. This alternative approach is less rigorous than the prior approach, but it seems to work. - removed the 'warn' and 'die' helper functions because they weren't used in this 2nd pass approach. --- libexec/goenv-install | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/libexec/goenv-install b/libexec/goenv-install index df35980..5ca5f66 100755 --- a/libexec/goenv-install +++ b/libexec/goenv-install @@ -9,15 +9,6 @@ set -e # helper functions -function warn() { - printf '\033[0;31m%s\033[0m\n' "$1" >&2 -} - -function die() { - warn "$1" - exit 1 -} - function download_url_exist() { local url="$1" curl -L --output /dev/null --silent --head --fail "$url" @@ -32,19 +23,18 @@ function download_url() { # newer versions are at http://golang.org/dl # older versions are at http://go.googlecode.com/files - local base_urls=("http://golang.org/dl" "http://go.googlecode.com/files") - local download="" - - for base_url in "${base_urls[@]}" - do - download="${base_url}/go${version}.${platform}-${arch}${extra}.tar.gz" - if download_url_exist $download ; - then - echo $download - return - fi - done - die "[err] Couldn't find download url for golang version '$version'" + local base_url_new="http://golang.org/dl" + 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 From 3f6a2bad8051d8eadfa15deff244c64f4bc58e2b Mon Sep 17 00:00:00 2001 From: indraniel Date: Mon, 25 Jan 2016 17:55:20 -0600 Subject: [PATCH 4/6] + include new download url --- libexec/goenv-install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libexec/goenv-install b/libexec/goenv-install index 5ca5f66..5bbf293 100755 --- a/libexec/goenv-install +++ b/libexec/goenv-install @@ -20,10 +20,10 @@ function download_url() { local arch="$3" local extra="$4" - # newer versions are at http://golang.org/dl + # newer versions are at http://storage.googleapis.com/golang # older versions are at http://go.googlecode.com/files - local base_url_new="http://golang.org/dl" + 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" From 28706c37f87d769a3eebad46603faaa4e7850fc2 Mon Sep 17 00:00:00 2001 From: indraniel Date: Mon, 25 Jan 2016 17:56:39 -0600 Subject: [PATCH 5/6] + account for custom "extra" parameters - Between go versions 1.2 through 1.4.3, osx packages were subdivided into two versions, one for OSX 10.6 and another for OSX 10.8 --- libexec/goenv-install | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libexec/goenv-install b/libexec/goenv-install index 5bbf293..47f8402 100755 --- a/libexec/goenv-install +++ b/libexec/goenv-install @@ -62,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 From c11ae6cb94e024cb48d827a492760904d7d6e47d Mon Sep 17 00:00:00 2001 From: indraniel Date: Mon, 25 Jan 2016 17:57:50 -0600 Subject: [PATCH 6/6] + mention the download url - this helps when debugging far into the future when I've forgotten many of the downloading details. --- libexec/goenv-install | 1 + 1 file changed, 1 insertion(+) diff --git a/libexec/goenv-install b/libexec/goenv-install index 47f8402..a899e52 100755 --- a/libexec/goenv-install +++ b/libexec/goenv-install @@ -75,6 +75,7 @@ fi # URL to download from download=$(download_url $version $platform $arch $extra) +echo "Downloading: $download" # Can't get too clever here set +e