#!/bin/bash -e

. /usr/share/debconf/confmodule

LC_USER='robot-direct-admin'

touch /var/log/mysql-grants-update.log
chown $LC_USER -R /var/log/mysql-grants-update*.log /var/cache/grants
[ -f /etc/cron.d/mysql-grants ] && rm /etc/cron.d/mysql-grants
grep -i "$LC_USER" /etc/security/pam_env.conf > /dev/null || echo "LC_USER              DEFAULT='robot-direct-admin'" >> /etc/security/pam_env.conf

[ -e /etc/mysql-grants.conf ] && rm /etc/mysql-grants.conf
[ -e /etc/cron.d/mysql-grants-update ] && rm /etc/cron.d/mysql-grants-update
[ -e /etc/logrotate.d/mysql-grants-update ] && rm /etc/logrotate.d/mysql-grants-update

case $(hostname) in
    ppc*)
        /bin/ln -s /etc/mysql-grants.d/mysql-grants.direct.conf /etc/mysql-grants.conf
    ;;
    bm*|catalogia*)
        /bin/ln -s /etc/mysql-grants.d/mysql-grants.bm.conf /etc/mysql-grants.conf
        /bin/ln -s /etc/mysql-grants.d/mysql-grants.bm.cron /etc/cron.d/mysql-grants-update
        /bin/ln -s /etc/mysql-grants.d/mysql-grants.bm.logrotate /etc/logrotate.d/mysql-grants-update
    ;;
    *)
        echo "Dont find mysql-grants.<project>.conf"
    ;;
esac

exit 0
