#!/bin/sh


#migrate DB
cd /var/www/html
while ! mysqladmin ping -h"db" --silent; do
    sleep 1
done
echo "Ready...."

sudo -u www-data -s -- <<EOF
    # Export variables for www-data user so they
    # are accessible when running wp CLI
    export WP_ENV="$WP_ENV"
    export WP_HOME="$WP_HOME"
    export WP_DB_HOST="$WP_DB_HOST"
    export MYSQL_DATABASE="$MYSQL_DATABASE"
    export MYSQL_USER="$MYSQL_USER"
    export MYSQL_PASSWORD="$MYSQL_PASSWORD"
    export WP_AUTH_KEY="$WP_AUTH_KEY"
    export WP_SECURE_AUTH_KEY="$WP_SECURE_AUTH_KEY"
    export WP_LOGGED_IN_KEY="$WP_LOGGED_IN_KEY"
    export WP_NONCE_KEY="$WP_NONCE_KEY"
    export WP_AUTH_SALT="$WP_AUTH_SALT"
    export WP_SECURE_AUTH_SALT="$WP_SECURE_AUTH_SALT"
    export WP_LOGGED_IN_SALT="$WP_LOGGED_IN_SALT"
    export WP_NONCE_SALT="$WP_NONCE_SALT"
    export WP_JWT_AUTH_SECRET_KEY="$WP_JWT_AUTH_SECRET_KEY"

    # Execute database update
    composer update-db

EOF

echo "Done"

#start image
exec apache2-foreground
