Re: Run script after package install, update
On Sun 15 Jun 2025 at 13:33:41 (-0400), Greg Wooledge wrote:
> On Sun, Jun 15, 2025 at 12:14:30 -0500, David Wright wrote:
> > Well, I just plagiarised /etc/apt/apt.conf.d/99needrestart:
> >
> > $ cat /etc/apt/apt.conf.d/99redogrub
> > DPkg::Post-Invoke {"test -x /var/local/bin/redo && /var/local/bin/redo || true"; };
> > $
> >
> > and wrote /var/local/bin/redo:
> >
> > $ cat /var/local/bin/redo
> > #!/bin/sh
> > if [ "/boot/grub/grub.cfg" -nt "/var/local/bin/redo" ]; then
> > grub-mkconfig -o /boot/grub/grub.cfg
> > fi
> > touch "/var/local/bin/redo"
> > #
>
> Looks reasonable. The only thing you might want to take note of is the
> -nt operand in /bin/sh's test command. It's in the 2024 edition of POSIX,
> but it's not in the previous edition, so one shouldn't expect it to be
> present in shells that are more than half a year old.
>
> Dash (in Bookworm) happens to include it, as well as bash, which is why it
> works here. It's just not as portable as you might have thought.
Indeed, I'd never heard of it, but feeling exhausted (gardening in
this heat), I googled instead of searching manpages, and it popped up.
It's in bullseye's dash too.
> I'm not sure why you've got scripts under /var, though. That's weird.
Well, I had no choice but to pollute /etc/apt/apt.conf.d/; however,
I have a few files under /var/local/ (like the home directory of the
user that unlocks /home remotely), so I created a bin/ and stuck it
there. After all, dpkg itself runs scripts from /var/lib/dpkg/info/.
Cheers,
David.
Reply to: