#!/bin/sh

## install wordpress with cli : https://make.wordpress.org/cli/handbook/how-to-install/
mkdir -p ${WP_DIR}
wp core download --path="${WP_DIR}" --allow-root

#	mariadb --execute="CREATE DATABASE ${DB_NAME};" && \
#	mariadb --execute="CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PSWD}';" && \
#	mariadb --execute="GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'localhost' with grant option;"

## create config file :
wp config create \
	--dbhost=mariadb \
	--dbname="${DB_NAME}" \
	--dbuser="${DB_USER}" \
	--dbpass="${DB_PASS}" \
	--path="${WP_DIR}" --allow-root

## install wordpress :
wp core install \
	--url="${WP_URL}" \
	--title="${WP_TITLE}" \
	--admin_user="${WP_ADMIN}" \
	--admin_email="${WP_ADMIN_EMAIL}" \
	--admin_password="${WP_ADMIN_PSWD}" \
	--skip-email \
	--path="${WP_DIR}" --allow-root

## create user :
wp user create \
	${WP_USER} ${WP_USER_EMAIL} \
	--user_pass=${WP_USER_PSWD} \
	--path=${WP_DIR} --allow-root
chown -R nginx:nginx /var/www/*
chmod 755 -R /var/www/*

exec php-fpm7.3 -F
#exec php-fpm7.3 --nodaemonize
