#!/usr/bin/env bash
#----------------------------------------------------------------------#
# This file is a part of ShapeMapper, and is licensed under the terms  #
# of the MIT license. Copyright 2018 Steven Busan.                     #
#----------------------------------------------------------------------#

# warn if attempting to run on a Mac
if [ "$(uname)" == "Darwin" ]; then
    msg="ShapeMapper is only currently built for 64-bit Linux. "
    msg+="Mac is unsupported."
    echo "$msg"
    exit 1
fi

# Find the parent folder of this script,
# resolving (possibly nested) symlinks
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
    THIS_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
    SOURCE="$(readlink "$SOURCE")"
    [[ $SOURCE != /* ]] && SOURCE="$THIS_DIR/$SOURCE"
done
THIS_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"


# Locating the parent directory doesn't work in all contexts
# (e.g. inside a Docker container AFAICT) so look at an
# environment var in those cases
if [ ! -z "${SHAPEMAPPER_ROOT_DIR}" ]; then
    THIS_DIR="${SHAPEMAPPER_ROOT_DIR}"
fi

source ${THIS_DIR}/libexec/paths/bin_paths.sh

# warn user if executables are not present
if [ -z $(which shapemapper_read_trimmer) ] || \
   [ -z $(which shapemapper_mutation_parser) ] || \
   [ -z $(which shapemapper_mutation_counter) ]; then
    msg="Error: can't find core shapemapper executables. Download "
    msg+="the full release tarball (not just the source code) "
    msg+="which includes compiled executables."
    echo "$msg"
    exit 1
fi

exec /opt/gensoft/exe/shapemapper/2.3.2/venv/bin/python3.8 ${THIS_DIR}/libexec/python/cli.py "$@"


