#!/bin/bash

#  Copyright 2007-2015 Zuse Institute Berlin
#
#   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.

# inspired by the start script of ant

prefix=/usr
exec_prefix=${prefix}
SCALARISDIR=${exec_prefix}/lib/scalaris
PYTHON3="/usr/bin/python3"
SCALARISCLIENT_PYTHON3="${prefix}/lib/python3.5/site-packages/scalaris_client.py"

if [ ! -x "$PYTHON3" -o "x$PYTHON3" = "x/usr/bin/false" ] ; then
  echo "Python not found or not executable: $PYTHON3"
  exit 1
fi

for arg in "$@"; do
  args="$args \"$arg\""
done

# activate no_config if called in the source tree:
ABSPATH="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
DIRNAME=`dirname $ABSPATH`
# is this a source checkout or an (rpm/deb/manual) installation?
if [ "$DIRNAME" != "${exec_prefix}/bin" -a "$DIRNAME" != "/bin" -a "${DIRNAME##*/}" = "python3-api" ]; then
  # local mode, i.e. uninstalled
  SCALARISCLIENT_PYTHON3="`dirname $0`/scalaris_client.py"
fi

eval $PYTHON3 $SCALARISCLIENT_PYTHON3 $args
