#!/bin/bash set -e MYSQL_PKG="$(dpkg --list | sed -ne 's/^ii \(mariadb-server-[[:digit:].]\+\) .*$/\1/p')" . /usr/share/yunohost/helpers do_pre_regen() { pending_dir=$1 cd /usr/share/yunohost/templates/mysql install -D -m 644 my.cnf "${pending_dir}/etc/mysql/my.cnf" } do_post_regen() { regen_conf_files=$1 if [[ ! -d /var/lib/mysql/mysql ]] then # dpkg-reconfigure will initialize mysql (if it ain't already) # It enabled auth_socket for root, so no need to define any root password... # c.f. : cat /var/lib/dpkg/info/mariadb-server-10.3.postinst | grep install_db -C3 dpkg-reconfigure -freadline -u "$MYSQL_PKG" 2>&1 systemctl -q is-active mariadb.service \ || systemctl start mariadb sleep 5 echo "" | mysql && echo "Can't connect to mysql using unix_socket auth ... something went wrong during initial configuration of mysql !?" fi if [ ! -e /etc/yunohost/mysql ] then # Dummy password that's not actually used nor meaningful ... # (because mysql is supposed to be configured to use unix_socket on new setups) # but keeping it for legacy # until we merge https://github.com/YunoHost/yunohost/pull/912 ... ynh_string_random 10 > /etc/yunohost/mysql chmod 400 /etc/yunohost/mysql fi # mysql is supposed to be an alias to mariadb... but in some weird case is not # c.f. https://forum.yunohost.org/t/mysql-ne-fonctionne-pas/11661 # Playing with enable/disable allows to recreate the proper symlinks. if [ ! -e /etc/systemd/system/mysql.service ] then systemctl stop mysql -q systemctl disable mysql -q systemctl disable mariadb -q systemctl enable mariadb -q systemctl is-active mariadb -q || systemctl start mariadb fi [[ -z "$regen_conf_files" ]] \ || service mysql restart } FORCE=${2:-0} DRY_RUN=${3:-0} case "$1" in pre) do_pre_regen $4 ;; post) do_post_regen $4 ;; *) echo "hook called with unknown argument \`$1'" >&2 exit 1 ;; esac exit 0