[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 09:31:45AM +0200, Anders Andersson wrote:
> On Sun, Jun 15, 2025 at 7:45 AM Nicholas Geovanis
> <nickgeovanis@gmail.com> wrote:
> >
> >
> >
> > On Sat, Jun 14, 2025, 9:15 PM Boyan Penkov <boyan.penkov@gmail.com> wrote:
> >>
> >> Hello folks,
> >>
> >> I'm wiring to ask how to get apt to run a script after a particular
> >> package is installed or updated.  Am I looking for dpkg-triggers or
> >> some apt conf?
> >>
> >> Specifically, I have GRUB installed to *every* drive, with the
> >> expectation that all but one drives can fail and the machine will
> >> still boot (to something...).  To this end, after I see apt has
> >> updated grub, I manually run something like:
> >> ```
> >> sudo update-grub
> >> sudo grub-install /dev/sda
> >> sudo grub-install /dev/sdb
> >> sudo update-grub
> >> ```
> >> I'd like to automate this; if grub is changed, run this script automatically.
> >
> >
> > You could easily do this with ansible. In perhaps 30 lines of YAML you could install those fixes, and do the grub work in the same ansible source file. Repeatable the next time you have fixes to install, just run that playbook again with 1 command.
> 
> First of all, 30 lines to automate 2-4 lines is absurd. You have a
> hammer, don't recommend it to people who need a screwdriver!

OK, here is the screwdriver (from man apt.conf(5)):

       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.

(Those are in the DPkg section, so probably their full name is
DPkg::Post-Invoke, etc).

There seems to be also a Post-Invoke-Success hook, not documented in
the man page. From skimming the internet it seems to live Apt::Update
namespace (possibly it's just called once for a whole bunch of updates?).

Perhaps this would be worth a bug report against the APT doc, what do
you think?

Cheers
-- 
t

Attachment: signature.asc
Description: PGP signature


Reply to: