storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/buildscripts/checkdeps.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  # MinIO Cloud Storage, (C) 2014-2018 MinIO, Inc.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  #
    17  
    18  _init() {
    19  
    20      shopt -s extglob
    21  
    22      ## Minimum required versions for build dependencies
    23      GIT_VERSION="1.0"
    24      GO_VERSION="1.16"
    25      OSX_VERSION="10.8"
    26      KNAME=$(uname -s)
    27      ARCH=$(uname -m)
    28      case "${KNAME}" in
    29          SunOS )
    30              ARCH=$(isainfo -k)
    31              ;;
    32      esac
    33  }
    34  
    35  ## FIXME:
    36  ## In OSX, 'readlink -f' option does not exist, hence
    37  ## we have our own readlink -f behavior here.
    38  ## Once OSX has the option, below function is good enough.
    39  ##
    40  ## readlink() {
    41  ##     return /bin/readlink -f "$1"
    42  ## }
    43  ##
    44  readlink() {
    45      TARGET_FILE=$1
    46  
    47      cd `dirname $TARGET_FILE`
    48      TARGET_FILE=`basename $TARGET_FILE`
    49  
    50      # Iterate down a (possible) chain of symlinks
    51      while [ -L "$TARGET_FILE" ]
    52      do
    53          TARGET_FILE=$(env readlink $TARGET_FILE)
    54          cd `dirname $TARGET_FILE`
    55          TARGET_FILE=`basename $TARGET_FILE`
    56      done
    57  
    58      # Compute the canonicalized name by finding the physical path
    59      # for the directory we're in and appending the target file.
    60      PHYS_DIR=`pwd -P`
    61      RESULT=$PHYS_DIR/$TARGET_FILE
    62      echo $RESULT
    63  }
    64  
    65  ## FIXME:
    66  ## In OSX, 'sort -V' option does not exist, hence
    67  ## we have our own version compare function.
    68  ## Once OSX has the option, below function is good enough.
    69  ##
    70  ## check_minimum_version() {
    71  ##     versions=($(echo -e "$1\n$2" | sort -V))
    72  ##     return [ "$1" == "${versions[0]}" ]
    73  ## }
    74  ##
    75  check_minimum_version() {
    76      IFS='.' read -r -a varray1 <<< "$1"
    77      IFS='.' read -r -a varray2 <<< "$2"
    78  
    79      for i in "${!varray1[@]}"; do
    80          if [[ ${varray1[i]} -lt ${varray2[i]} ]]; then
    81              return 0
    82          elif [[ ${varray1[i]} -gt ${varray2[i]} ]]; then
    83              return 1
    84          fi
    85      done
    86  
    87      return 0
    88  }
    89  
    90  assert_is_supported_arch() {
    91      case "${ARCH}" in
    92          x86_64 | amd64 | aarch64 | ppc64le | arm* | s390x )
    93              return
    94              ;;
    95          *)
    96              echo "Arch '${ARCH}' is not supported. Supported Arch: [x86_64, amd64, aarch64, ppc64le, arm*, s390x]"
    97              exit 1
    98      esac
    99  }
   100  
   101  assert_is_supported_os() {
   102      case "${KNAME}" in
   103          Linux | FreeBSD | OpenBSD | NetBSD | DragonFly | SunOS )
   104              return
   105              ;;
   106          Darwin )
   107              osx_host_version=$(env sw_vers -productVersion)
   108              if ! check_minimum_version "${OSX_VERSION}" "${osx_host_version}"; then
   109                  echo "OSX version '${osx_host_version}' is not supported. Minimum supported version: ${OSX_VERSION}"
   110                  exit 1
   111              fi
   112              return
   113              ;;
   114          *)
   115              echo "OS '${KNAME}' is not supported. Supported OS: [Linux, FreeBSD, OpenBSD, NetBSD, Darwin, DragonFly]"
   116              exit 1
   117      esac
   118  }
   119  
   120  assert_check_golang_env() {
   121      if ! which go >/dev/null 2>&1; then
   122          echo "Cannot find go binary in your PATH configuration, please refer to Go installation document at https://golang.org/doc/install"
   123          exit 1
   124      fi
   125  
   126      installed_go_version=$(go version | sed 's/^.* go\([0-9.]*\).*$/\1/')
   127      if ! check_minimum_version "${GO_VERSION}" "${installed_go_version}"; then
   128          echo "Go runtime version '${installed_go_version}' is unsupported. Minimum supported version: ${GO_VERSION} to compile."
   129          exit 1
   130      fi
   131  }
   132  
   133  assert_check_deps() {
   134      # support unusual Git versions such as: 2.7.4 (Apple Git-66)
   135      installed_git_version=$(git version | perl -ne '$_ =~ m/git version (.*?)( |$)/; print "$1\n";')
   136      if ! check_minimum_version "${GIT_VERSION}" "${installed_git_version}"; then
   137          echo "Git version '${installed_git_version}' is not supported. Minimum supported version: ${GIT_VERSION}"
   138          exit 1
   139      fi
   140  }
   141  
   142  main() {
   143      ## Check for supported arch
   144      assert_is_supported_arch
   145  
   146      ## Check for supported os
   147      assert_is_supported_os
   148  
   149      ## Check for Go environment
   150      assert_check_golang_env
   151  
   152      ## Check for dependencies
   153      assert_check_deps
   154  }
   155  
   156  _init && main "$@"