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

Re: Run script after package install, update?



On Sun, Jun 15, 2025 at 11:33:09AM -0400, Greg Wooledge wrote:
> On Sun, Jun 15, 2025 at 11:07:41 -0400, Boyan Penkov wrote:
> > So ultimately, my problem is addressed; however, the larger question
> > is still open: is there in fact a straightforward way for a user, not
> > the package maintainer, to tell the package management system: "If and
> > only if your operation touched package x, also do this one thing
> > locally."?  I can think of about a million use cases for this: "if you
> > touched maildir-utils, run mu  index." "if you touched offlineimap,
> > run offlineimap" "if you touched etckeeper, re-commit the /etc files"
> > and so on ...
> 
> Since the apt documentation is such complete rubbish, the only ways
> to actually figure out how anything *works* are source diving and
> experimenting.  I do not feel like trying to source-dive through apt
> and its libraries, so I tried an experiment.
> 
> According to the apt.conf(5) man page:
> 
>        Pre-Invoke, Post-Invoke
>            This is a list of shell commands to run before/after invoking
>            dpkg(1). Like options this must be specified in list notation. The
>            commands are invoked in order using /bin/sh; should any fail APT
>            will abort.
> 
> That's clear as mud.  What is "list notation"?  Again, I had to experiment.
> I tried looking for examples, learned that the
> /usr/share/doc/apt/examples/configure-index.gz file documented at the end
> of the man page does not exist, discovered that the file
> /usr/share/doc/apt/examples/configure-index exists instead, read that, and
> found nothing helpful in deciphering what an apt.conf.d/* file should
> look like.

Aaah. I guess they mean Perl-y lists, like ["foo", "bar", "baz"].

> I looked at other files in /etc/apt/apt.conf.d/ for inspiration, and
> tried searching for the word "list" in the man page, but ultimately it
> came down to experimenting until I got it right.
> 
> Here's what I did:
> 
> 1) I created the file /etc/apt/apt.conf.d/99localexperiment with the
> following contents:
> 
> ====================================================================
> DPkg::Post-Invoke { /usr/local/sbin/dpkg-experiment; };
> ====================================================================

Hm. Seems they are more permissive than I guessed :-)
But anyway, you found out.

> 2) I created the script /usr/local/sbin/dpkg-experiment with the following
> contents:
> 
> ====================================================================
> #!/bin/sh
> exec > /var/tmp/dpkg-experiment
> printf '%s args' "$#"
> if test "$#" != 0; then
>     printf :
>     printf ' <%s>' "$@"
> fi
> echo; echo
> ps -fp "$$,$PPID"
> echo
> env
> ====================================================================
> 
> and gave it 755 permissions.
> 
> 3) I installed a package by running "sudo apt-get install sl".
> 
> Here's the /var/tmp/dpkg-experiment file that was created as a result:

[...]

> Conclusion: there is nothing at all in the environment or arguments
> passed to the Post-Invoke script(s) that indicate what has been done.
> Any such scripts created by the local sysadmin will have to take their
> own investigative steps to try to figure out what happened, and what
> they should do about it.
> 
> Unless of course there's some *other* hook that we don't know about
> because the documentation is so poor.

Yep, that's the sad state. Thanks for investigating. Perhaps it'd be
worth talking to the devels.

Cheers
-- 
t

Attachment: signature.asc
Description: PGP signature


Reply to: