#!/bin/sh
set -eux

# Render environment variables in the config file.
tempfile="$(mktemp)"
envsubst < /var/lib/ldap-account-manager/config/lam.conf > "$tempfile"
cat "$tempfile" > /var/lib/ldap-account-manager/config/lam.conf
rm "$tempfile"

# Set the password and unset the variable from memory.
chroot --userspec=www-data / /usr/local/sbin/lam-setpass "$LAM_PASSWORD"
unset LAM_PASSWORD

# Start the process.
eval exec "$@"
