Package: ucf
Version: 3.0053
Severity: minor

Hi,

in ucf (3.0044) unstable, you did:
Remove unused ucf_helper_functions.sh and examples/ChangeLog.

Why were ucf_helper_functions.sh removed from ucf? This is intended to 
be used by ucf consumers such as aide (see #930130 when it was added). 
In fact, the aide package has been using the code for a decade now.

The code was submitted to ucf by me a decade ago after being implemented 
and tested inside aide. Since getting the code into the ucf package 
proper already took years, and I wanted to be able to backport aide, I 
kept aide using its own copy of the file.

When I was preparing aide to finally migrate to using the code from 
inside ucf, I was somewhat surprised to see it removed again two years 
ago.

Was it your intention to reduce ucf's usefulness, or you just not 
understand what this code does when you did your first upload of ucf? I 
am pretty sure that I submitted docs years ago, were they gone when you 
reviewed the code? Since the aide package uses this, I can confirm the 
code is not obsolete and is in perfect working order with ucf and could 
be used in other packages had it not been removed.

I am attaching a current version of ucf_helper_functions.sh that is more 
shellcheck compatible. Please consider adding the code again. It wil now 
be another three or four release until aide can actually make use of the 
file delivered with ucf_helper_functions.sh since at least trixie was 
unfortunately released without.

It you have any questions about the code, please don't hesitate to get 
in touch with me, the original author.

Greetings
Marc


-- System Information:
Debian Release: forky/sid
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 
'oldstable-security'), (500, 'unstable'), (500, 'testing'), (500, 'stable'), 
(500, 'oldstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 7.0.10+deb14-amd64 (SMP w/12 CPU threads; PREEMPT)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8), LANGUAGE=en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages ucf depends on:
ii  debconf [debconf-2.0]  1.5.92
ii  libtext-wrapi18n-perl  0.06-11
ii  procps                 2:4.0.4-9+b2
ii  sensible-utils         0.0.26

ucf recommends no packages.

ucf suggests no packages.

-- debconf information excluded
#!/bin/bash

UCF="ucf --three-way --debconf-ok"

# rename ucf-conffile. This was mostly stolen from cacti.postinst after
# a short discussion on debian-mentors, see
# http://lists.debian.org/debian-mentors/2013/07/msg00027.html
# and the following thread. Thanks to Paul Gevers
rename_ucf_file() {
    local oldname
    local newname

    # override UCF_FORCE_CONFFNEW with an empty local variable
    local UCF_FORCE_CONFFNEW

    oldname="$1"
    newname="$2"
    if [[ ! -e "${newname}" ]] ; then
        if [[ -e "${oldname}" ]]; then
            mv "${oldname}" "${newname}"
        fi
        # ucf doesn't offer a documented way to do this, so we need to 
        # peddle around with undocumented ucf internals.
        sed -i "s|${oldname}|${newname}|" /var/lib/ucf/hashfile
        ucfr --purge "${PKGNAME}" "${oldname}"
        ucfr "${PKGNAME}" "${newname}"
        # else: Don't do anything, leave old file in place
    fi
    ucfr "${PKGNAME}" "${newname}"
}

generate_directory_structure() {
    local pkgdir
    local locdir
    pkgdir="$1"
    locdir="$2"

    # generate empty directory structure

    (cd "${pkgdir}" && find . -type d -print0 ) | \
      (cd "${locdir}" && xargs -0 mkdir -p --)
}

# handle a single ucf_conffile by first checking whether the file might be
# accociated with a different package. If so, we keep our hands off the file
# so that a different package can safely hijack our conffiles.
# to hijack a file, simply ucfr it to a package before the ucf processing
# code.
# If the file is either unassociated or already associated with us, call ucf
# proper and register the file as ours.
handle_single_ucf_file()
{
    local pkgfile
    local locfile
    if [[ -n "${UCF_HELPER_FUNCTIONS_DEBUG:-}" ]]; then
        set -x
    fi

    pkgfile="$1"
    locfile="$2"
    export DEBIAN_FRONTEND

    PKG="$(ucfq --with-colons "${locdir}/${file}" | head -n 1 | cut 
--delimiter=: --fields=2 )"
    # skip conffile if it is associated with a different package.
    # This allows other packages to safely hijack our conffiles.
    if [[ -z "${PKG}" ]] || [[ "${PKG}" = "${PKGNAME}" ]]; then
        ${UCF} "${pkgfile}" "${locdir}/${file}"
        ucfr "${PKGNAME}" "${locdir}/${file}"
    fi
    set +x
}

# checks whether a file was deleted in the package and handle it on the local
# system appropriately: If the local file differs from what we had previously,
# we just unregister it and leave it on the system (preserving local changes),
# otherwise we remove it.
# this also removes conffiles that are zero-size after the
# ucf run, which might happen if the local admin has
# deleted a conffile that has changed in the package.
handle_deleted_ucf_file()
{
    local locfile
    local locdir
    local pkgdir
    if [[ -n "${UCF_HELPER_FUNCTIONS_DEBUG:-}" ]]; then
        set -x
    fi
    locfile="$1"
    pkgdir="$2"
    locdir="$3"

    # compute the name of the reference file in $pkgdir
    reffile="$(echo "${locfile}" | sed "s|${locdir}|${pkgdir}|")"
    if ! [[ -e "${reffile}" ]]; then
        # if the reference file does not exist, then it was removed in the 
package
        # do as if the file was replaced with an empty file
        ${UCF} /dev/null "${locfile}"
        if [[ -s "${locfile}" ]]; then
            # the file has non-zero size after the ucf run. local admin must
            # have decided to keep the file with contents. Done here.
            :
        else
            # the file has zero size and can be removed
            # remove the file itself ('') and all possible backup/reference 
extensions
            for ext in '' '~' '%' .bak .dpkg-tmp .dpkg-new .dpkg-old .dpkg-dist 
.ucf-new .ucf-old .ucf-dist;  do
              rm -f "${locfile}${ext}"
            done
        fi
        # unregister the file anyhow since the package doesn't know about it 
any more
        ucf --purge "${locfile}"
        ucfr --purge "${PKGNAME}" "${locfile}"
    fi
    set +x
}

handle_all_ucf_files() {
    local pkgdir
    local locdir
    pkgdir="$1"
    locdir="$2"

    generate_directory_structure "${pkgdir}" "${locdir}"

    # handle regular ucf-conffiles by iterating through all conffiles
    # that come with the package
    for file in $(find "${pkgdir}" -type f -printf '%P\n' ); do
        handle_single_ucf_file "${pkgdir}/${file}" "${locdir}/${file}"
    done

    # handle ucf-conffiles that were deleted in our package by iterating
    # through all ucf-conffiles that are registered for the package
    for locfile in $(ucfq --with-colons "${PKGNAME}" | cut --delimiter=: 
--fields=1); do
        handle_deleted_ucf_file "${locfile}" "${pkgdir}" "${locdir}"
    done
}

# vim:sw=4:sts=4:et:

Reply via email to