#!/bin/sh
##
##  drupal-setup
##

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

#   create the MySQL database for Drupal
@l_prefix@/bin/mysqladmin --user=root --password=$password create drupal
@l_prefix@/bin/mysql --user=root --password=$password mysql <<EOF
GRANT ALL ON drupal.* TO drupal@localhost IDENTIFIED BY 'drupal';
FLUSH PRIVILEGES;
EOF

#   create the default Drupal database schema
@l_prefix@/bin/mysql --user=root --password=$password drupal \
    <@l_prefix@/share/drupal/database/database.mysql

#  configure /etc/drupal/default/settings.php accordingly
@l_prefix@/lib/openpkg/shtool subst \
    -e '/^\$db_url =/s;mysql://username:password@localhost/database;mysql://drupal:drupal@localhost/drupal;' \
    @l_prefix@/etc/drupal/default/settings.php
