[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: converting conffile to dpkg-conffile and keeping piuparts happy



Hi,

On Sun, Jun 01, 2025 at 10:20:31PM +0200, Marc Haber wrote:
How can I change my new dpkg-conffile and keep piuparts happy at the same time?

Here is the solution I found myself:

$ head -n-0 debian/ferm.p*
==> debian/ferm.postrm <==
#!/bin/sh
set -e

action=$1

if [ "${action}" = "purge" ]; then
    rm -f \
        /etc/default/ferm \
        /etc/default/ferm.bak
fi


#DEBHELPER#

==> debian/ferm.preinst <==
#!/bin/sh
set -e

action=$1
version=$2

DEFAULTSFILE="/etc/default/ferm"
BACKUPDEFAULTSFILE="${DEFAULTSFILE}.bak"
# sha256 hashes of $DEFAULTSFILE in ferm 2.5.1-4,
# with ENABLE="yes" and ENABLE="no"
DEFAULTSFILEHASHES="
64c84ccb16e984935c05dec6fa8d6b424b4f83735a9c53430a4ba34c5eb3074d
96affdfb381229de75cacb94412580df3938ad5f1e87ae1d004ab303630cd571
"

if [ "${action}" = "upgrade" ]; then
    # remove old cache files
    rm -f /var/cache/ferm/*.sh /var/cache/ferm/*.tmp

    # ferm 2.5.1-4 and earlier managed their defaultsfile in the
    # maintainer script. Move old defaultsfile away if unchanged
    if dpkg --compare-versions "${version}" le-nl "2.5.1-4"; then
        if [ -e "${DEFAULTSFILE}" ]; then
            CURRENT_HASH="$(sha256sum "${DEFAULTSFILE}" | cut -d ' ' -f 1)"
            if printf "%s\n" "${DEFAULTSFILEHASHES}" | grep --quiet --line-regexp --fixed-strings "${CURRENT_HASH}"; then
                if [ -e "${BACKUPDEFAULTSFILE}" ]; then
                    TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
                    mv "${BACKUPDEFAULTSFILE}" "${BACKUPDEFAULTSFILE}.${TIMESTAMP}"
                fi
                mv "${DEFAULTSFILE}" "${DEFAULTSFILE}.bak"
            fi
        fi
    fi
fi


#DEBHELPER#

The idea is to detect whether the maintainer-script-managed file was changed by the local admin, and if not, move away the file so that dpkg can place the new conffile at the same path without showing a conffile prompt. If the local admin changed the file, a dpkg-conffile prompt is desired at this place.

Greetings
Marc

--
-----------------------------------------------------------------------------
Marc Haber         | "I don't trust Computers. They | Mailadresse im Header
Leimen, Germany    |  lose things."    Winona Ryder | Fon: *49 6224 1600402
Nordisch by Nature |  How to make an American Quilt | Fax: *49 6224 1600421


Reply to: