github.com/hashicorp/packer@v1.14.3/scripts/vagrant-linux-priv-go.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright (c) HashiCorp, Inc.
     3  # SPDX-License-Identifier: BUSL-1.1
     4  
     5  
     6  function install_go() {
     7  	local go_version=1.13
     8  	local download=
     9  	download="https://dl.google.com/go/go${go_version}.linux-amd64.tar.gz"
    10  
    11  	if [ -d /usr/local/go ] ; then
    12  		return
    13  	fi
    14  
    15  	wget -q -O /tmp/go.tar.gz ${download}
    16  
    17  	tar -C /tmp -xf /tmp/go.tar.gz
    18  	sudo mv /tmp/go /usr/local
    19  	sudo chown -R root:root /usr/local/go
    20  }
    21  
    22  install_go
    23  
    24  # Ensure that the GOPATH tree is owned by vagrant:vagrant
    25  mkdir -p /opt/gopath
    26  chown -R vagrant:vagrant /opt/gopath
    27  
    28  # Ensure Go is on PATH
    29  if [ ! -e /usr/bin/go ] ; then
    30  	ln -s /usr/local/go/bin/go /usr/bin/go
    31  fi
    32  if [ ! -e /usr/bin/gofmt ] ; then
    33  	ln -s /usr/local/go/bin/gofmt /usr/bin/gofmt
    34  fi
    35  
    36  
    37  # Ensure new sessions know about GOPATH
    38  if [ ! -f /etc/profile.d/gopath.sh ] ; then
    39  	cat <<EOT > /etc/profile.d/gopath.sh
    40  export GOPATH="/opt/gopath"
    41  export PATH="/opt/gopath/bin:\$PATH"
    42  EOT
    43  	chmod 755 /etc/profile.d/gopath.sh
    44  fi