#!/bin/sh

# Set up environment the same way it would be if run under
# the systemd unit file.

export LANG="${LANG:-C.UTF-1}"
export MIX_ENV="${MIX_ENV:-prod}"

<%= if :runtime in dirs do %>RUNTIME_DIR="<%= runtime_dir %>"<% end %>
<%= if :configuration in dirs do %>CONFIGURATION_DIR="<%= configuration_dir %>"<% end %>
<%= if :logs in dirs do %>LOGS_DIR="<%= logs_dir %>"<% end %>
<%= if :cache in dirs do %>CACHE_DIR="<%= cache_dir %>"<% end %>
<%= if :state in dirs do %>STATE_DIR="<%= state_dir %>"<% end %>
<%= if :tmp in dirs do %>TMP_DIR="<%= tmp_dir %>"<% end %>

<%= if conform_conf_path && conform_conf_path != "" do %>CONFORM_CONF_PATH="<%= conform_conf_path %>"<% end %>

<%= for env <- env_vars do %>
<%= env %>
<% end %>

<% env_files = Enum.map(env_files,
fn("-" <> value) -> value
  (value) -> value
end)
%>
<%= for file <- env_files do %>
if [ -f "<%= file %>" ]; then
    . "<%= file %>"
fi
<% end %>
