#!/bin/sh
##
##  ripedb-setup
##

#   determine MySQL root password
password=`grep "^password" @l_prefix@/etc/mysql/my.pwd |\
          sed -e 's;^password[^=]*= *;;' -e 's; *$;;'`

#   create a MySQL username/password for RIPEDB and RIPADMIN
@l_prefix@/bin/mysql --user=root --password=$password mysql <<EOF
GRANT ALL ON RIPEDB.* TO ripe@localhost IDENTIFIED BY 'RIPEDB';
GRANT ALL ON RIPADMIN.* TO ripe@localhost IDENTIFIED BY 'RIPADMIN';
FLUSH PRIVILEGES;
EOF

#   create the default RIPEDB database schema
@l_prefix@/bin/mysqladmin --user=root --password=$password create RIPEDB
@l_prefix@/bin/mysql --user=root --password=$password RIPEDB <@l_prefix@/libexec/ripe-dbase/SQL/create.tables.sql
@l_prefix@/bin/mysql --user=root --password=$password RIPEDB <@l_prefix@/libexec/ripe-dbase/SQL/main.index.1
@l_prefix@/bin/mysql --user=root --password=$password RIPEDB <@l_prefix@/libexec/ripe-dbase/SQL/aux.index.2
@l_prefix@/bin/mysql --user=root --password=$password RIPEDB <@l_prefix@/libexec/ripe-dbase/SQL/leaf.index.2

#   create the default RIPADMIN database schema
@l_prefix@/bin/mysql --user=root --password=$password <@l_prefix@/libexec/ripe-dbase/SQL/create.RIPADMIN.sql

