#!/bin/sh

NODE_CMD=${NODE_HOME}/node
if [ ! -f "${NODE_CMD}" ]; then
    NODE_CMD=node
fi

if [ $? != 0 ]; then
  echo
  echo -e "\033[31mERROR: NODE_HOME is not set and 'node' command not found in your PATH.\033[0m"
  echo
  echo -e "\033[31mPlease set the NODE_HOME variable in your environment to match the location of your NodeJs installation.\033[0m"
  exit 1
fi

basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case $(uname) in
    *CYGWIN*|*MINGW*|*MSYS*) basedir=$(cygpath -w "$basedir");;
esac

PM_CLI_JS=${basedir}/pm-cli.js

if [ $? != 0 ]; then
  echo -e "\033[31mERROR: ohpm has not been initialized yet. Execute the init script to initialize it first.\033[0m"
  exit 1
fi

exec "${NODE_CMD}" "${PM_CLI_JS}" "$@"
