#!/bin/sh

# 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

	hn=$(hostname)
	/usr/bin/mysql -uroot -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'; grant all privileges on $1.* to '$2'@'$hn' identified by '$3';" >/dev/null 2>&1
}

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

