#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
  DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
EXECUTION_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"

NODE_PATH="${EXECUTION_DIR}:${EXECUTION_DIR}/node_modules"
export NODE_PATH="${NODE_PATH}"

FCFNODE_PATH=`which fcfnode`
NODE_PATH=`which node`
if [[ -z "${FCFNODE_PATH}" || -z "${NODE_PATH}" ]]; then
  if [ -f "/etc/bash.bashrc" ]; then
  	source "/etc/bash.bashrc"
  fi
  USER_BASHRC_PATH=`realpath ~/.bashrc`
  if [ -f "${USER_BASHRC_PATH}" ]; then
  	source "${USER_BASHRC_PATH}"
  fi
fi

node "$EXECUTION_DIR/fcfmngr.js" $@
exit $?
