github.com/minio/mc@v0.0.0-20240507152021-646712d5e5fb/buildscripts/checkdeps.sh (about) 1 #!/usr/bin/env bash 2 # 3 # Copyright (c) 2015-2021 MinIO, Inc. 4 # 5 # This file is part of MinIO Object Storage stack 6 # 7 # This program is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU Affero General Public License as published by 9 # the Free Software Foundation, either version 3 of the License, or 10 # (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU Affero General Public License for more details. 16 # 17 # You should have received a copy of the GNU Affero General Public License 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 # 20 21 # shellcheck source=buildscripts/build.env 22 . "$(pwd)/buildscripts/build.env" 23 24 _init() { 25 26 shopt -s extglob 27 28 ## Minimum required versions for build dependencies 29 GIT_VERSION="1.0" 30 GO_VERSION="1.13" 31 OSX_VERSION="10.8" 32 KNAME=$(uname -s) 33 ARCH=$(uname -m) 34 case "${KNAME}" in 35 SunOS ) 36 ARCH=$(isainfo -k) 37 ;; 38 esac 39 } 40 41 ## FIXME: 42 ## In OSX, 'readlink -f' option does not exist, hence 43 ## we have our own readlink -f behavior here. 44 ## Once OSX has the option, below function is good enough. 45 ## 46 ## readlink() { 47 ## return /bin/readlink -f "$1" 48 ## } 49 ## 50 readlink() { 51 TARGET_FILE=$1 52 53 cd `dirname $TARGET_FILE` 54 TARGET_FILE=`basename $TARGET_FILE` 55 56 # Iterate down a (possible) chain of symlinks 57 while [ -L "$TARGET_FILE" ] 58 do 59 TARGET_FILE=$(env readlink $TARGET_FILE) 60 cd `dirname $TARGET_FILE` 61 TARGET_FILE=`basename $TARGET_FILE` 62 done 63 64 # Compute the canonicalized name by finding the physical path 65 # for the directory we're in and appending the target file. 66 PHYS_DIR=`pwd -P` 67 RESULT=$PHYS_DIR/$TARGET_FILE 68 echo $RESULT 69 } 70 71 assert_is_supported_arch() { 72 case "${ARCH}" in 73 x86_64 | amd64 | ppc64le | aarch64 | arm* | s390x | loong64 | loongarch64 ) 74 return 75 ;; 76 *) 77 echo "Arch '${ARCH}' is not supported. Supported Arch: [x86_64, amd64, ppc64le, aarch64, arm*, s390x, loong64, loongarch64]" 78 exit 1 79 esac 80 } 81 82 assert_is_supported_os() { 83 case "${KNAME}" in 84 Linux | FreeBSD | OpenBSD | NetBSD | DragonFly | SunOS ) 85 return 86 ;; 87 Darwin ) 88 osx_host_version=$(env sw_vers -productVersion) 89 if ! check_minimum_version "${OSX_VERSION}" "${osx_host_version}"; then 90 echo "OSX version '${osx_host_version}' is not supported. Minimum supported version: ${OSX_VERSION}" 91 exit 1 92 fi 93 return 94 ;; 95 *) 96 echo "OS '${KNAME}' is not supported. Supported OS: [Linux, FreeBSD, OpenBSD, NetBSD, Darwin, DragonFly]" 97 exit 1 98 esac 99 } 100 101 assert_check_golang_env() { 102 if ! which go >/dev/null 2>&1; then 103 echo "Cannot find go binary in your PATH configuration, please refer to Go installation document at https://golang.org/doc/install" 104 exit 1 105 fi 106 107 installed_go_version=$(go version | sed 's/^.* go\([0-9.]*\).*$/\1/') 108 if ! check_minimum_version "${GO_VERSION}" "${installed_go_version}"; then 109 echo "Go runtime version '${installed_go_version}' is unsupported. Minimum supported version: ${GO_VERSION} to compile." 110 exit 1 111 fi 112 } 113 114 assert_check_deps() { 115 # support unusual Git versions such as: 2.7.4 (Apple Git-66) 116 installed_git_version=$(git version | perl -ne '$_ =~ m/git version (.*?)( |$)/; print "$1\n";') 117 if ! check_minimum_version "${GIT_VERSION}" "${installed_git_version}"; then 118 echo "Git version '${installed_git_version}' is not supported. Minimum supported version: ${GIT_VERSION}" 119 exit 1 120 fi 121 } 122 123 main() { 124 ## Check for supported arch 125 assert_is_supported_arch 126 127 ## Check for supported os 128 assert_is_supported_os 129 130 ## Check for Go environment 131 assert_check_golang_env 132 133 ## Check for dependencies 134 assert_check_deps 135 } 136 137 _init && main "$@"