#!/bin/bash

#####################################################################################################
# Instalando MariaDB / MySql:
#####################################################################################################
cd /tmp
# Instalando mysql sem pedir senha
export DEBIAN_FRONTEND=noninteractive
/usr/bin/apt-get install mysql-server default-libmysqlclient-dev -q -y

# Setando password do mysql - "mysqllt38c"
/usr/bin/mysqladmin -u root password "mysqllt38c"

# Liberar o acesso externo ao mysql
#	1) /etc/mysql/my.cnf - bind-address = 0.0.0.0
#	2) GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '[senha]' WITH GRANT OPTION;
#	3) FLUSH PRIVILEGES;

# Executando 1) no Mysql:
#/usr/bin/scp /etc/mysql/my.cnf /etc/mysql/my.bkp
#/bin/sed -e 's/= 127.0.0.1/= 0.0.0.0/' /etc/mysql/my.cnf > /tmp/my.new
#/usr/bin/scp /tmp/my.new /etc/mysql/my.cnf

# Executando 1) no MariaDB:
/usr/bin/scp /etc/mysql/my.cnf /etc/mysql/my.cnf.bkp
/bin/echo "[mysqld]" >> /etc/mysql/my.cnf
/bin/echo "bind-address = 0.0.0.0" >> /etc/mysql/my.cnf
/usr/sbin/service mysql restart

# Executando 2)
/usr/bin/mysql -u root -pmysqllt38c -Bse "GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'mysqllt38c' WITH GRANT OPTION;"

# Executando 3)
/usr/bin/mysql -u root -pmysqllt38c -Bse "FLUSH PRIVILEGES;"

#End