diff --git a/buildscripts/checkdeps.sh b/buildscripts/checkdeps.sh index a556cea8..bc498148 100755 --- a/buildscripts/checkdeps.sh +++ b/buildscripts/checkdeps.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Minio Client, (C) 2015 Minio, Inc. +# Minio Client, (C) 2015, 2016, 2017 Minio, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,14 +25,17 @@ _init() { OSX_VERSION="10.8" KNAME=$(uname -s) ARCH=$(uname -m) - - ## Check all dependencies are present - MISSING="" - - ## Documentation sources - DOC_GO_INSTALL_URL="https://docs.minio.io/docs/how-to-install-golang" } +## FIXME: +## In OSX, 'readlink -f' option does not exist, hence +## we have our own readlink -f behaviour here. +## Once OSX has the option, below function is good enough. +## +## readlink() { +## return /bin/readlink -f "$1" +## } +## readlink() { TARGET_FILE=$1 @@ -54,101 +57,47 @@ readlink() { echo $RESULT } -### -# -# Takes two arguments -# arg1: version number in `x.x.x` format or `devel` -# arg2: version number in `x.x.x` format or `devel` -# -# example: check_version "$version1" "$version2" -# -# returns: -# 0 - Installed version is equal to required -# 1 - Installed version is greater than required -# 2 - Installed version is lesser than required -# 3 - If args have length zero -# -#### -check_version() { - ## validate args - [[ -z "$1" ]] && return 3 - [[ -z "$2" ]] && return 3 +## FIXME: +## In OSX, 'sort -V' option does not exist, hence +## we have our own version compare function. +## Once OSX has the option, below function is good enough. +## +## check_minimum_version() { +## versions=($(echo -e "$1\n$2" | sort -V)) +## return [ "$1" == "${versions[0]}" ] +## } +## +check_minimum_version() { + IFS='.' read -r -a varray1 <<< "$1" + IFS='.' read -r -a varray2 <<< "$2" - if [[ $1 == $2 ]]; then - return 0 - fi - - local IFS=. - local i ver1=($1) ver2=($2) - - if [ "$ver1" = "devel" ]; then - return 1 - fi - if [ "$ver2" = "devel" ]; then - return 2 - fi - - # fill empty fields in ver1 with zeros - for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do - ver1[i]=0 - done - for ((i=0; i<${#ver1[@]}; i++)); do - if [[ -z ${ver2[i]} ]]; then - # fill empty fields in ver2 with zeros - ver2[i]=0 - fi - if ((10#${ver1[i]} > 10#${ver2[i]})); then + for i in "${!varray1[@]}"; do + if [[ ${varray1[i]} -lt ${varray2[i]} ]]; then + return 0 + elif [[ ${varray1[i]} -gt ${varray2[i]} ]]; then return 1 fi - if ((10#${ver1[i]} < 10#${ver2[i]})); then - ## Installed version is lesser than required - Bad condition - return 2 - fi done + return 0 } -check_golang_env() { - echo ${GOROOT:?} 2>&1 >/dev/null - if [ $? -eq 1 ]; then - echo "ERROR" - echo "GOROOT environment variable missing, please refer to Go installation document" - echo "${DOC_GO_INSTALL_URL}" - exit 1 - fi - - echo ${GOPATH:?} 2>&1 >/dev/null - if [ $? -eq 1 ]; then - echo "ERROR" - echo "GOPATH environment variable missing, please refer to Go installation document" - echo "${DOC_GO_INSTALL_URL}" - exit 1 - fi - - local go_binary_path=$(which go) - - if [ -z "${go_binary_path}" ] ; then - echo "Cannot find go binary in your PATH configuration, please refer to Go installation document" - echo "${DOC_GO_INSTALL_URL}" - exit -1 - fi - - local new_go_binary_path=${go_binary_path} - if [ -h "${go_binary_path}" ]; then - new_go_binary_path=$(readlink ${go_binary_path}) - fi - - if [[ ! "$(dirname ${new_go_binary_path})" =~ "${GOROOT}"* ]] ; then - echo "The go binary found in your PATH configuration does not belong to the Go installation pointed by your GOROOT environment," \ - "please refer to Go installation document" - echo "${DOC_GO_INSTALL_URL}" - exit -1 - fi +assert_is_supported_arch() { + case "${ARCH}" in + x86_64 | amd64 | aarch64 | arm* ) + return + ;; + *) + echo "ERROR" + echo "Arch '${ARCH}' not supported." + echo "Supported Arch: [x86_64, amd64, aarch64, arm*]" + exit 1 + esac } assert_is_supported_os() { case "${KNAME}" in - Linux | FreeBSD | OpenBSD ) + Linux | FreeBSD | OpenBSD | NetBSD | DragonFly ) return ;; Darwin ) @@ -164,67 +113,59 @@ assert_is_supported_os() { *) echo "ERROR" echo "OS '${KNAME}' is not supported." - echo "Supported OS: [Linux, FreeBSD, OpenBSD, Darwin]" + echo "Supported OS: [Linux, FreeBSD, OpenBSD, NetBSD, Darwin, DragonFly]" exit 1 esac } -assert_is_supported_arch() { - case "${ARCH}" in - i386 | x86_64 | amd64 | aarch64 | arm* ) - return - ;; - *) - echo "ERROR" - echo "Arch '${ARCH}' not supported." - echo "Supported Arch: [i386, x86_64, amd64, aarch64, arm*]" - exit 1 - esac -} - -check_deps() { - check_version "$(env go version 2>/dev/null | awk '{print $3}' | sed 's/go\([0-9.]*\)$/\1/')" "${GO_VERSION}" - if [ $? -ge 2 ]; then - MISSING="${MISSING} golang(>=${GO_VERSION})" +assert_check_golang_env() { + if ! which go >/dev/null 2>&1; then + echo "ERROR" + echo "Cannot find go binary in your PATH configuration, please refer to Go installation document at" + echo "https://docs.minio.io/docs/how-to-install-golang" + exit 1 fi - check_version "$(env git --version 2>/dev/null | sed -e 's/^.* \([0-9.\].*\).*$/\1/' -e 's/^\([0-9.\]*\).*/\1/g')" "${GIT_VERSION}" - if [ $? -ge 2 ]; then - MISSING="${MISSING} git(>=${GIT_VERSION})" + installed_go_version=$(go version | sed 's/^.* go\([0-9.]*\).*$/\1/') + if ! check_minimum_version "${GO_VERSION}" "${installed_go_version}"; then + echo "ERROR" + echo "Go version '${installed_go_version}' not supported." + echo "Minimum supported version: ${GO_VERSION}" + exit 1 + fi + + if [ -z "${GOPATH}" ]; then + echo "ERROR" + echo "GOPATH environment variable missing, please refer to Go installation document" + echo "https://docs.minio.io/docs/how-to-install-golang" + exit 1 + fi + +} + +assert_check_deps() { + # support unusual Git versions such as: 2.7.4 (Apple Git-66) + installed_git_version=$(git version | perl -ne '$_ =~ m/git version (.*?)( |$)/; print "$1\n";') + if ! check_minimum_version "${GIT_VERSION}" "${installed_git_version}"; then + echo "ERROR" + echo "Git version '${installed_git_version}' not supported." + echo "Minimum supported version: ${GIT_VERSION}" + exit 1 fi } main() { - echo -n "Check for supported arch.. " + ## Check for supported arch assert_is_supported_arch - echo -n "Check for supported os.. " + ## Check for supported os assert_is_supported_os - echo -n "Checking if proper environment variables are set.. " - check_golang_env + ## Check for Go environment + assert_check_golang_env - echo "Done" - echo "Using GOPATH=${GOPATH} and GOROOT=${GOROOT}" - - echo -n "Checking dependencies for Minio Client.. " - check_deps - - ## If dependencies are missing, warn the user and abort - if [ "x${MISSING}" != "x" ]; then - echo "ERROR" - echo - echo "The following build tools are missing:" - echo - echo "** ${MISSING} **" - echo - echo "Please install them " - echo "${MISSING}" - echo - echo "Follow ${DOC_GO_INSTALL_URL} for further instructions" - exit 1 - fi - echo "Done" + ## Check for dependencies + assert_check_deps } _init && main "$@" diff --git a/buildscripts/checkgopath.sh b/buildscripts/checkgopath.sh index 61e61c14..8c4321c1 100644 --- a/buildscripts/checkgopath.sh +++ b/buildscripts/checkgopath.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Minio Cloud Storage, (C) 2015, 2016 Minio, Inc. +# Minio Client, (C) 2015, 2016, 2017 Minio, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.