File: ensure-go-installed.sh

package info (click to toggle)
git-sizer 1.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 300 kB
  • sloc: sh: 98; makefile: 80
file content (30 lines) | stat: -rw-r--r-- 786 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# This file is meant to be sourced with ROOTDIR set.

if [ -z "$ROOTDIR" ]; then
    echo 1>&2 'ensure-go-installed.sh invoked without ROOTDIR set!'
fi

# Is go installed, and at least 1.9?
go_ok() {
    set -- $(go version 2>/dev/null |
                sed -n 's/.*go\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1 \2/p' |
                head -n 1)
    [ $# -eq 2 ] && [ "$1" -eq 1 ] && [ "$2" -ge 9 ]
}

# If a local go is installed, use it.
set_up_vendored_go() {
    GO_VERSION=go1.9.2
    VENDORED_GOROOT="$ROOTDIR/vendor/$GO_VERSION/go"
    if [ -x "$VENDORED_GOROOT/bin/go" ]; then
        export GOROOT="$VENDORED_GOROOT"
        export PATH="$GOROOT/bin:$PATH"
    fi
}

set_up_vendored_go

if ! go_ok; then
    script/install-vendored-go >/dev/null || exit 1
    set_up_vendored_go
fi