post_install(){
  groupadd -g 89 mysql &>/dev/null
  useradd -u 89 -g mysql -d /var/lib/mysql -s /bin/false mysql &>/dev/null

  echo ":: You need to initialize the MariaDB data directory prior to starting"
  echo "   the service. This can be done with mysql_install_db command, e.g.:"
  echo "   mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql"

  usr/bin/systemd-tmpfiles --create mysql.conf

  echo "The cluster needs to be configured before used, please read the
Getting Started Guide at
https://mariadb.com/kb/en/mariadb/documentation/replication/galera/getting-started-with-mariadb-galera-cluster/" \
| fmt -u
}

post_upgrade(){
  getent group mysql >/dev/null 2>&1 || groupadd -g 89 mysql &>/dev/null
  getent passwd mysql >/dev/null 2>&1 || useradd -u 89 -g mysql -d /var/lib/mysql \
    -s /bin/false mysql &>/dev/null

  if [[ "$(vercmp $2 5.5.25-4)" -lt 0 ]] && [[ -d /data ]]; then
    for x in data/*; do
      cp -r $x var/lib/mysql
    done
    rm -rf data
  fi

  if [[ "$(vercmp $2 5.5.25-5)" -lt 0 ]]; then
    echo ":: mysql.service has been renamed to mysqld.service to keep"
    echo "   consistency with MySQL package."
  fi

  if [[ "$(vercmp $2 10.0)" -lt 0 ]]; then
    echo ":: Major version update. Consider restarting mysqld.service and"
    echo "   running mysql_upgrade afterwards."
  fi
}
