#!/bin/bash

# function to "declare" the database that exist
hasdb() {
	/usr/bin/mysql -s -u $2 -p$3 $1 > /dev/null 2>&1 << EOF
EOF

	if [[ $? -eq 0 ]]; then
		return
	fi

	/usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf -u debian-sys-maint -s -e "create database	if not exists $1; grant all privileges on $1.* to '$2'@'%' identified by '$3'; grant all privileges on $1.* to '$2'@'localhost' identified by '$3';" >/dev/null 2>&1
}

[ -e /etc/mysql/databases ] && . /etc/mysql/databases

