#!/bin/sh
set -e

WORKDIR="${APACHE_DOCUMENT_ROOT:-/var/www/html}"

setup_ssh() {
    mkdir -p /var/run/sshd

    PASS="${PROJETS_ROOT_PASSWORD:-${MAIA_ROOT_PASSWORD:-}}"
    if [ -n "$PASS" ]; then
        echo "root:${PASS}" | chpasswd
    fi

    if ! /usr/sbin/sshd; then
        echo "projets-php: sshd non démarré (Apache continue)." >&2
        return 0
    fi
    echo "projets-php: sshd démarré dans le conteneur (port 22)." >&2
}

setup_ssh
exec apache2-foreground
