#!/bin/bash set -e # shellcheck source=/dev/null . /usr/share/debconf/confmodule if [ -n "$DEBIAN_SCRIPT_DEBUG" ] then set -v -x DEBIAN_SCRIPT_TRACE=1 fi ${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 } mariadb_datadir=/var/lib/mariadb legacy_mariadb_datadir=/var/lib/mysql # Check if the version file mariadb_upgrade_info or mysql_upgrade_info is # included with the provided data directory. If it is a MariaDB version, then # return the major version number only (XX.XX). Return empty if this directory # does not belong to MariaDB. get_mariadb_upgrade_info_major_version() { datadir="$1" # Check both mariadb_upgrade_info (higher priority) and mysql_upgrade_info. if [ -f "$datadir/mysql_upgrade_info" ] then read -r full_version < "$datadir/mysql_upgrade_info" fi if [ -f "$datadir/mariadb_upgrade_info" ] then read -r full_version < "$datadir/mariadb_upgrade_info" fi # If version is not empty and contains 'MariaDB', get the version number. if [ -n "$full_version" ] && echo "$full_version" | grep -q "MariaDB" then # The major version number should the first two components of the version # string (e.g. 11.8 from 11.8.6). echo "$full_version" | awk -F'.' '{print $1"."$2}' fi } # # - Purge logs and data only if they are ours (#307473) # - Remove the mysql user only after all his owned files are purged. # - Cleanup the initscripts only if this was the last provider of them # if [ "$1" = "purge" ] then rm -f /etc/mysql/mariadb.conf.d/99-legacy-datadir.cnf # Mark data directories for removal if they match the current MariaDB version. remove_mariadb_datadir="false" remove_legacy_mariadb_datadir="false" mariadb_datadir_version=$(get_mariadb_upgrade_info_major_version "$mariadb_datadir") if [ "$mariadb_datadir_version" = "11.8" ] then remove_mariadb_datadir="true" fi legacy_mariadb_datadir_version=$(get_mariadb_upgrade_info_major_version "$legacy_mariadb_datadir") if [ "$legacy_mariadb_datadir_version" = "11.8" ] then remove_legacy_mariadb_datadir="true" fi # Remove logs in /var/log/mysql only if they are ours. # These must be removed before mysql user is removed. if [ "$remove_mariadb_datadir" = "true" ] || [ "$remove_legacy_mariadb_datadir" = "true" ] then rm -f /var/log/mysql.{log,err}{,.0,.[1234567].gz} rm -rf /var/log/mysql fi db_input high "mariadb-server/postrm_remove_databases" || true db_go || true db_get "mariadb-server/postrm_remove_databases" || true if [ "$RET" = "true" ] then # never remove the debian.cnf when the databases are still existing # else we ran into big trouble on the next install! if [ "$remove_mariadb_datadir" = "true" ] || [ "$remove_legacy_mariadb_datadir" = "true" ] then rm -f /etc/mysql/debian.cnf fi # Remove all contents from /var/lib/mariadb except if it's a # directory with file system data. See #829491 for details and # #608938 for potential mysql-server leftovers which erroneously # had been renamed. # Attempt removal only if the directory hasn't already been removed # by dpkg to avoid failing on "No such file or directory" errors. if [ "$remove_mariadb_datadir" = "true" ] then find "$mariadb_datadir" -mindepth 1 \ -not -path '*/lost+found/*' -not -name 'lost+found' \ -not -path '*/lost@002bfound/*' -not -name 'lost@002bfound' \ -delete # "|| true" still needed as rmdir still exits with non-zero if # /var/lib/mariadb is a mount point rmdir --ignore-fail-on-non-empty "$mariadb_datadir" || true fi # Remove all contents from /var/lib/mysql if it's owned by us, with same # checks as /var/lib/mariadb. if [ "$remove_legacy_mariadb_datadir" = "true" ] then find "$legacy_mariadb_datadir" -mindepth 1 \ -not -path '*/lost+found/*' -not -name 'lost+found' \ -not -path '*/lost@002bfound/*' -not -name 'lost@002bfound' \ -delete # "|| true" still needed as rmdir still exits with non-zero if # /var/lib/mysql is a mount point rmdir --ignore-fail-on-non-empty "$legacy_mariadb_datadir" || true fi # Remove /run/mysqld and mysql user if owned by us. if [ "$remove_mariadb_datadir" = "true" ] || [ "$remove_legacy_mariadb_datadir" = "true" ] then rm -rf /run/mysqld # this directory is created by the init script, don't leave behind userdel mysql || true fi fi fi # Automatically added by dh_installinit/13.31 if [ "$1" = "remove" ] && [ -x "/etc/init.d/mariadb" ] ; then chmod -x "/etc/init.d/mariadb" >/dev/null || true fi if [ -z "$DPKG_ROOT" ] && [ "$1" = "purge" ] ; then update-rc.d mariadb remove >/dev/null fi # End automatically added section # Automatically added by dh_installsystemd/13.31 if [ "$1" = remove ] && [ -d /run/systemd/system ] ; then systemctl --system daemon-reload >/dev/null || true fi # End automatically added section # Automatically added by dh_installsystemd/13.31 if [ "$1" = "purge" ]; then if [ -x "/usr/bin/deb-systemd-helper" ]; then deb-systemd-helper purge 'mariadb.service' >/dev/null || true fi fi # End automatically added section # Automatically added by dh_installdebconf/13.31 if [ "$1" = purge ] && [ -e /usr/share/debconf/confmodule ]; then . /usr/share/debconf/confmodule db_purge fi # End automatically added section # Automatically added by dh_apparmor/4.1.7-1 if [ "$1" = "purge" ] && ! [ -e "/etc/apparmor.d/mariadbd" ] ; then rm -f "/etc/apparmor.d/disable/mariadbd" || true rm -f "/etc/apparmor.d/force-complain/mariadbd" || true rm -f "/etc/apparmor.d/local/mariadbd" || true rm -f /var/cache/apparmor/*/"mariadbd" || true rmdir /etc/apparmor.d/disable 2>/dev/null || true rmdir /etc/apparmor.d/local 2>/dev/null || true rmdir /etc/apparmor.d 2>/dev/null || true fi # End automatically added section