#!/bin/sh

# Create app dirs on target or staging dir
#
# This creates the release directory structure, e.g. /srv/foo,
# and may create app dirs such as /etc/foo when they
# are not automatically created by systemd.

set -e

# Environment vars
# DESTDIR, prefix for target files, optional

# Config vars
DEPLOY_USER="${DEPLOY_USER:-<%= deploy_user %>}"
DEPLOY_GROUP="${DEPLOY_GROUP:-<%= deploy_group %>}"
APP_USER="${APP_USER:-<%= app_user %>}"
APP_GROUP="${APP_GROUP:-<%= app_group %>}"

<%= for dir <- create_dirs, dir[:enabled] != false do %>
<% if dir[:comment] do %># <%= dir.comment %><% end %>
if [ ! -d "${DESTDIR}<%= dir.path %>" ]; then
  echo "==> Creating dir ${DESTDIR}<%= dir.path %>"
  mkdir -p "${DESTDIR}<%= dir.path %>"
  <%= if dir[:user] do %>chown <%= dir.user %>:<%= dir.group %> "${DESTDIR}<%= dir.path %>"<% end %>
  <%= if dir[:mode] do %>chmod <%= dir.mode %> "${DESTDIR}<%= dir.path %>"<% end %>
fi
<% end %>
