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