#!/bin/bash

reconfigure_mysql() {
  if grep -q "^# configured by salpack" /etc/my.cnf; then
    echo "MySQL already configured."
    return
  fi
  if rpm -V mysql-libs >/dev/null; then
    mv /etc/my.cnf /etc/my.cnf.salpack
    cat > /etc/my.cnf << EOF
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# configured by salpack
character-set-server=utf8
innodb_file_per_table=1
max_connections=1024
max_allowed_packet=100M
#ft_min_word_len=3

# SSL
#ssl-ca=/etc/pki/mysql/cacert.pem
#ssl-cert=/etc/pki/mysql/server.crt
#ssl-key=/etc/pki/mysql/server.key

# mysqltuner optimalizations
#query_cache_size=32M
#thread_cache_size=20
#table_cache=32K
#innodb_buffer_pool_size=1G
#key_buffer_size=1G
#tmp_table_size=32M
#max_heap_table_size=16M
# options that significantly increase max. memory usage
#join_buffer_size=1M

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
EOF
  else
    echo "MySQL configuration already changed, skipping update."
    return
  fi
}

reconfigure_mysql
