#!/usr/bin/env bash

# Copyright 2018 Analytics Zoo Authors.
#
# 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.

if (( $# < 2)); then
  echo "getting $* $#"
  echo "Bad parameters. Usage example: bash get_bigdl_python.sh /tmp/bigdl_python/ 0.5.0"
  exit -1
fi

DEST_DIR=$1
echo "DEST_DIR: $DEST_DIR"
BIGDL_VERSION=$2
echo "BIGDL_VERSION: $BIGDL_VERSION"

rm -rf $DEST_DIR/*

GET_COMMAND="mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get \
-DartifactId=dist-spark-2.2.0-scala-2.11.8-all \
-DgroupId=com.intel.analytics.bigdl \
-Dversion=${BIGDL_VERSION} \
-Dclassifier=python-api \
-Dpackaging=zip \
-Ddest=${DEST_DIR}/bigdl-python-api-${BIGDL_VERSION}.zip"

echo "Running: $GET_COMMAND"
$GET_COMMAND

exit_status=$?
if [ $exit_status -ne 0 ];
then
    rm -rf ${DEST_DIR}
    echo "Fail to get the BigDL python api from maven!!!!"
    exit $exit_status_1
fi

cd ${DEST_DIR}
mkdir sources
unzip bigdl-python-api-${BIGDL_VERSION}.zip -d sources

