#!/bin/sh
##
##  sympa-setup.sh -- Sympa MySQL Setup Utility
##

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

#   determine Sympa database password
sympa_password=`grep "^db_passwd" @l_prefix@/etc/sympa/sympa.conf |\
          sed -e 's;^db_passwd[ 	]*;;' -e 's; *$;;'`

cmd="${1:-'install'}"
case "$cmd" in
    install )
        #   create the default Sympa database schema
        @l_prefix@/bin/mysql \
            --user=$mysql_username --password=$mysql_password \
            mysql <@l_prefix@/share/sympa/script/create_db.mysql

        #   create a MySQL username/password for Sympa
        @l_prefix@/bin/mysql \
            --user=$mysql_username --password=$mysql_password \
            mysql <<EOF
        GRANT ALL ON sympa.* TO sympa@localhost IDENTIFIED BY '$sympa_password';
        FLUSH PRIVILEGES;
EOF
        ;;
    uninstall )
        @l_prefix@/bin/mysql \
            --user=$mysql_username --password=$mysql_password \
            mysql <<EOF
        DROP DATABASE sympa;
EOF
        ;;
esac

