github.com/whyrusleeping/gx@v0.14.3/bin/check_go_version (about)

     1  #!/bin/sh
     2  #
     3  # Check that the go version is at least equal to a minimum version
     4  # number.
     5  #
     6  # Call it for example like this:
     7  #
     8  #   $ check_go_version "1.5.2"
     9  #
    10  
    11  USAGE="$0 GO_MIN_VERSION"
    12  
    13  die() {
    14      printf >&2 "fatal: %s\n" "$@"
    15      exit 1
    16  }
    17  
    18  # Get arguments
    19  
    20  test "$#" -eq "1" || die "This program must be passed exactly 1 arguments" "Usage: $USAGE"
    21  
    22  GO_MIN_VERSION="$1"
    23  
    24  UPGRADE_MSG="Please take a look at https://golang.org/doc/install to install or upgrade go."
    25  
    26  # Get path to the directory containing this file
    27  # If $0 has no slashes, uses "./"
    28  PREFIX=$(expr "$0" : "\(.*\/\)") || PREFIX='./'
    29  # Include the 'check_at_least_version' function
    30  . ${PREFIX}check_version
    31  
    32  # Check that the go binary exist and is in the path
    33  
    34  type go >/dev/null 2>&1 || die_upgrade "go is not installed or not in the PATH!"
    35  
    36  # Check the go binary version
    37  
    38  VERS_STR=$(go version 2>&1) || die "'go version' failed with output: $VERS_STR"
    39  
    40  GO_CUR_VERSION=$(expr "$VERS_STR" : ".*go version go\([^ ]*\) .*") || die "Invalid 'go version' output: $VERS_STR"
    41  
    42  check_at_least_version "$GO_MIN_VERSION" "$GO_CUR_VERSION" "go"