#!/usr/bin/env sh

set -e

mysql=@MYSQL@
mysql_admin=@MYSQL_ADMIN@
mysql_admin_passwd=@MYSQL_ADMIN_PASSWD@
mysql_host=@MYSQL_HOST_WITHOUT_PORT@
mysql_port=@MYSQL_PORT@
db_name=@TANGO_DB_NAME@

if test "x$mysql_admin" = "x"; then
	user_switch="";
else
	user_switch="-u$x$mysql_admin";
fi

if test "x$mysql_admin_passwd" = "x"; then
   passwd_switch="";
else
   passwd_switch="-p$mysql_admin_passwd"
fi

if test "x$mysql_host" = "x"; then
  host_switch="";
else
  host_switch="-h$mysql_host";
fi

if test "x$mysql_port" = "x"; then
  port_switch="--port=0";
else
  port_switch="--port=$mysql_port";
fi

$mysql $user_switch $passwd_switch $host_switch $port_switch < ./update_stored_procedures.sql > /dev/null
