Pacnew automation

In the light of the latest events became clear, that a change in the conf files, respectively the generation of .pacnew files, is something that happens relatively rare, but when it happens is either overlooked from or confuses the less experienced users.
How about you automate the process a little bit? This can be integrated in MSM Notifier for example. Just like the check for new kernel or translation, it can periodically check for pacnew/old files. Then it can display a message for 2 cases.
Case 1: The user has a default old file.
In that case some function hashes the old file, compares with a databases with a default old file and if it sees the old one was a default file without any user customisation, asks the user it he wants to overwrite with the new one and for his sudo password and does it.
Case 2: The user has some customisation
Either just notify the user to deal with it, maybe showing a link to a tutorial, or automatically install a gui diff editor like meld and open it for inspection.

I see something similar here, with bash, but integrating into MSN or MSM gui will be another level.

While I see what your intentions are - I see problems.

What if user makes the wrong choice and wrecks the system?

That could easily happen with files like /etc/group, /etc/passwd and /etc/locale.gen.

When it is a manual - educated - by the user - invoked edit or replacement - it is concentious.

With the approach you suggest - the distribution will be blamed if the user makes a wrong decision.

We see that way to often with apps - installed using custom buildscripts - breaking when the system has been synced due to a new stable snap.

1 Like

Well then maybe hook/pacdiff and a popup at the end of the transaction in pamac, where the user can easily miss the creation of pacnew if not looking at the log: “There are new versions of some configuration files, please inspect and merge/overwrite. For more info see this wiki page.”

Hooks exist, ex:

pacdiff-pacman-hook-git

Somewhere and sometime I found this tutorial here and copied it out. I would very much like to pay my respects to the person and name the source, but I didn’t make a note of it:

This tutorial will teach you how to create a pacman hook to never miss any .pacnew files after an update.

Just create two files:

 Create a script that we’ll call later with the pacman hook, we’ll name it `check-pacnew` and create it in `/etc/pacman.d/scripts/` with your favorite editor:

#!/bin/bash
#
# List .pacnew files when found

pacnews=($(/usr/bin/pacdiff --output|grep -v pacsave))
nb="${#pacnews[@]}"
if [[ $nb > 0 ]]; then
  echo -e "\e[1;31m$nb .pacnew found in system \e[0m"
  printf "%s\n" "${pacnews[@]}"
fi

Ensure /etc/pacman.d/scripts/check-pacnew is owned by root and is executable!

The actual pacman hook, will be named check-pacnew.hook and should be created in /etc/pacman.d/hooks/:

    [Trigger]
    Operation = Upgrade
    Type = Package
    Target = *

    [Action]
    Description = Looking for .pacnew files...
    Exec = /etc/pacman.d/scripts/check-pacnew
    When = PostTransaction
    NeedsTargets

That’s it!

Thanks to the author unknown to me!

Edit: OK, @omano was the originator … Thanks to him!

@anon86816115

You’re welcome.

Thanks @omano , but why point down? Is this wrong? Please tell me what’s wrong with that.

Pacman does already handle this case where original = X, current = X, new = Y;

https://wiki.archlinux.org/title/Pacman/Pacnew_and_Pacsave#.pacnew

Would be the best and easiest solution I think. Otherwise, as recent events have shown, users who update via pamac gui may never learn that they need to deal with these files until something breaks.

1 Like

Because the answer to your question was under your post :slight_smile:

I didn’t “thumb down” :-1: your post, but I :point_down: “indexed” the post under yours :smiley:

Unfortunately may be true, but what is more unfortunate is people installing Arch based distribution not understanding these derivative distributions, like Arch itself, require at least basic maintenance, which everything is explained in the WIKI, but also unfortunate these people will never open a WIKI until they are told to.

4 Likes

Exactly my point. The users using pamac. Which is every new user of the distro, until they become more advanced users. They should get some help to notice something is there to be handled.

Thanks to this and the other linked topics where there are many similar scripts to find, i made my own flavour. It checks 30 seconds after boot and notifies with popup if there are pacdiff files. Does not do anything alone (because that is how i like it, only a notification if i have forgot something).

#!/usr/bin/env bash
#
# pacnew checker
#

sleep 30

#check if libnotify is available
if ! [[ "$(which notify-send)" =~ (notify-send) ]]; then
	echo ":: libnotify not found... sudo pacman -S libnotify"
	exit 1
fi

#check for pacnew and notify
pacnews=($(/usr/bin/pacdiff  -p --output|grep -v pacsave))
nb="${#pacnews[@]}"
if [[ $nb > 0 ]]; then
  echo -e "\e[1;31m$nb .pacnew found in system \e[0m"
  printf "%s\n" "${pacnews[@]}"
  notify-send -u normal "Use DIFFPROG=meld pacdiff -s" "<span color='#ff1000' font='28px'><b>.PACNEW files found</b></span>"
fi

For the future visitors of the thread: @Ste74 Stefano Capitani made a GUI variant of a checking script here

p.s. In case the above topic is not visible to you since the project is very new and still in the development section of the forum for internal testing, here is the public gitlab page

and the package in the repos is of course manjaro-pacnew-checker

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.