[X2Go-Commits] [x2goserver] 02/02: debian/: add x2goserver-xsession.{preinst, post{inst, rm}} scriptlets to handle Xsession.d breakage cleanup correctly.

git-admin at x2go.org git-admin at x2go.org
Tue Jul 31 11:57:37 CEST 2018


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository x2goserver.

commit 2990ea342e21633317f4bdf2197e390905e44e8a
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Tue Jul 31 11:55:54 2018 +0200

    debian/: add x2goserver-xsession.{preinst,post{inst,rm}} scriptlets to handle Xsession.d breakage cleanup correctly.
    
    Note that we can rely on dpkg-maintscript-helper's dir_to_symlink
    support only if the version is high enough, which is not the case on
    older Debian and Ubuntu platforms.
    
    While on Debian, that's only Wheezy and lower and we don't care about
    these versions anyway, Ubuntu Trusty/14.04 is sadly still supported and
    needs to be provided a proper workaround for now.
---
 debian/changelog                    |   8 +++
 debian/x2goserver-xsession.postinst |  78 ++++++++++++++++++++++
 debian/x2goserver-xsession.postrm   |  76 +++++++++++++++++++++
 debian/x2goserver-xsession.preinst  | 130 ++++++++++++++++++++++++++++++++++++
 4 files changed, 292 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index d95d1a8..f91216c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -16,6 +16,14 @@ x2goserver (4.1.0.2-0x2go1) UNRELEASED; urgency=medium
       correctly.
     + Add Pre-Depends on specific minimum dpkg version to x2goserver-xsession,
       needed for ${DPKG_RUNNING_VERSION} support.
+  * debian/:
+    + Add x2goserver-xsession.{preinst,post{inst,rm}} scriptlets to handle
+      Xsession.d breakage cleanup correctly. Note that we can rely on
+      dpkg-maintscript-helper's dir_to_symlink support only if the version is
+      high enough, which is not the case on older Debian and Ubuntu platforms.
+      While on Debian, that's only Wheezy and lower and we don't care about
+      these versions anyway, Ubuntu Trusty/14.04 is sadly still supported and
+      needs to be provided a proper workaround for now.
 
  -- X2Go Release Manager <git-admin at x2go.org>  Fri, 27 Jul 2018 07:06:39 +0200
 
