#!/bin/bash -x

export APP="$(realpath "$1")"
export CACHE="$2"
export ENV="$3"
export BP="$(realpath "$(dirname "$0")/..")"
export PATH="$PATH:$BP/bin"

if ! test -d "$CACHE"
then mkdir "$CACHE"
fi

. "$BP/bin/read_config"

tar -xvzf "$BP/uml.tar.gz" -C "$APP"

mkdir "$APP/.profile.d"
cp "$BP/bin/read_config" "$APP/.profile.d/uml_read_config.sh"
cp "$BP/bin/redirect_PORT" "$APP/.profile.d/uml_redirect_PORT.sh"

fix_procfile "$APP/Procfile"
