eole-mariadb/preservice/25-bdd-init

47 lines
798 B
Plaintext
Raw Normal View History

2018-04-12 16:12:42 +02:00
#!/bin/bash
#
# Initialize root password
# and secure MariaDB installation
#
2018-05-09 15:41:04 +02:00
INITDONE="/etc/eole/.galera"
2018-05-09 14:25:25 +02:00
[[ "$(CreoleGet dbEnable)" == "non" ]] && exit 0
2018-05-09 15:41:04 +02:00
[[ -e ${INITDONE} ]] && exit 0
2018-05-09 14:25:25 +02:00
2018-04-12 17:10:39 +02:00
ROLE=$(CreoleGet dbClusterPosition 'Leader')
2018-04-12 16:12:42 +02:00
SECURE_CMD="mysql_secure_installation"
PASSWORD=$(pwgen -1 10)
2018-04-12 16:33:44 +02:00
passwd="/usr/share/eole/sbin/mariadbPwd"
2018-05-09 13:32:42 +02:00
logdir="/var/log/eole"
logfile="${logdir}/maria-init.log"
[[ ! -d "${logdir}" ]] && mkdir -p ${logdir}
2018-04-12 16:12:42 +02:00
2018-04-12 17:10:39 +02:00
if [[ ${ROLE} == "Leader" ]]
then
2018-05-09 17:07:19 +02:00
service mysql start
2018-04-12 17:10:39 +02:00
${passwd} ${PASSWORD}
2018-04-12 16:12:42 +02:00
2018-04-12 17:10:39 +02:00
# Run secure installation script
${SECURE_CMD} > ${logfile} 2>&1 <<__EOF__
2018-04-12 16:33:44 +02:00
${PASSWORD}
2018-04-12 16:12:42 +02:00
y
n
y
y
y
y
2018-04-12 16:33:44 +02:00
__EOF__
2018-05-09 17:07:19 +02:00
if [[ ${?} -eq 0 ]]
then
service mysql stop
touch ${INITDONE}
exit ${?}
else
service mysql stop
exit ${?}
fi
2018-04-12 17:10:39 +02:00
else
exit 0
fi