#! /bin/bash

# Check if CK_ROOT is defined and used it, otherwise use auto-detected path
if [ -z "$CK_ROOT" ]; then 
  CK_path1=`dirname $0`
  pushd $CK_path1/.. > /dev/null
  CK_path=`pwd`
  popd > /dev/null
  export CK_ROOT=$CK_path; 
fi

# Check which python to use
if [ "$CK_PYTHON" != "" ]; then
   export PYTHON=$CK_PYTHON
fi

if [ -z "$PYTHON" ]; then
   if $(python3 --version &> /dev/null) ; then
      export PYTHON=python3
   else
      export PYTHON=python
   fi
fi

# Load kernel module (either GIT/local installation or as package)
if [ -f "$CK_ROOT/ck/kernel.py" ]; then 
 $PYTHON -W ignore::DeprecationWarning $CK_ROOT/ck/kernel.py "$@"
else
 $PYTHON -m ck.kernel "$@"
fi
