#!/usr/bin/env bash

SETTINGS_FILE=$(find . -maxdepth 3 -type f -name 'settings.py' | head -1)
PROJECT=$(dirname $SETTINGS_FILE)
MANAGE_FILE=$(find . -maxdepth 3 -type f -name 'manage.py' | head -1)
MANAGE_FILE=${MANAGE_FILE:2}

if [ "$FRESH_APP" ]; then
    # Legacy Django injection for existing applications.
    touch .heroku/injection_disabled
fi

# Disable injection for new applications.
if [ -f .heroku/injection_disabled ]; then
  DISABLE_INJECTION=1
fi

if [ -f .heroku/collectstatic_disabled ]; then
  DISABLE_COLLECTSTATIC=1
fi

export SETTINGS_FILE MANAGE_FILE PROJECT DISABLE_INJECTION

if [ ! "$DISABLE_INJECTION" ]; then
    # Legacy Django injection for existing applications.
    source $BIN_DIR/steps/django/injection
fi

if [ ! "$DISABLE_COLLECTSTATIC" ]; then
    source $BIN_DIR/steps/django/collectstatic
fi

