#!/usr/bin/env bash

#
#	MetaCall Build Bash Script by Parra Studios
#	Build and install bash script utility for MetaCall.
#
#	Copyright (C) 2016 - 2021 Vicente Eduardo Ferrer Garcia <vic798@gmail.com>
#
#	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.
#

# Load default environment variables (this must be run from tools/<image> path)
source ../../.env

# These values are passed by the Hub, but if we are running locally we can get them
[ -n "$SOURCE_TYPE" ] || SOURCE_TYPE=git
[ -n "$SOURCE_BRANCH" ] || SOURCE_BRANCH=$(git symbolic-ref -q --short HEAD)
[ -n "$GIT_SHA1" ] || GIT_SHA1=$(git rev-parse -q HEAD)

if [[ "${SOURCE_BRANCH/-*/}" =~ ^[0-9][0-9.]*$ ]]; then
	VERSION=${SOURCE_BRANCH/-*/}
fi

# Set dockerfile path if it is not absolute or if it is not defined
if [ ! -n "$DOCKERFILE_PATH" ] || [ ! "${DOCKERFILE_PATH:0:1}" = "/" ]; then
	DOCKERFILE_PATH="`pwd`/Dockerfile"
fi
