From c932eac93e3022588e41b15c5416694443eceffc Mon Sep 17 00:00:00 2001 From: Aron Xu Date: Wed, 28 Sep 2016 02:47:26 +0800 Subject: [PATCH] Handle the case /etc/hostid is being wrongly marked as conffile There are packages distributed with /etc/hostid file installed as conffile, which is going to cause problem when the package is purged. Here we detect such case and migrate it to an ordinary file that preserves during purge. Also replace the endianness detection code to use od(1) from coreutils instead of requiring gcc --- debian/spl.postinst | 8 +++++++- debian/spl.postrm | 10 ++++++++++ debian/spl.preinst | 10 ++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 debian/spl.postrm create mode 100644 debian/spl.preinst diff --git a/debian/spl.postinst b/debian/spl.postinst index 10683a4..a0bb353 100644 --- a/debian/spl.postinst +++ b/debian/spl.postinst @@ -21,6 +21,12 @@ set -e # If this file don't already exists on our system or has less than 4 bytes, then # we will stabilize our current hostid by writing its value to /etc/hostid +# Detect if /etc/hostid is a conffile of previous spl package, migrate if yes +# hostid file should preserve even when package is purged +if $(dpkg-query --showformat='${Conffiles}\n' --show spl >/dev/null 2>&1); then + dpkg-maintscript-helper rm_conffile /etc/hostid -- "$@" +fi + if [ ! -f /etc/hostid ] || [ $(stat -c %s /etc/hostid) -lt 4 ] ; then # Write our current hostid to /etc/hostid @@ -31,7 +37,7 @@ if [ ! -f /etc/hostid ] || [ $(stat -c %s /etc/hostid) -lt 4 ] ; then DD=$(echo $HOSTID | cut -b 7,8) # Big Endian - if echo | gcc -E -dM - | grep -q "__BYTE_ORDER__.*__ORDER_BIG_ENDIAN__"; then + if [ $(echo -n I | od -to2 | awk 'FNR==1{ print substr($2,6,1)}' 2>/dev/null) = 0 ]; then # Invoke the printf from coreutils. shell builtin lacks the byte format. /usr/bin/printf "\x$AA\x$BB\x$CC\x$DD" >/etc/hostid else diff --git a/debian/spl.postrm b/debian/spl.postrm new file mode 100644 index 0000000..2b6dc7b --- /dev/null +++ b/debian/spl.postrm @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +# Detect if /etc/hostid is a conffile of previous spl package, migrate if yes +# hostid file should preserve even when package is purged +if $(dpkg-query --showformat='${Conffiles}\n' --show spl >/dev/null 2>&1); then + dpkg-maintscript-helper rm_conffile /etc/hostid -- "$@" +fi + +#DEBHELPER# diff --git a/debian/spl.preinst b/debian/spl.preinst new file mode 100644 index 0000000..2b6dc7b --- /dev/null +++ b/debian/spl.preinst @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +# Detect if /etc/hostid is a conffile of previous spl package, migrate if yes +# hostid file should preserve even when package is purged +if $(dpkg-query --showformat='${Conffiles}\n' --show spl >/dev/null 2>&1); then + dpkg-maintscript-helper rm_conffile /etc/hostid -- "$@" +fi + +#DEBHELPER#