# sets mysql root pw and horde dbs
#
# <thomas@linuxmuster.net>
# 26.11.2013
# GPL v3
#

echo "### 10_mysql prepatch"

/etc/init.d/mysql start

if [ "$1" = "--first" ]; then

  dpkg -L horde3 &> /dev/null && $SCRIPTSDIR/create-horde-db.sh

  if [ ! -f /root/.my.cnf ]; then
    echo "Creating /root/.my.cnf ..."
    myrootpw=`pwgen -s 24 1`
    mysqladmin -u root password $myrootpw
    echo "[client]" > /root/.my.cnf
    echo "user            = root" >> /root/.my.cnf
    echo "password        = $myrootpw" >> /root/.my.cnf
    echo "[mysqladmin]" >> /root/.my.cnf
    echo "user            = root" >> /root/.my.cnf
    echo "password        = $myrootpw" >> /root/.my.cnf
    chmod 600 /root/.my.cnf
  fi

fi
