#!/usr/bin/env bash

# Get remote console for the app
# This needs to be run under the app user account

# Exit on errors
set -e

# Config vars
DEPLOY_DIR="<%= deploy_dir %>"
RUNTIME_DIR="<%= runtime_dir %>"
APP_NAME="<%= app_name %>"
export LANG="<%= env_lang %>"

CURRENT_DIR="$DEPLOY_DIR/current"
export RELEASE_MUTABLE_DIR="<%= runtime_dir %>"
<%= if conform do %>
export CONFORM_CONF_PATH="<%= conform_conf_path %>"
<% end %>

CURRENT_ENV="<%= current_dir %>/etc/environment"
DEPLOY_ENV="<%= deploy_dir %>/etc/environment"
CONFIGURATION_ENV="<%= configuration_dir %>/environment"
RUNTIME_ENV="<%= runtime_dir %>/runtime-environment"

if [ -f "$CURRENT_ENV" ]; then
    source "$CURRENT_ENV"
fi

if [ -f "$DEPLOY_ENV" ]; then
    source "$DEPLOY_ENV"
fi

if [ -f "$CONFIGURATION_ENV" ]; then
    source "$CONFIGURATION_ENV"
fi

if [ -f "$RUNTIME_ENV" ]; then
    source "$RUNTIME_ENV"
fi

$CURRENT_DIR/bin/$APP_NAME remote_console
