#!/bin/sh
##
##  typo3-setup
##

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

#   dispatch operation
cmd="${1:-"install"}"
case "$cmd" in
    install )
        #   create the MySQL database for TYPO3
        @l_prefix@/bin/mysqladmin --user="$username" --password="$password" create typo3
        ( echo "GRANT ALL ON typo3.* TO typo3@localhost IDENTIFIED BY 'typo3';"
          echo "FLUSH PRIVILEGES;"
        ) | @l_prefix@/bin/mysql --user="$username" --password="$password" typo3
        ;;
    uninstall )
        #   remove the database
        ( echo "DROP DATABASE typo3;"
        ) | @l_prefix@/bin/mysql --user="$username" --password="$password" mysql
        ;;
esac

