2015-02-17 13:17:31 -05:00
|
|
|
#!/usr/bin/env bash
|
2015-02-15 03:48:15 -05:00
|
|
|
#
|
2015-07-24 20:51:40 -04:00
|
|
|
# Minio Cloud Storage, (C) 2015 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"
|
2016-02-10 00:51:03 -05:00
|
|
|
CURL_VERSION="7.12.0"
|
2016-02-05 06:10:17 -05:00
|
|
|
GPG_VERSION="1.3"
|
2015-09-17 19:32:09 -04:00
|
|
|
GO_VERSION="1.5.1"
|
2015-02-15 17:48:11 -05:00
|
|
|
OSX_VERSION="10.8"
|
|
|
|
UNAME=$(uname -sm)
|
2015-02-15 03:48:15 -05:00
|
|
|
|
|
|
|
## Check all dependencies are present
|
|
|
|
MISSING=""
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-02-15 03:48:15 -05:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# Takes two arguments
|
|
|
|
# arg1: version number in `x.x.x` format
|
|
|
|
# arg2: version number in `x.x.x` format
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
####
|
2015-07-27 21:09:23 -04:00
|
|
|
check_version() {
|
2015-02-15 03:48:15 -05:00
|
|
|
## validate args
|
|
|
|
[[ -z "$1" ]] && return 3
|
|
|
|
[[ -z "$2" ]] && return 3
|
|
|
|
|
|
|
|
if [[ $1 == $2 ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
local IFS=.
|
|
|
|
local i ver1=($1) ver2=($2)
|
|
|
|
# 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
|
|
|
|
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if ((10#${ver1[i]} < 10#${ver2[i]})); then
|
2015-07-27 21:09:23 -04:00
|
|
|
## Installed version is lesser than required - Bad condition
|
2015-02-15 03:48:15 -05:00
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
check_golang_env() {
|
|
|
|
echo ${GOROOT:?} 2>&1 >/dev/null
|
|
|
|
if [ $? -eq 1 ]; then
|
2015-07-27 21:09:23 -04:00
|
|
|
echo "ERROR"
|
|
|
|
echo "GOROOT environment variable missing, please refer to Go installation document"
|
|
|
|
echo "https://github.com/minio/minio/blob/master/INSTALLGO.md#install-go-13"
|
|
|
|
exit 1
|
2015-02-15 03:48:15 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo ${GOPATH:?} 2>&1 >/dev/null
|
|
|
|
if [ $? -eq 1 ]; then
|
2015-07-27 21:09:23 -04:00
|
|
|
echo "ERROR"
|
|
|
|
echo "GOPATH environment variable missing, please refer to Go installation document"
|
|
|
|
echo "https://github.com/minio/minio/blob/master/INSTALLGO.md#install-go-13"
|
|
|
|
exit 1
|
2015-02-15 03:48:15 -05:00
|
|
|
fi
|
2015-06-23 12:44:05 -04:00
|
|
|
|
|
|
|
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 "https://github.com/minio/minio/blob/master/INSTALLGO.md#install-go-13"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
2015-07-05 21:12:58 -04:00
|
|
|
local new_go_binary_path=${go_binary_path}
|
|
|
|
if [ -h "${go_binary_path}" ]; then
|
2015-07-27 21:09:23 -04:00
|
|
|
new_go_binary_path=$(readlink ${go_binary_path})
|
2015-07-05 21:12:58 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ !"$(dirname ${new_go_binary_path})" =~ *"${GOROOT%%*(/)}"* ]] ; then
|
2015-06-23 12:44:05 -04:00
|
|
|
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 "https://github.com/minio/minio/blob/master/INSTALLGO.md#install-go-13"
|
|
|
|
exit -1
|
|
|
|
fi
|
2015-02-15 03:48:15 -05:00
|
|
|
}
|
|
|
|
|
2015-02-15 17:48:11 -05:00
|
|
|
is_supported_os() {
|
|
|
|
case ${UNAME%% *} in
|
|
|
|
"Linux")
|
|
|
|
os="linux"
|
|
|
|
;;
|
2015-07-27 21:09:23 -04:00
|
|
|
"Darwin")
|
|
|
|
osx_host_version=$(env sw_vers -productVersion)
|
|
|
|
check_version "${osx_host_version}" "${OSX_VERSION}"
|
|
|
|
[[ $? -ge 2 ]] && die "Minimum OSX version supported is ${OSX_VERSION}"
|
|
|
|
;;
|
|
|
|
"*")
|
|
|
|
echo "Exiting.. unsupported operating system found"
|
|
|
|
exit 1;
|
2015-02-15 17:48:11 -05:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
is_supported_arch() {
|
|
|
|
local supported
|
|
|
|
case ${UNAME##* } in
|
|
|
|
"x86_64")
|
|
|
|
supported=1
|
|
|
|
;;
|
2015-10-20 14:47:45 -04:00
|
|
|
"arm"*)
|
|
|
|
supported=1
|
|
|
|
;;
|
2015-02-15 17:48:11 -05:00
|
|
|
*)
|
|
|
|
supported=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
if [ $supported -eq 0 ]; then
|
|
|
|
echo "Invalid arch: ${UNAME} not supported, please use x86_64/amd64"
|
2015-07-27 21:09:23 -04:00
|
|
|
exit 1;
|
2015-02-15 17:48:11 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-02-15 03:48:15 -05:00
|
|
|
check_deps() {
|
|
|
|
check_version "$(env go version 2>/dev/null | sed 's/^.* go\([0-9.]*\).*$/\1/')" "${GO_VERSION}"
|
|
|
|
if [ $? -ge 2 ]; then
|
2015-09-19 03:52:01 -04:00
|
|
|
MISSING="${MISSING} golang(${GO_VERSION})"
|
2015-02-15 03:48:15 -05:00
|
|
|
fi
|
|
|
|
|
2015-02-20 03:21:43 -05:00
|
|
|
check_version "$(env git --version 2>/dev/null | sed -e 's/^.* \([0-9.\].*\).*$/\1/' -e 's/^\([0-9.\]*\).*/\1/g')" "${GIT_VERSION}"
|
2015-02-15 03:48:15 -05:00
|
|
|
if [ $? -ge 2 ]; then
|
2015-07-27 21:09:23 -04:00
|
|
|
MISSING="${MISSING} git"
|
2015-02-15 03:48:15 -05:00
|
|
|
fi
|
2016-02-05 06:10:17 -05:00
|
|
|
|
|
|
|
check_version "$(env gpg --version 2>/dev/null | sed -e 's/^.* \([0-9.\].*\).*$/\1/' -e 's/^\([0-9.\]*\).*/\1/g' | head -1)" "${GPG_VERSION}"
|
|
|
|
if [ $? -ge 2 ]; then
|
|
|
|
MISSING="${MISSING} gpg"
|
|
|
|
fi
|
2016-02-10 00:51:03 -05:00
|
|
|
|
|
|
|
check_version "$(env curl --version 2>/dev/null | sed -e 's/^.* \([0-9.\].*\).*$/\1/' -e 's/^\([0-9.\]*\).*/\1/g' | head -1)" "${CURL_VERSION}"
|
|
|
|
if [ $? -ge 2 ]; then
|
|
|
|
MISSING="${MISSING} curl"
|
|
|
|
fi
|
2015-02-15 03:48:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2015-02-15 17:48:11 -05:00
|
|
|
echo -n "Check for supported arch.. "
|
|
|
|
is_supported_arch
|
|
|
|
|
|
|
|
echo -n "Check for supported os.. "
|
|
|
|
is_supported_os
|
|
|
|
|
2015-02-15 03:48:15 -05:00
|
|
|
echo -n "Checking if proper environment variables are set.. "
|
|
|
|
check_golang_env
|
|
|
|
|
|
|
|
echo "Done"
|
|
|
|
echo "Using GOPATH=${GOPATH} and GOROOT=${GOROOT}"
|
|
|
|
|
|
|
|
echo -n "Checking dependencies for Minio.. "
|
|
|
|
check_deps
|
|
|
|
|
|
|
|
## If dependencies are missing, warn the user and abort
|
|
|
|
if [ "x${MISSING}" != "x" ]; then
|
2015-07-27 21:09:23 -04:00
|
|
|
echo "ERROR"
|
|
|
|
echo
|
|
|
|
echo "The following build tools are missing:"
|
|
|
|
echo
|
|
|
|
echo "** ${MISSING} **"
|
|
|
|
echo
|
|
|
|
echo "Please install them "
|
|
|
|
echo "${MISSING}"
|
|
|
|
echo
|
|
|
|
echo "Follow https://github.com/minio/minio/blob/master/INSTALLGO.md for further instructions"
|
|
|
|
exit 1
|
2015-02-15 03:48:15 -05:00
|
|
|
fi
|
|
|
|
echo "Done"
|
2015-02-13 04:08:52 -05:00
|
|
|
}
|
|
|
|
|
2015-02-15 03:48:15 -05:00
|
|
|
_init && main "$@"
|