# Copyright 2025-2026 Thomas Hintz

# This file is part of Nassella.

# Nassella is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.

# Nassella is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with Nassella. If not, see <https://www.gnu.org/licenses/>.

IMAGE_DEPS := $(IMAGE_DEPS) \
app/nassella/postgres_db \
app/nassella/postgres_user \
app/nassella/postgres_password \
app/nassella/lldap_postgres_db \
app/nassella/lldap_postgres_user \
app/nassella/lldap_postgres_password \
app/nassella/authelia_postgres_db \
app/nassella/authelia_postgres_user \
app/nassella/authelia_postgres_password \
app/nassella/nassella.env \
app/nassella/authelia-config/configuration.yml \
app/nassella/lldap-config/lldap_config.toml

app/nassella/postgres_db: $(apps_config)
	bash -c 'source ./$(apps_config); printf "%s\n" "$$NASSELLA_POSTGRES_DB" > $@'
app/nassella/postgres_user: $(apps_config)
	bash -c 'source ./$(apps_config); printf "%s\n" "$$NASSELLA_POSTGRES_USER" > $@'
app/nassella/postgres_password: $(apps_config)
	bash -c 'source ./$(apps_config); printf "%s\n" "$$NASSELLA_POSTGRES_PASSWORD" > $@'
app/nassella/authelia_postgres_db: $(apps_config)
	bash -c 'source ./$(apps_config); printf "%s\n" "$$NASSELLA_AUTHELIA_POSTGRES_DB" > $@'
app/nassella/authelia_postgres_user: $(apps_config)
	bash -c 'source ./$(apps_config); printf "%s\n" "$$NASSELLA_AUTHELIA_POSTGRES_USER" > $@'
app/nassella/authelia_postgres_password: $(apps_config)
	bash -c 'source ./$(apps_config); printf "%s\n" "$$NASSELLA_AUTHELIA_POSTGRES_PASSWORD" > $@'
app/nassella/lldap_postgres_db: $(apps_config)
	bash -c 'source ./$(apps_config); printf "%s\n" "$$NASSELLA_LLDAP_POSTGRES_DB" > $@'
app/nassella/lldap_postgres_user: $(apps_config)
	bash -c 'source ./$(apps_config); printf "%s\n" "$$NASSELLA_LLDAP_POSTGRES_USER" > $@'
app/nassella/lldap_postgres_password: $(apps_config)
	bash -c 'source ./$(apps_config); printf "%s\n" "$$NASSELLA_LLDAP_POSTGRES_PASSWORD" > $@'
app/nassella/lldap_admin_password: $(apps_config)
	bash -c 'source ./$(apps_config); printf "%s\n" "$$NASSELLA_LLDAP_ADMIN_PASSWORD" > $@'
app/nassella/stripe_api_key: $(apps_config)
	bash -c 'source ./$(apps_config); printf "%s\n" "$$NASSELLA_STRIPE_API_KEY" > $@'
app/nassella/authelia-config/configuration.yml: $(apps_config) app/nassella/authelia-config/configuration.yml.tmpl \
app/nassella/make-nassella-authelia-config.sh
	./app/nassella/make-nassella-authelia-config.sh $(apps_config)
app/nassella/lldap-config/lldap_config.toml: $(apps_config) app/nassella/lldap-config/lldap_config.toml.tmpl \
app/nassella/make-nassella-lldap-config.sh
	./app/nassella/make-nassella-lldap-config.sh $(apps_config)
