#!/bin/bash
set -e

if [[ $(CreoleGet mode_conteneur_actif) == "oui" ]]; then
    container_path=$(CreoleGet container_path_domaine)
fi

PRIVATE_DIR=$container_path/etc/eole/private

# Permit to join workstation to the domain
MANAGER_PASS_FILE="${PRIVATE_DIR}/eole-workstation-manager.password"

# Lookup information in Active Directory
READER_PASS_FILE="${PRIVATE_DIR}/eole-workstation-reader.password"

if [ ! -d "${PRIVATE_DIR}" ]
then
    mkdir -p "${PRIVATE_DIR}"
    chmod 700 "${PRIVATE_DIR}"
fi

# Reset password at each reconfigure
pwgen -scn1 42 > "${MANAGER_PASS_FILE}"
chmod 700 "${MANAGER_PASS_FILE}"

if [ ! -s "${READER_PASS_FILE}" ]
then
    # Long time password
    pwgen -scn1 42 > "${READER_PASS_FILE}"
fi
chmod 700 "${READER_PASS_FILE}"

exit 0
