2015-02-17 13:17:31 -05:00
|
|
|
#!/usr/bin/env bash
|
2015-02-15 03:48:15 -05:00
|
|
|
#
|
2018-02-13 23:59:19 -05:00
|
|
|
# Minio Cloud Storage, (C) 2014-2018 Minio, Inc.
|
2015-02-15 03:48:15 -05:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
2014-12-04 04:56:01 -05:00
|
|
|
|
2015-02-15 03:48:15 -05:00
|
|
|
_init() {
|
2015-06-23 12:44:05 -04:00
|
|
|
|
|
|
|
shopt -s extglob
|
|
|
|
|
2015-02-15 03:48:15 -05:00
|
|
|
## Minimum required versions for build dependencies
|
|
|
|
GIT_VERSION="1.0"
|
2018-04-06 14:07:39 -04:00
|
|
|
GO_VERSION="1.10.1"
|
2015-02-15 17:48:11 -05:00
|
|
|
OSX_VERSION="10.8"
|
2016-11-07 16:28:41 -05:00
|
|
|
KNAME=$(uname -s)
|
|
|
|
ARCH=$(uname -m)
|
2017-04-23 14:10:18 -04:00
|
|
|
case "${KNAME}" in
|
|
|
|
SunOS )
|
|
|
|
ARCH=$(isainfo -k)
|
|
|
|
;;
|
|
|
|
esac
|
2015-02-15 03:48:15 -05:00
|
|
|
}
|
|
|
|
|
2016-11-07 16:28:41 -05:00
|
|
|
## FIXME:
|
|
|
|
## In OSX, 'readlink -f' option does not exist, hence
|
2018-06-28 19:02:02 -04:00
|
|
|
## we have our own readlink -f behavior here.
|
2016-11-07 16:28:41 -05:00
|
|
|
## Once OSX has the option, below function is good enough.
|
|
|
|
##
|
|
|
|
## readlink() {
|
|
|
|
## return /bin/readlink -f "$1"
|
|
|
|
## }
|
|
|
|
##
|
2015-07-27 21:09:23 -04:00
|
|
|
readlink() {
|
|
|
|
TARGET_FILE=$1
|
|
|
|
|
|
|
|
cd `dirname $TARGET_FILE`
|
|
|
|
TARGET_FILE=`basename $TARGET_FILE`
|
|
|
|
|
|
|
|
# Iterate down a (possible) chain of symlinks
|
|
|
|
while [ -L "$TARGET_FILE" ]
|
|
|
|
do
|
|
|
|
TARGET_FILE=$(env readlink $TARGET_FILE)
|
|
|
|
cd `dirname $TARGET_FILE`
|
|
|
|
TARGET_FILE=`basename $TARGET_FILE`
|
|
|
|
done
|
|
|
|
|
|
|
|
# Compute the canonicalized name by finding the physical path
|
|
|
|
# for the directory we're in and appending the target file.
|
|
|
|
PHYS_DIR=`pwd -P`
|
|
|
|
RESULT=$PHYS_DIR/$TARGET_FILE
|
|
|
|
echo $RESULT
|
|
|
|
}
|
|
|
|
|
2016-11-07 16:28:41 -05:00
|
|
|
## 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"
|
|
|
|
|
|
|
|
for i in "${!varray1[@]}"; do
|
2016-11-21 15:25:46 -05:00
|
|
|
if [[ ${varray1[i]} -lt ${varray2[i]} ]]; then
|
2016-11-07 16:28:41 -05:00
|
|
|
return 0
|
2016-11-21 15:25:46 -05:00
|
|
|
elif [[ ${varray1[i]} -gt ${varray2[i]} ]]; then
|
2015-02-15 03:48:15 -05:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
2015-06-23 12:44:05 -04:00
|
|
|
|
2016-11-07 16:28:41 -05:00
|
|
|
return 0
|
2015-02-15 03:48:15 -05:00
|
|
|
}
|
|
|
|
|
2016-11-07 16:28:41 -05:00
|
|
|
assert_is_supported_arch() {
|
|
|
|
case "${ARCH}" in
|
2018-07-03 12:42:19 -04:00
|
|
|
x86_64 | amd64 | aarch64 | ppc64le | arm* )
|
2016-11-07 16:28:41 -05:00
|
|
|
return
|
2016-03-26 16:36:33 -04:00
|
|
|
;;
|
2016-11-07 16:28:41 -05:00
|
|
|
*)
|
2018-07-03 12:42:19 -04:00
|
|
|
echo "Arch '${ARCH}' is not supported. Supported Arch: [x86_64, amd64, aarch64, ppc64le, arm*]"
|
2016-11-07 16:28:41 -05:00
|
|
|
exit 1
|
2015-02-15 17:48:11 -05:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2016-11-07 16:28:41 -05:00
|
|
|
assert_is_supported_os() {
|
|
|
|
case "${KNAME}" in
|
2017-04-23 14:10:18 -04:00
|
|
|
Linux | FreeBSD | OpenBSD | NetBSD | DragonFly | SunOS )
|
2016-11-07 16:28:41 -05:00
|
|
|
return
|
2015-02-15 17:48:11 -05:00
|
|
|
;;
|
2016-11-07 16:28:41 -05:00
|
|
|
Darwin )
|
|
|
|
osx_host_version=$(env sw_vers -productVersion)
|
|
|
|
if ! check_minimum_version "${OSX_VERSION}" "${osx_host_version}"; then
|
2018-02-13 23:59:19 -05:00
|
|
|
echo "OSX version '${osx_host_version}' is not supported. Minimum supported version: ${OSX_VERSION}"
|
2016-11-07 16:28:41 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
return
|
2015-10-20 14:47:45 -04:00
|
|
|
;;
|
2015-02-15 17:48:11 -05:00
|
|
|
*)
|
2018-02-13 23:59:19 -05:00
|
|
|
echo "OS '${KNAME}' is not supported. Supported OS: [Linux, FreeBSD, OpenBSD, NetBSD, Darwin, DragonFly]"
|
2016-11-07 16:28:41 -05:00
|
|
|
exit 1
|
2015-02-15 17:48:11 -05:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2016-11-07 16:28:41 -05:00
|
|
|
assert_check_golang_env() {
|
|
|
|
if ! which go >/dev/null 2>&1; then
|
2018-02-13 23:59:19 -05:00
|
|
|
echo "Cannot find go binary in your PATH configuration, please refer to Go installation document at https://docs.minio.io/docs/how-to-install-golang"
|
2016-11-07 16:28:41 -05:00
|
|
|
exit 1
|
2015-02-15 03:48:15 -05:00
|
|
|
fi
|
|
|
|
|
2016-11-07 16:28:41 -05:00
|
|
|
installed_go_version=$(go version | sed 's/^.* go\([0-9.]*\).*$/\1/')
|
|
|
|
if ! check_minimum_version "${GO_VERSION}" "${installed_go_version}"; then
|
2018-02-13 23:59:19 -05:00
|
|
|
echo "Go runtime version '${installed_go_version}' is unsupported. Minimum supported version: ${GO_VERSION} to compile."
|
2016-11-07 16:28:41 -05:00
|
|
|
exit 1
|
2015-02-15 03:48:15 -05:00
|
|
|
fi
|
2016-11-07 16:28:41 -05:00
|
|
|
}
|
2015-02-15 03:48:15 -05:00
|
|
|
|
2016-11-07 16:28:41 -05:00
|
|
|
assert_check_deps() {
|
2016-12-31 22:57:33 -05:00
|
|
|
# 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";')
|
2016-11-07 16:28:41 -05:00
|
|
|
if ! check_minimum_version "${GIT_VERSION}" "${installed_git_version}"; then
|
2018-02-13 23:59:19 -05:00
|
|
|
echo "Git version '${installed_git_version}' is not supported. Minimum supported version: ${GIT_VERSION}"
|
2015-07-27 21:09:23 -04:00
|
|
|
exit 1
|
2015-02-15 03:48:15 -05:00
|
|
|
fi
|
2016-11-07 16:28:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
## Check for supported arch
|
|
|
|
assert_is_supported_arch
|
|
|
|
|
|
|
|
## Check for supported os
|
|
|
|
assert_is_supported_os
|
|
|
|
|
|
|
|
## Check for Go environment
|
|
|
|
assert_check_golang_env
|
|
|
|
|
|
|
|
## Check for dependencies
|
|
|
|
assert_check_deps
|
2015-02-13 04:08:52 -05:00
|
|
|
}
|
|
|
|
|
2015-02-15 03:48:15 -05:00
|
|
|
_init && main "$@"
|