File: mysql-server-8.0.postrm

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (119 lines) | stat: -rwxr-xr-x 3,202 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash

set -e

# It is possible that Debconf has already been removed, too.
if [ -f /usr/share/debconf/confmodule ]; then
  . /usr/share/debconf/confmodule
fi

if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }

mysql_cfgdir=/etc/mysql
DATADIR=/var/lib/mysql
MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"

MYSQL_UPGRADE_INFO_FILE="$DATADIR/mysql_upgrade_info"
MARIADB_UPGRADE_INFO_FILE="$DATADIR/mariadb_upgrade_info"

# To avoid having hardcoded paths in the script, we do a search on the path, as suggested at:
# https://www.debian.org/doc/manuals/developers-reference/ch06.en.html#bpp-debian-maint-scripts
pathfind() {
  OLDIFS="$IFS"
  IFS=:
  for p in $PATH; do
    if [ -x "$p/$*" ]; then
      IFS="$OLDIFS"
      return 0
    fi
  done
  IFS="$OLDIFS"
  return 1
}

# Try to stop the server in a sane way. If it does not success let the admin
# do it himself. No database directories should be removed while the server
# is running!
stop_server() {
  set +e
  if pathfind invoke-rc.d; then
    invoke-rc.d mysql stop
  else
    /etc/init.d/mysql stop
  fi
  errno=$?
  set -e

  if [ "$?" != 0 ]; then
    echo "Trying to stop the MySQL server resulted in exitcode $?." 1>&2
    echo "Stop it yourself and try again!" 1>&2
    exit 1
  fi
}

case "$1" in
  purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
    if [ -n "`$MYADMIN ping 2>/dev/null`" ]; then
      stop_server
      sleep 2
    fi
  ;;
  *)
    echo "postrm called with unknown argument '$1'" 1>&2
    exit 1
  ;;
esac

# New packaging paradigm for my.cnf as of Dec-2014 for sharing mysql
# variants in Ubuntu.
case "$1" in
  remove|disappear)
    [ -x /usr/share/mysql-common/configure-symlinks ] && /usr/share/mysql-common/configure-symlinks remove mysql "$mysql_cfgdir/mysql.cnf"
  ;;
esac

# Check if MariaDB database now exists in data directory using upgrade info
found_version="8.0"
mariadb_exists=0

if [[ -f "$MYSQL_UPGRADE_INFO_FILE" ]]; then
  found_version=$(<"$MYSQL_UPGRADE_INFO_FILE")
fi

if [[ -f "$MARIADB_UPGRADE_INFO_FILE" ]]; then
   found_version=$(<"$MARIADB_UPGRADE_INFO_FILE")
fi

if [[ "$found_version" == *"MariaDB"* ]]; then
  mariadb_exists=1
fi

# MariaDB found - notify user
if [ "$mariadb_exists" = 1 ]; then
  echo "Found an instance of MariaDB $found_version, files will not be removed automatically." 1>&2
fi

# - When purging, ask if data files should also be removed   
if [ "$1" = "purge" ] && [ "$mariadb_exists" = 0 ]; then
  # we remove the mysql user only after all his owned files are purged
  rm -f /var/log/mysql.{log,err}{,.0,.[1234567].gz}
  rm -rf /var/log/mysql

  db_input high mysql-server-5.7/postrm_remove_databases || true
  db_go || true
  db_get mysql-server-5.7/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!
    rm -f /etc/mysql/debian.cnf
    rm -rf /var/lib/mysql
    rm -rf /var/lib/mysql-files
    rm -rf /var/lib/mysql-keyring
    userdel mysql || true
  fi
fi

#DEBHELPER#

exit 0