diff --git a/debian/x2goserver-xsession.postinst b/debian/x2goserver-xsession.postinst
new file mode 100755
index 0000000..e1c6d0f
--- /dev/null
+++ b/debian/x2goserver-xsession.postinst
@@ -0,0 +1,78 @@
+#!/bin/sh
+# postinst script for x2goserver-xsession
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <postinst> `configure' <most-recently-configured-version>
+#        * <old-postinst> `abort-upgrade' <new version>
+#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+#          <new-version>
+#        * <postinst> `abort-remove'
+#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+#          <failed-install-package> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+if dpkg --compare-versions -- "${DPKG_RUNNING_VERSION}" ge '1.17.14'; then
+	dpkg-maintscript-helper 'dir_to_symlink' \
+	  '/etc/x2go/Xsession.d' '/etc/X11/Xsession.d' '4.1.0.2-0~' 'x2goserver-xsession' -- "${@}"
+else
+	finish_dir_to_symlink()
+	{
+		local PATHNAME="${1}"
+		local SYMLINK_TARGET="${2}"
+
+		# Move the contents of the staging directory to the symlink target,
+		# as those are all new files installed between this package being
+		# unpacked and configured.
+		local ABS_SYMLINK_TARGET
+		if [ "${SYMLINK_TARGET#/}" = "${SYMLINK_TARGET}" ]; then
+			ABS_SYMLINK_TARGET="$(dirname "${PATHNAME}")/${SYMLINK_TARGET}"
+		else
+			ABS_SYMLINK_TARGET="${SYMLINK_TARGET}"
+		fi
+		rm "${PATHNAME}/.dpkg-staging-dir"
+		find "${PATHNAME}" -mindepth 1 -print0 | \
+			xargs -0 -i% mv -f "%" "${ABS_SYMLINK_TARGET}/"
+
+		# Remove the staging directory.
+		rmdir "${PATHNAME}"
+
+		# Do the actual switch.
+		ln -s "${SYMLINK_TARGET}" "${PATHNAME}"
+
+		# We are left behind the old files owned by this package in the backup
+		# directory, just remove it.
+		rm -rf "${PATHNAME}.dpkg-backup"
+	}
+fi
+
+case "${1}" in
+	'configure')
+		if dpkg --compare-versions -- "${DPKG_RUNNING_VERSION}" lt '1.17.14'; then
+			PATHNAME='/etc/x2go/Xsession.d'
+			SYMLINK_TARGET='/etc/X11/Xsession.d'
+			[ -d "${PATHNAME}.dpkg-backup" ] &&
+			[ ! -h "${PATHNAME}" ] && [ -d "${PATHNAME}" ] &&
+			[ -f "${PATHNAME}/.dpkg-staging-dir" ]; then
+				finish_dir_to_symlink "${PATHNAME}" "${SYMLINK_TARGET}"
+		fi
+		;;
+	'abort-upgrade'|'abort-remove'|'abort-deconfigure')
+		;;
+	*)
+		echo "${0} called with unknown argument '${1}'" >&2
+		exit '1'
+		;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit '0'
diff --git a/debian/x2goserver-xsession.postrm b/debian/x2goserver-xsession.postrm
new file mode 100755
index 0000000..b827a91
--- /dev/null
+++ b/debian/x2goserver-xsession.postrm
@@ -0,0 +1,76 @@
+#!/bin/sh
+# postrm script for x2goserver-xsession
+
+set -e
+
+# summary of how this script can be called:
+#        * <postrm> `remove'
+#        * <postrm> `purge'
+#        * <old-postrm> `upgrade' <new-version>
+#        * <new-postrm> `failed-upgrade' <old-version>
+#        * <new-postrm> `abort-install'
+#        * <new-postrm> `abort-install' <old-version>
+#        * <new-postrm> `abort-upgrade' <old-version>
+#        * <disappearer's-postrm> `disappear' <overwriter>
+#          <overwriter-version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+set -e
+
+if dpkg --compare-versions -- "${DPKG_RUNNING_VERSION}" ge '1.17.14'; then
+	dpkg-maintscript-helper 'dir_to_symlink' \
+	  '/etc/x2go/Xsession.d' '/etc/X11/Xsession.d' '4.1.0.2-0~' 'x2goserver-xsession' -- "${@}"
+else
+	abort_dir_to_symlink()
+	{
+		local PATHNAME="${1}"
+
+		echo "Restoring backup of ${PATHNAME} ..."
+		if [ -h "${PATHNAME}" ]; then
+			rm -f "${PATHNAME}"
+		else
+			# The staging directory must be empty, as no other package
+			# should have been unpacked in between.
+			rm -f "${PATHNAME}/.dpkg-staging-dir"
+			rmdir "${PATHNAME}"
+		fi
+
+		mv "${PATHNAME}.dpkg-backup" "${PATHNAME}"
+	}
+fi
+
+PATHNAME='/etc/x2go/Xsession.d'
+SYMLINK_TARGET='/etc/X11/Xsession.d'
+case "${1}" in
+	'purge')
+		if dpkg --compare-versions -- "${DPKG_RUNNING_VERSION}" lt '1.17.14'; then
+			[ -d "${PATHNAME}.dpkg-backup" ] && rm -rf "${PATHNAME}.dpkg-backup"
+		fi
+		;;
+	'abort-install'|'abort-upgrade')
+		if dpkg --compare-versions -- "${DPKG_RUNNING_VERSION}" lt '1.17.14'; then
+			[ -n "${2}" ] &&
+			[ -d "${PATHNAME}.dpkg-backup" ] &&
+			[ \( ! -h "${PATHNAME}" -a -d "${PATHNAME}" -a \
+			     -f "${PATHNAME}/.dpkg-staging-dir" \) -o \
+			  \( -h "${PATHNAME}" -a \
+			     \( "$(readlink "${PATHNAME}")" = "${SYMLINK_TARGET}" -o \
+			        "$(readlink -f "${PATHNAME}")" = "${SYMLINK_TARGET}" \) \) ] &&
+			dpkg --compare-versions -- "${2}" le-nl '4.1.0.2-0~' &&
+				abort_dir_to_symlink "${PATHNAME}"
+		fi
+	'remove'|'upgrade'|'failed-upgrade'|'disappear')
+		;;
+	*)
+		echo "${0} called with unknown argument '${1}'" >&2
+		exit '1'
+		;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit '0'
diff --git a/debian/x2goserver-xsession.preinst b/debian/x2goserver-xsession.preinst
new file mode 100755
index 0000000..e4e5198
--- /dev/null
+++ b/debian/x2goserver-xsession.preinst
@@ -0,0 +1,130 @@
+#!/bin/sh
+# preinst script for x2goserver-xsession
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <postinst> `configure' <most-recently-configured-version>
+#        * <old-postinst> `abort-upgrade' <new version>
+#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+#          <new-version>
+#        * <postinst> `abort-remove'
+#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+#          <failed-install-package> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+if dpkg --compare-versions -- "${DPKG_RUNNING_VERSION}" ge '1.17.14'; then
+	dpkg-maintscript-helper 'dir_to_symlink' \
+	  '/etc/x2go/Xsession.d' '/etc/X11/Xsession.d' '4.1.0.2-0~' 'x2goserver-xsession' -- "${@}"
+else
+	error() {
+		echo "${PROGNAME}: error: ${*}" >&2
+		exit '1'
+	}
+
+	ensure_package_owns_file() {
+		local PACKAGE="${1}"
+		local FILE="${2}"
+
+		if ! dpkg-query -L "${PACKAGE}" | grep -F -q -x "${FILE}"; then
+			return '1'
+		fi
+		return '0'
+	}
+
+	internal_pkg_must_own_file()
+	{
+		local PACKAGE="${1}"
+		local FILE="${2}"
+
+		if ! ensure_package_owns_file "${PACKAGE}" "${FILE}"; then
+			error "file '${FILE}' not owned by package '${PACKAGE}'"
+		fi
+
+		return '0'
+	}
+
+	prepare_dir_to_symlink()
+	{
+		local PACKAGE="${1}"
+		local PATHNAME="${2}"
+
+		local LINE
+		# If there are conffiles we should not perform the switch.
+		dpkg-query -W -f='${Conffiles}\n' "${PACKAGE}" | while read -r LINE; do
+			case "${LINE}" in
+			"${PATHNAME}"/*)
+				error "directory '${PATHNAME}' contains conffiles," \
+				      "cannot switch to symlink"
+				;;
+			esac
+		done
+
+		# If there are locally created files or files owned by another package
+		# we should not perform the switch.
+		find "${PATHNAME}" -print0 | \
+			xargs -0 -n1 ${0} _internal_pkg_must_own_file "${PACKAGE}" || \
+			error "directory '${PATHNAME}' contains files not owned by" \
+			      "package ${PACKAGE}, cannot switch to symlink"
+
+		# At this point, we know that the directory either contains no files,
+		# or only non-conffiles owned by the package.
+		#
+		# To do the switch we cannot simply replace it with the final symlink
+		# just yet, because dpkg needs to remove any file present in the old
+		# package that have disappeared in the new one, and we do not want to
+		# lose files resolving to the same pathname in the symlink target.
+		#
+		# We cannot replace the directory with a staging symlink either,
+		# because dpkg will update symlinks to their new target.
+		#
+		# So we need to create a staging directory, to avoid removing files
+		# from other packages, and to trap any new files in the directory
+		# to move them to their correct place later on.
+		mv -f "${PATHNAME}" "${PATHNAME}.dpkg-backup"
+		mkdir "${PATHNAME}"
+
+		# Mark it as a staging directory, so that we can track things.
+		touch "${PATHNAME}/.dpkg-staging-dir"
+	}
+fi
+
+case "${1}" in
+	'_internal_pkg_must_own_file')
+		if dpkg --compare-versions -- "${DPKG_RUNNING_VERSION}" lt '1.17.14'; then
+			# This is an internal command, must not be used outside this program.
+			internal_pkg_must_own_file "${@}"
+		else
+			echo "${0} called with unknown argument '${1}'" >&2
+			exit '1'
+		fi
+		;;
+	'install'|'upgrade')
+		if dpkg --compare-versions -- "${DPKG_RUNNING_VERSION}" lt '1.17.14'; then
+			PACKAGE='x2goserver-xsession'
+			PATHNAME='/etc/x2go/Xsession.d'
+			[ -n "${2}" ] &&
+			[ ! -h "${PATHNAME}" ] && [ -d "${PATHNAME}" ] &&
+			if dpkg --compare-versions -- "${2}" le-nl '4.1.0.2-0~'; then
+				prepare_dir_to_symlink "${PACKAGE}" "${PATHNAME}"
+			fi
+		fi
+		;;
+	'abort-upgrade')
+		;;
+	*)
+		echo "${0} called with unknown argument '${1}'" >&2
+		exit '1'
+		;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit '0'

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git


More information about the x2go-commits mailing list