#!/bin/bash

# This script is a hook called via the dt-install-sandbox-software command.
# Do not run it directly.

[ -z "$1" ] && echo "Run dt-install-sandbox-software to call this script" && exit 1

if [ "$1" != "--env-loaded" ]; then
	[ -z "$2" ] && echo "Run dt-install-sandbox-software (version 1) to call this script" && exit 1
	[ -z "$CS_API_SANDBOX" ] && export CS_API_SANDBOX=$1  # root of the sandbox
	[ -z "$CS_API_TOP" ] && export CS_API_TOP=$2          # root of the primary git project
	SB_ENV_FILE=$3            # name of the environment file to use
	[ -z "$CS_API_NAME" ] && export CS_API_NAME=`dirname $CS_API_SANDBOX`
	[ -z "$SB_ENV_FILE" ] && SB_ENV_FILE=defaults.sh
	. $CS_API_TOP/sandbox/$SB_ENV_FILE
fi

# Install node if specified with CS_API_NODE_VER
[ -n "$CS_API_NODE_VER" -a ! -L $CS_API_SANDBOX/node ] && dt-get-software -V $CS_API_NODE_VER node $CS_API_SANDBOX

[ ! -d $CS_API_REPO_ROOT/.git ] && echo "This is a runtime environment installation" && exit 0

exit 0
