Hi anyone looking at this patch!

I have tried to write a similar patch to apply to the current
mysql-5.7 server branch, and discovered a showstopping bug in the code
I wrote: it fails if it's a clean install!  The fix (now applied to
the github branch) is to change the new line in the
mysql-server-5.7.postinst patch from

olds=$(ls ... 2>/dev/null)

to

olds=$(ls ... 2>/dev/null || true)

so that it doesn't fail if any of the file patterns listed are not
found.

Attached is a similar patch for mysql-server-5.7, now tested on my
machine, against the head of mysql-5.7/debian/master on
git://anonscm.debian.org/pkg-mysql/mysql.git - happy for someone else
to also test it, and apply it if it they're happy with it.  (I also
removed the new but unnecessary "pathfind" function as invoke-rc.d is
in an essential package.)  The logic is exactly the same as the patch
for mariadb-10.1.

Best wishes,

   Julian
































diff --git a/debian/mysql-server-5.7.lintian-overrides b/debian/mysql-server-5.7.lintian-overrides
index 18e5d5e1..36927084 100644
--- a/debian/mysql-server-5.7.lintian-overrides
+++ b/debian/mysql-server-5.7.lintian-overrides
@@ -1,3 +1,5 @@
 # These long lines reproduce actual output and to reformat them
 # would damage the integrity of the man page.
 manpage-has-errors-from-man usr/share/man/man1/mysqlbinlog.1.gz 1979: warning [p 13, 2.7i, div `3tbd3,2', 0.8i]: can't break line
+# the second update-rc.d is informational only: see postrm for details
+mysql-server-5.7: duplicate-updaterc.d-calls-in-postrm mysql
diff --git a/debian/mysql-server-5.7.postinst b/debian/mysql-server-5.7.postinst
index 54adbd09..868be838 100755
--- a/debian/mysql-server-5.7.postinst
+++ b/debian/mysql-server-5.7.postinst
@@ -22,27 +22,8 @@ run_init_sql() {
   return $result
 }
 
-# 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
-}
-
 invoke() {
-  if pathfind invoke-rc.d; then
-    invoke-rc.d mysql $1
-  else
-    /etc/init.d/mysql $1
-  fi
+  invoke-rc.d mysql $1
 }
 
 # Check if server is able to start. If it fails we abort early and refer
@@ -315,6 +296,22 @@ if [ "$1" = "configure" ]; then
       invoke start
     fi
   fi
+
+  # Fix broken postrms in mysql-server-5.[1-6] and mariadb-server-10.[01]
+  # packages to prevent purging these packages from breaking our package.
+  # (See #852495)  It is unlikely that a user would have mariadb-server
+  # postrm files lying around, but we aim to be safe.
+
+  # We comment out all of the commands which assume that there is no other
+  # mysql server installed.
+  # (Because of the Conflicts in the control file for this package, they can
+  # only possibly be in a configuration-only state at this point.  And this
+  # cannot harm even if the system is in a very broken state and we are being
+  # configured in spite of those packages being in a different state.)
+  olds=$(ls /var/lib/dpkg/info/mysql-server-5.[1-6].postrm /var/lib/dpkg/info/mariadb-server-10.[01].postrm 2>/dev/null || true)
+  if [ -n "$olds" ]; then
+      perl -i -pe 's/stop_server(?=\s|$)/# stop_server/; s/^(\s*)((?:update|invoke)-rc\.d.*$)/$1# $2\n$1true/; s/^(\s*)(deb-systemd-helper.*$)/$1# $2\n$1true/; s%rm -f "/etc/apparmor.d%# rm -f "/etc/apparmor.d%' $olds
+  fi
 fi
 
 # forget we ever saw the password.  don't use reset to keep the seen status
diff --git a/debian/mysql-server-5.7.postrm b/debian/mysql-server-5.7.postrm
index 49d45f1b..171ea338 100755
--- a/debian/mysql-server-5.7.postrm
+++ b/debian/mysql-server-5.7.postrm
@@ -11,49 +11,11 @@ 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
-MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
-
-# 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
+    # We handle purge actions below.  The server has already been stopped
+    # if necessary by the prerm.
   ;;
   *)
     echo "postrm called with unknown argument '$1'" 1>&2
@@ -91,6 +53,60 @@ if [ "$1" = "purge" ]; then
   fi
 fi
 
-#DEBHELPER#
+# We manually add the debhelper snippets here to ensure that when purging,
+# only safe-to-run snippets are run if another mysql-server or mariadb-server
+# package is installed.
+
+# Automatically added by dh_installinit
+# modified to protect against another mysql server package being installed
+if [ "$1" = "purge" -a ! \( -x /usr/sbin/mysqld -o -L /usr/sbin/mysqld \) ]; then
+	update-rc.d mysql remove >/dev/null
+fi
+
+
+# In case this system is running systemd, we make systemd reload the unit files
+# to pick up changes.
+if [ -d /run/systemd/system ] ; then
+	systemctl --system daemon-reload >/dev/null || true
+fi
+# End automatically added section
+# Automatically added by dh_systemd_enable
+if [ "$1" = "remove" ]; then
+	if [ -x "/usr/bin/deb-systemd-helper" ]; then
+		deb-systemd-helper mask mysql.service >/dev/null
+	fi
+fi
+
+# modified to protect against another mysql server package being installed
+if [ "$1" = "purge" -a ! \( -x /usr/sbin/mysqld -o -L /usr/sbin/mysqld \) ]; then
+	if [ -x "/usr/bin/deb-systemd-helper" ]; then
+		deb-systemd-helper purge mysql.service >/dev/null
+		deb-systemd-helper unmask mysql.service >/dev/null
+	fi
+fi
+# End automatically added section
+# Automatically added by dh_installdebconf
+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
+# modified to protect against another mysql server package being installed
+if [ "$1" = "purge" -a ! \( -x /usr/sbin/mysqld -o -L /usr/sbin/mysqld \) ] && ! [ -e "/etc/apparmor.d/usr.sbin.mysqld" ] ; then
+    rm -f "/etc/apparmor.d/disable/usr.sbin.mysqld" || true
+    rm -f "/etc/apparmor.d/force-complain/usr.sbin.mysqld" || true
+    rm -f "/etc/apparmor.d/local/usr.sbin.mysqld" || 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
 
 exit 0
+
+# We add the debhelper snippets here, after the exit 0, so that they can
+# be visually checked in the future to ensure that nothing has been left
+# out above.
+
+#DEBHELPER#
diff --git a/debian/mysql-server-5.7.preinst b/debian/mysql-server-5.7.preinst
index 4ac328cc..143cf61d 100755
--- a/debian/mysql-server-5.7.preinst
+++ b/debian/mysql-server-5.7.preinst
@@ -20,21 +20,6 @@ DATADIR=/var/lib/mysql
 LOGDIR=/var/log/mysql
 UPGRADEDIR=/var/lib/mysql-upgrade
 
-# 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! Another mysqld in e.g. a different chroot is fine for us.
@@ -42,12 +27,7 @@ stop_server() {
     if [ ! -x /etc/init.d/mysql ]; then return; fi
 
     set +e
-    if pathfind invoke-rc.d; then
-      cmd="invoke-rc.d mysql stop"
-    else
-      cmd="/etc/init.d/mysql stop"
-    fi
-    $cmd
+    invoke-rc.d mysql stop
     errno=$?
     set -e
    

Reply via email to