#!/bin/sh -e
#
# Startup script for MySQL daemon.
# Copyright (C) 2001  Dmitry V. Levin <ldv@fandra.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

PROG="${0##*/}"

GetConf()
{
	local group=$1
	[ -n "$group" ] || group="$PROG"
	shift

	local name=$1
	shift

	local varname=$1
	[ -n "$varname" ] || varname="$name"
	shift

	local default=$1
	shift

	local val=`my_print_defaults "$group" |grep "^--$name=" |tail -1`
	if [ -n "$val" ]; then
		eval export $varname="${val#--$name=}"
	else
		eval export $varname="$default"
	fi
}

GetConf '' mysqld '' /usr/sbin/mysqld
GetConf '' logfile '' /var/log/mysql/info
GetConf mysqld chroot '' /var/lib/mysql
GetConf mysqld socket '' "$chroot/mysql.sock"
GetConf mysqld pid-file pidfile "$chroot/mysqld.pid"

umask 007

# Test arguments.
$mysqld "$@" -V >/dev/null

/usr/sbin/mysqld_wrapper "$@" &
