diff --git a/images/linux/scripts/installers/go.sh b/images/linux/scripts/installers/go.sh index 8a16eef84..c454f59ff 100644 --- a/images/linux/scripts/installers/go.sh +++ b/images/linux/scripts/installers/go.sh @@ -13,8 +13,8 @@ golangTags="/tmp/golang_tags.json" # $2=IsDefaultVersion (true or false) function InstallGo () { version=$( getFullGoVersion $1 ) - downloadVersion=$version.linux-amd64.tar.gz - goFolder=/usr/local/go$1 + downloadVersion="go$version.linux-amd64.tar.gz" + goFolder="$AGENT_TOOLSDIRECTORY/go/$version/x64" echo "Install Go $version" curl -sL https://dl.google.com/go/${downloadVersion} -o ${downloadVersion} @@ -22,7 +22,10 @@ function InstallGo () { tar -C $goFolder -xzf $downloadVersion --strip-components=1 go rm $downloadVersion echo "GOROOT_${1//./_}_X64=$goFolder" | tee -a /etc/environment - DocumentInstalledItem "Go $1 ($($goFolder/bin/go version))" + DocumentInstalledItem "Go $version ($($goFolder/bin/go version))" + + # Create symlink in old location /usr/local/go to new location + ln -s $goFolder /usr/local/go$version # If this version of Go is to be the default version, # symlink it into the path and point GOROOT to it. @@ -37,8 +40,8 @@ function getFullGoVersion () { local pattern="refs/tags/go$1([.0-9]{0,3})$" local query='[.[] | select( .ref | test($pattern))] | .[-1] | .ref' refValue=$(jq --arg pattern "$pattern" "$query" $golangTags) - version=$(echo "$refValue" | cut -d '/' -f 3) - version=$(echo "${version//\"}") # go1.12.17 + version=$(echo "$refValue" | cut -d '/' -f 3 | awk -F 'go' '{print $2}') + version=$(echo "${version//\"}") # 1.12.17 echo $version } @@ -52,4 +55,4 @@ for go in ${GO_VERSIONS}; do else InstallGo $go false fi -done \ No newline at end of file +done diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index fc47d0e91..5aa162f0d 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -251,19 +251,6 @@ ], "execute_command": "/bin/sh -c '{{ .Vars }} {{ .Path }}'" }, - { - "type": "shell", - "scripts": [ - "{{template_dir}}/scripts/installers/go.sh" - ], - "environment_vars": [ - "METADATA_FILE={{user `metadata_file`}}", - "HELPER_SCRIPTS={{user `helper_script_folder`}}", - "GO_VERSIONS={{user `go_versions`}}", - "GO_DEFAULT={{user `go_default`}}" - ], - "execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}" - }, { "type": "file", "source": "{{template_dir}}/toolcache-1604.json", @@ -292,6 +279,19 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, + { + "type": "shell", + "scripts": [ + "{{template_dir}}/scripts/installers/go.sh" + ], + "environment_vars": [ + "METADATA_FILE={{user `metadata_file`}}", + "HELPER_SCRIPTS={{user `helper_script_folder`}}", + "GO_VERSIONS={{user `go_versions`}}", + "GO_DEFAULT={{user `go_default`}}" + ], + "execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}" + }, { "type": "shell", "scripts":[ diff --git a/images/linux/ubuntu1804.json b/images/linux/ubuntu1804.json index 2471106f3..8408704f5 100644 --- a/images/linux/ubuntu1804.json +++ b/images/linux/ubuntu1804.json @@ -255,19 +255,6 @@ ], "execute_command": "/bin/sh -c '{{ .Vars }} {{ .Path }}'" }, - { - "type": "shell", - "scripts": [ - "{{template_dir}}/scripts/installers/go.sh" - ], - "environment_vars": [ - "METADATA_FILE={{user `metadata_file`}}", - "HELPER_SCRIPTS={{user `helper_script_folder`}}", - "GO_VERSIONS={{user `go_versions`}}", - "GO_DEFAULT={{user `go_default`}}" - ], - "execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}" - }, { "type": "file", "source": "{{template_dir}}/toolcache-1804.json", @@ -296,6 +283,19 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, + { + "type": "shell", + "scripts": [ + "{{template_dir}}/scripts/installers/go.sh" + ], + "environment_vars": [ + "METADATA_FILE={{user `metadata_file`}}", + "HELPER_SCRIPTS={{user `helper_script_folder`}}", + "GO_VERSIONS={{user `go_versions`}}", + "GO_DEFAULT={{user `go_default`}}" + ], + "execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}" + }, { "type": "shell", "scripts":[