File: /var/lib/dpkg/info/ispmanager-pkg-mysql.postinst
#!/bin/bash
# postinst script for coremanager
#
# see: dh_installdeb(1)
#set -e
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
COREDIR=/usr/local/mgr5
. ${COREDIR}/lib/pkgsh/ispmgr_pkg_funcs.sh
case "$1" in
configure)
if [ "${MYSQL_SERVICE}" = "mariadb" ]; then
MYCNF=/etc/mysql/mariadb.conf.d/50-server.cnf
else
MYCNF=/etc/mysql/mysql.conf.d/mysqld.cnf
fi
# Limit NOFILE
if [ -f /etc/systemd/system/mysql.service.d ]; then
SERVICE_CONF_DIR=/etc/systemd/system/mysql.service.d
else
SERVICE_CONF_DIR=/etc/systemd/system/mariadb.service.d
fi
if [ -d /etc/systemd/system/ ] && [ -n "$(which systemctl 2>/dev/null)" ]; then
if [ ! -f ${SERVICE_CONF_DIR}/nofile.conf ] && [ ! -f ${SERVICE_CONF_DIR}/limits.conf ]; then
mkdir -p ${SERVICE_CONF_DIR}
echo -e "[Service]\nLimitNOFILE=16384" > ${SERVICE_CONF_DIR}/nofile.conf
systemctl daemon-reload
mysql_restart=yes
fi
fi
if [ -z ${2} ]; then
if [ "#${ISPCONVERT}" = "#yes" ]; then
:
else
if [ "#${MIGRATION}" != "#mgr5" ]; then
SCOUNT=0
while ! test -f ${COREDIR}/etc/${ISPMGR}.db ; do
SCOUNT=$(expr ${SCOUNT} + 1)
${MGRCTL} -m ${ISPMGR} whoami >/dev/null 2>/dev/null ||:
sleep 1
if [ ${SCOUNT} -gt 5 ]; then
break
fi
done
if ! cat ${MYCNF} | sed -n -r '/\[mysqld\]/,/\[/p' | grep -q character-set-server ; then
sed -i -r '/^\[mysqld\]/a character-set-server = utf8' ${MYCNF}
mysql_restart=yes
fi
if ! cat ${MYCNF} | sed -n -r '/\[mysqld\]/,/\[/p' | grep -q collation-server ; then
sed -i -r '/^\[mysqld\]/a collation-server = utf8_general_ci' ${MYCNF}
mysql_restart=yes
fi
if [ -n "${mysql_restart}" ] && [ -n "${MYSQL_SERVICE}" ]; then
Service ${MYSQL_SERVICE} restart
fi
if $ISPMGRCTL db.server | grep -q name=MySQL ; then
# DB exists
PASSWD=$(${COREDIR}/etc/scripts/mysql_passwd)
export MGRCTL_MYSQL_PASSWORD=${PASSWD}
${ISPMGRCTL} db.server.edit elid=MySQL -e 'password=$MGRCTL_MYSQL_PASSWORD' sok=ok
else
PASSWD=$(${COREDIR}/etc/scripts/mysql_passwd)
export MGRCTL_MYSQL_PASSWORD=${PASSWD}
if [ "${ISPMGR}" = "ispmgrnode" ]; then
MYSQLVER=$(/usr/sbin/mysqld -V 2>/dev/null|awk '{print $3}')
${ISPMGRCTL} db.server.edit name=MySQL username=root host=localhost type=mysql -e 'password=$MGRCTL_MYSQL_PASSWORD' savedver=${MYSQLVER} sok=ok >/dev/null
else
MAX_ATTEMPTS=5
attempt=1
while [ $attempt -le $MAX_ATTEMPTS ]; do
${ISPMGRCTL} db.server.edit name=MySQL username=root host=localhost type=mysql -e 'password=$MGRCTL_MYSQL_PASSWORD' sok=ok >/dev/null
if ${ISPMGRCTL} db.server | grep -q name=MySQL ; then
break
else
if [ $attempt -lt $MAX_ATTEMPTS ]; then
echo "The server wasn't added. Try again."
sleep 1
fi
fi
attempt=$((attempt + 1))
done
fi
fi
fi
fi
fi
# Checking if this mariadb > 5.5.31
if [ ! -f ${COREDIR}/etc/.mariadb_length_check ]; then
m_version=$(echo "SELECT VERSION()" | mysql -s 2>/dev/null)
if [ -n "${m_version}" ]; then
if echo ${m_version} | grep -qi mariadb && version_ge "${m_version}" "5.5.31" ; then
# This is mariadb and version greater than 5.5.31. We can increase username length
mysql -s < ${COREDIR}/etc/scripts/mariadb_username_length_alter.sql 2>/dev/null || alter_fail=yes
fi
test -z "${alter_fail}" && touch ${COREDIR}/etc/.mariadb_length_check
else
echo "Can not detect mysql version"
fi
fi
if grep -q "user\s*\=\s*root" /etc/mysql/debian.cnf ; then
ROOTPW=$(cat /root/.my.cnf | awk -F= '$1 ~ "^password" {print $2}' | sed 's/ //g')
sed -i -r "s/^(password\s*=\s*)$/\1${ROOTPW}/" /etc/mysql/debian.cnf
fi
AddPath mysql_restart "systemctl restart ${MYSQL_SERVICE}" mysql
AddPath mysqld.ini ${MYCNF} mysql
AddPath mysqld /usr/sbin/mysqld mysql
## Reloading Manager
ReloadMgr ${ISPMGR}
if [ -z ${2} ]; then
if [ "#${ISPCONVERT}" = "#yes" ]; then
:
else
ServiceAddmon mysql
# Afterinstall
AfterinstallModule ${ISPMGR} mysql
fi
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
exit 0