#!/bin/sh

set -e

# Check if the MySQL database dvwa exists.
# If the DB does not exist, it will create the DB, the DB user and the
# user password.

if ! mysql -e "use dvwa" > /dev/null 2>&1; then
    sudo mysql -Bse "CREATE DATABASE IF NOT EXISTS dvwa;"
    sudo mysql -Bse "CREATE USER IF NOT EXISTS dvwa@localhost IDENTIFIED BY 'p@ssw0rd';"
    sudo mysql -Bse "GRANT ALL ON dvwa.* TO dvwa@localhost;"
    sudo mysql -Bse "FLUSH PRIVILEGES;"
fi
