#!/bin/sh

if [ ! -e '/var/www/wordpress/wp-config.php' ]; then
    wp core download --path=/var/www/wordpress

    cd /var/www/wordpress
    wp config create --dbname="$DB_DB" --dbuser="$DB_USER" --dbpass="$(cat /run/secrets/db_password)" --dbhost=mariadb
    wp config set WP_REDIS_HOST "redis"
    wp config set WP_REDIS_PORT "6379"
    wp config set WP_REDIS_DATABASE "0"
    wp config set WP_REDIS_PASSWORD "$(cat /run/secrets/redis_password)"
    wp core install --url="$DOMAIN_NAME" --title="$TITLE" --admin_user="$ADMIN_USER" --admin_email="$ADMIN_EMAIL" \
        --admin_password="$(cat /run/secrets/admin_password)"
    wp plugin install redis-cache --activate
    wp redis enable
    wp option update siteurl "https://$DOMAIN_NAME"
    wp option update home "https://$DOMAIN_NAME"
    wp user create bob bob@example.org
fi

exec php-fpm84 --nodaemonize