#!/bin/bash

# Get the path to this script in SCRIPT_DIR, preserving cwd
ORIG_DIR=$(pwd)
cd "$(dirname "$0")"
SCRIPT_DIR=$(pwd -P)
cd "$ORIG_DIR"

# Find the top of the tools tree (not to be confused with the 'tools'
# directory in that tree)
TOOLS_DIR="$SCRIPT_DIR/../../.."

# Find our binary dependencies (node).
if [ -d "$TOOLS_DIR/.git" ] || [ -f "$TOOLS_DIR/.git" ]; then
    # In a checkout.
    DEV_BUNDLE="$TOOLS_DIR/dev_bundle"
else
    # In an install.
    DEV_BUNDLE="$TOOLS_DIR"
fi

# Have at it!
export NODE_PATH="$DEV_BUNDLE/lib/node_modules"
exec "$DEV_BUNDLE/bin/node" "$SCRIPT_DIR/fake-mongod.js" "$@"
