2

This is related to Create meaningful etckeeper commit messages.

I've patched /etc/etckeeper/pre-install.d/50uncommitted-changes as follows (to add support for a "PRECOMMIT" file):

#!/bin/sh
set -e
PRECOMMIT=/root/.etckeeper/pre-install.txt

if etckeeper unclean; then
    if [ "$AVOID_COMMIT_BEFORE_INSTALL" = 1 ]; then
        echo "" >&2
        echo "** etckeeper detected uncommitted changes in /etc prior to $HIGHLEVEL_PACKAGE_MANAGER run" >&2
        echo "** Aborting $HIGHLEVEL_PACKAGE_MANAGER run. Manually commit and restart." >&2
        echo "" >&2
        exit 1
    fi
    if [ -r "PRECOMMIT" ]; then
        MSG=$(cat "$PRECOMMIT")
    else
        MSG="saving uncommitted changes in /etc prior to $HIGHLEVEL_PACKAGE_MANAGER run"
    fi
    if ! etckeeper commit "$MSG"; then
        echo "warning: etckeeper failed to commit changes in /etc using $VCS" >&2
    fi
fi
[ -r "$PRECOMMIT" ] && mv "$PRECOMMIT"  "$(basename "$PRECOMMIT" txt).$(date +%Y%m%d.%s)"

And I've written a (Bash) shell function for my /root/bashrc which wraps the apt-get command to create the this "precommit" message (and to rename out of the way).

But I'd prefer to patch the hooks in /etc/apt/apt.conf.d/05etckeeper

My question is: can I capture the apt-get command's arguments from within a DPKG::Pre-Invoke command?

muru
  • 69,900
  • 13
  • 192
  • 292
Jim Dennis
  • 600
  • 2
  • 11
  • To be clear I'm most interested in capturing which packages were being installed or removed at each commit to etckeeper. Sometimes I can infer this from the changes made to /etc ... but not always. – Jim Dennis Mar 04 '18 at 22:59
  • With `Pre-Install-Pkgs`, you can get detailed package change information and the apt command that was run (%-encoded). For example, see my post on AU: https://askubuntu.com/a/1006704/158442 The manpage doesn't mention any similar input for `Pre-Invoke`. – muru Mar 05 '18 at 02:07

0 Answers0