Check and manage pacnew files

For the issue with View & Merge, afterward it was doing nothing, I had a polkit window harassing me (it was opening again and again) I couldn’t close it and putting the password in it did not help deleting the pacnew.check file nor the .pacnew.

I will ending the correction and the new gui look, in the meantime you can delete the “pilot” file:
sudo rm /etc/pacnew-check.file

Update 2023-09-05T20:40:00Z

Well version 0.4.0 is in all branchs. I hope now all bugs are out. i have rewrite the GUI layout and insert the link for the forum and the wiki via buttons. Now all option for the files are showed in a list and only need to click the option you want.

Thanks! Will check it out :wink:

It seems it doesn’t work for me for the View & Merge function. when I close meld, it opens the polkit window to ask for password to remove the pacnew.check file, but I still have the pacnew. Actually the check file is removed now, it only prompts the polkit windows for the check file though.

It may be on my side, I created the pacnew by copying as root one of the config file.

Yep this should correct now in 0.4.0

Still there is an issue I think I have an idea, I’ll modify the SH script and report.

//EDIT: @Ste74 it is simple, the code is not run at all in the merge function when you click OK, then it doesn’t execute that pacnew-checker.sh · 912dc1164eef866528d224630ff350b330f45bb2 · Stefano Capitani / manjaro-pacnew-checker · GitLab but it executes that pacnew-checker.sh · 912dc1164eef866528d224630ff350b330f45bb2 · Stefano Capitani / manjaro-pacnew-checker · GitLab

Old and irrelevant now

here is my modified script for debugging (you need to create pacnew-check.file2 and pacnew-check.file3

#!/bin/env bash

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# Author: Stefano Capitani <stefanoatmanjarodotorg>

export PATH=/usr/bin:/usr/sbin

conflict_files=$(pacdiff -o)
icon=/usr/share/icons/manjaro/maia/32x32.png

files=$(mktemp)
pacdiff -o > "$files"

trap "rm -f ""$files"" ; exit" ERR EXIT

merge_function() {
    #Opening meld
    /usr/bin/meld "admin://${file%.pacnew}" "admin://$file"
    yad --title="Management of Pacnew/Pacsave files" --image="$icon" --text="Now we will <span foreground='red'>remove</span> Pacnew or Pacsave files or keep it" \
        --button=Cancel --button=Ok
    a="$?"

    if [[ "$a" -eq "0" ]]; then
        notify-send "file for merge function is = $file" && pkexec rm -f "$file" && pkexec rm -f /etc/pacnew-check.file2
    fi
}


wiki_link() {
    xdg-open https://wiki.manjaro.org/index.php/System_Maintenance/en#Pacnew_and_Pacsave_files 
}

forum_link() {
    xdg-open https://forum.manjaro.org/
}

export -f forum_link
export -f wiki_link

yad --title='Pacdiff Checker' --center --use-interp --on-top --info --text-info < "$files" --image="$icon" --text='<span foreground="red">New Pacnew/Pacsave files found:\n</span>
Keep in mind:
you must be aware of your choices;
if you are unsure please inquire using
our social channels such as our forum.\n' --button=Wiki:"wiki_link" --button=Forum:"forum_link" --button=Ok:0

unset -f forum_link
unset -f wiki_link

#Repeat through the conflict files and allow the user to choose what to do
for file in $conflict_files; do
    
    choices=$(yad --title="Management of Pacnew/Pacsave files" --height=250 --text "What do you want to do with the file <span foreground='red'>"$file"?</span>\n" \
    --list --no-headers --column=Option --column=Action \
    1 "Keep original and remove Pacnew or Pacsave" \
    2 "View and Merge Pacnew or Pacsave" \
    3 "Replace original with the Pacnew or Pacsave" \
    4 "Do nothing" \
    --no-buttons)
    
    choice=$(echo $choices | cut -d '|' -f1)
    
    case "$choice" in
        '1')
            # The user has chosen to keep the conflict file, do not do anything and remove the Pacnew.
            pkexec rm -f "$file" /etc/pacnew-check.file ;;
        '2')
            # The user has chosen to opening the diff files.
            merge_function ;;
        '3')
            # The user has chosen to replace the current configuration file with the Pacnew.
            pkexec mv -f "$file" "${file%.pacnew}" && pkexec rm -f /etc/pacnew-check.file ;;
        '4')
            continue  ;;
    esac
done

yad --title="Pacdiff Checker" --info --image="$icon" --text="Management of Pacnew/Pacsave completed." --button=Done

[[ -f /etc/pacnew-check.file ]] && pkexec rm -f /etc/pacnew-check.file3 && notify-send "file for end of script  is = $file"
 
#Remove this file if present ( it comes from v0.3.2 )
[[ -f $HOME/.config/.check-pacnew ]] && rm -f $HOME/.config/.check-pacnew

#End

You will see it doesn’t delete the pacnew-check.file2 from the merge function but the pacnew-check.file3 from the end of the script.

//EDIT 2: I isolated the issue, it is only this part that doesn’t work:

    if [[ "$a" -eq "0" ]]; then
        pkexec rm -f "$file" /etc/pacnew-check.file
    fi

$a is equal to 0 but it doesn’t “then”.

//EDIT3:
For fun this works so now we know more:

    if [[ "0" -eq "0" ]]; then
        pkexec rm -f "$file" /etc/pacnew-check.file
    fi

There is an issue in the comparator.

adding some notify-send -t 10000 "custom message here even with variable like $file or $a" everywhere in the script was very helpful for debugging on a side note.

Here you go, fixed merge function:

merge_function() {
    #Opening meld
    /usr/bin/meld "admin://${file%.pacnew}" "admin://$file"
    yad --title="Management of Pacnew/Pacsave files" --image="$icon" --text="Now we will <span foreground='red'>remove</span> Pacnew or Pacsave file" \
        --button='Cancel':10 \
        --button='Ok':20

    a="$?"
    if [ "$a" -eq "20" ]; then
        pkexec rm -f "$file" /etc/pacnew-check.file
    fi
}

I added the button exit status code, and I separated the buttons.
I was mistaken yesterday, $a WAS equal to “0” in my tests, but only because of my notify-send debugging helper lines I put just before grabbing status code in $a lol. $a was actually “1” in your code I don’t know why, I’ll stop here I spent two nights on this simple issue already lol.

Now it is fixed :wink: (and I changed the text line a little bit too to make it clearer, “now we will remove the pacnew” is clear, you click OK or Cancel.

//EDIT: What about the pacsave files? The tool talks about them, but it doesn’t seem to manage them. I think all references to Pacsave should be removed then so it doesn’t talk about the files it doesn’t manage :D.

//EDIT: I will send a modified whole script with changes to language and other stuff soon.

I modified the script so it handles only the .pacnew files, and will not be disturbed when you have .pacorig or .pacsave files, and change text at different places:

#!/bin/env bash

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# Author: Stefano Capitani <stefanoatmanjarodotorg>

export PATH=/usr/bin:/usr/sbin

conflict_files=$(pacdiff -o | grep -v .pacsave | grep -v .pacorig)
icon=/usr/share/icons/manjaro/maia/32x32.png

files=$(mktemp)
pacdiff -o | grep -v .pacsave | grep -v .pacorig > "$files"

trap "rm -f ""$files"" ; exit" ERR EXIT

merge_function() {
    #Opening meld
    /usr/bin/meld "admin://${file%.pacnew}" "admin://$file"
    yad --title="Management of Pacnew files" --image="$icon" --text="Now we will <span foreground='red'>remove</span> the Pacnew file" \
        --button='Cancel':1 \
        --button='Ok':0

    a="$?"
    if [ "$a" -eq "0" ]; then
        pkexec rm -f "$file" /etc/pacnew-check.file
    fi
}


wiki_link() {
    xdg-open https://wiki.manjaro.org/index.php/System_Maintenance/en#Pacnew_and_Pacsave_files 
}

forum_link() {
    xdg-open https://forum.manjaro.org/
}

export -f forum_link
export -f wiki_link

yad --title='Pacdiff Checker' --center --use-interp --on-top --info --text-info < "$files" --image="$icon" --text='<span foreground="red">New Pacnew files found:\n</span>
Keep in mind:
you must be aware of your choices;
if you are unsure please inquire using
our social channels such as our forum.\n' --button=Wiki:"wiki_link" --button=Forum:"forum_link" --button=Ok:0

unset -f forum_link
unset -f wiki_link

#Repeat through the conflict files and allow the user to choose what to do
for file in $conflict_files; do
    
    choices=$(yad --title="Management of Pacnew files" --height=250 --text "What do you want to do with the file <span foreground='red'>"$file"?</span>\n" \
    --list --no-headers --column=Option --column=Action \
    1 "Keep the original and remove the Pacnew" \
    2 "View and Merge the Pacnew" \
    3 "Replace original with the Pacnew" \
    4 "Do nothing" \
    --no-buttons)
    
    choice=$(echo $choices | cut -d '|' -f1)
    
    case "$choice" in
        '1')
            # The user has chosen to keep the original file, do not do anything and remove the Pacnew.
            pkexec rm -f "$file" /etc/pacnew-check.file ;;
        '2')
            # The user has chosen to compare files.
            merge_function ;;
        '3')
            # The user has chosen to replace the current configuration file with the Pacnew.
            pkexec mv -f "$file" "${file%.pacnew}" && pkexec rm -f /etc/pacnew-check.file ;;
        '4')
            continue ;;
    esac
done

yad --title="Pacnew Checker" --info --image="$icon" --text="Management of Pacnew complete" --button=Done

[[ -f /etc/pacnew-check.file ]] && pkexec rm -f /etc/pacnew-check.file
 
#Remove this file if present ( it comes from v0.3.2 )
[[ -f $HOME/.config/.check-pacnew ]] && rm -f $HOME/.config/.check-pacnew

#End

The pacdiff command also needs to be modified in the hook script:

#!/bin/bash

#Test if pacnew/pacsave are created and create the spy file
[[ "$(/usr/bin/pacdiff -o | /usr/bin/grep -v .pacsave | /usr/bin/grep -v .pacorig)" ]] && /usr/bin/touch /etc/pacnew-check.file

This way it will not trigger when it find these other file types.

Here is the comparison Free online tool to compare two text files and find difference.

Well m-p-c Is now at V0.4.1.
Should now all Is ok. Thank you at @omano for testing and feedback.

2 Likes

Currently if there is a .pacorig, or a .pacsave file in the system, the tool will trigger but will not be able to handle it correctly.


As I explained/changed in my previous post, the tool only manages .pacnew files, so the pacdiff command should be fixed in the scripts so pacdiff output is only for .pacnew, and not .pacsave and .pacorig (which WILL be in the output and WILL be in Pacnew Checker file list without proper modified pacdiff command).

Also all references to Pacsave in the text should be removed then.

See my previous post for all the text and the modified pacdiff command (or the link to view everything I changed in previous version).

Damn, you are right i work on this only in the evening when my daughter Is in the bed so Is possible i m focused here but don t see there :sweat_smile:… let me correct It :innocent:

2 Likes

There is something wrong with the service: the journal has some errors

pacnew-checker.path: Job paths.target/start deleted to break ordering cycle starting with pacnew-checker.path/start
paths.target: Job pacnew-checker.path/start deleted to break ordering cycle starting with paths.target/start

I think it is the same error just one was before update to last version of m-p-c.

Well seem a loop in target job… Will check also this…

Well modified the main script for manage all pac*. @omano can you check my new commit and correct my comment wich explain what do…

1 Like

I will have a look but not before this weekend unfortunately. Hope more people will join in the adventure :smiley: in the meantime.

Unfortunately, i am now experiencing what is described here.
On the old version i created a pacnew manually and it went smooth. But at that time there was an upgrade of m-p-c itself to 0.4.1-1. So it was a combination of existence of .pacnew and upgrade of m-p-c (the OP in the topic above describes fresh install, so it seems no problems when m-p-c- itself is installed at the same time).

Now i am on 0.4.1-1 and today there were some libpamac updates. I currently have no .pacnews. And this is the log

Looking for Pacnew/Pacsave created.
Error: command failed to execute correctly
Summary
Preparing...
Synchronizing package databases...
Refreshing extra.db...
Resolving dependencies...
Checking inter-conflicts...
Download of libpamac-snap-plugin (11.6.2+5+gd2841ba-1) started
Download of libpamac-snap-plugin (11.6.2+5+gd2841ba-1) finished
Download of libpamac-flatpak-plugin (11.6.2+5+gd2841ba-1) started
Download of libpamac-flatpak-plugin (11.6.2+5+gd2841ba-1) finished
Download of libpamac (11.6.2+5+gd2841ba-1) started
Download of libpamac (11.6.2+5+gd2841ba-1) finished
Checking keyring...
Checking integrity...
Loading packages files...
Checking file conflicts...
Checking available disk space...
Running pre-transaction hooks...
Creating Timeshift snapshot before upgrade...
==> skipping timeshift-autosnap due skipRsyncAutosnap in /etc/timeshift-autosnap.conf set to TRUE.
Upgrading libpamac (11.6.2+4+g52f2eb3-1 -> 11.6.2+5+gd2841ba-1)...
Upgrading libpamac-flatpak-plugin (11.6.2+4+g52f2eb3-1 -> 11.6.2+5+gd2841ba-1)...
Upgrading libpamac-snap-plugin (11.6.2+4+g52f2eb3-1 -> 11.6.2+5+gd2841ba-1)...
Running post-transaction hooks...
Reloading system manager configuration...
Arming ConditionNeedsUpdate...
Updating the MIME type database...
Reloading system bus configuration...
Looking for Pacnew/Pacsave created.
Error: command failed to execute correctly
Checking which packages need to be rebuilt
parallel: Warning: $HOME not set. Using /tmp.
Transaction successfully finished.

Did you enable the proper systemd unit after installing pacnew-checker?

Did you try that Error updating manjaro-pacnew-checker - #6 by fbt89

Isn’t it supposed to be enabled on install? And the problem here seem to be the hook not the service.

No i didn’t reinstall.

I think it depends when you installed it.

Then try the reinstall.

Ok i did. We’ll see on the next update about the hook.
The service does not seem to be running too but i guess it is the know bug with the target loop.

The hook triggered during install. Trigger it again sudo pacman -Syu nano.

About the errors I also have them in journal, but it is not specific to pacnew-checker:

Sep 08 20:22:06 omano-nvme systemd[1399]: default.target: Job xdg-user-dirs-update.service/start deleted to break ordering cycle starting with default.target/start
Sep 08 20:22:06 omano-nvme systemd[1399]: default.target: Job appimagelauncherd.service/start deleted to break ordering cycle starting with default.target/start
Sep 08 20:22:06 omano-nvme systemd[1399]: default.target: Job paths.target/start deleted to break ordering cycle starting with default.target/start

Well, i have upload 0.4.2:
correct the hook script ( yep seems my first statement doesn’t work as expected if no pac* are present ) and also I changed the systems services … ah right now all pac* generated are managed…

Nooooo. Just before I send my fixed version (lot of issues in you preview commit)

Here is the preview commit with all needed fixes…

#!/bin/env bash

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# Author: Stefano Capitani <stefanoatmanjarodotorg>

export PATH=/usr/bin:/usr/sbin

conflict_files=$(pacdiff -o)
icon=/usr/share/icons/manjaro/maia/32x32.png
title='Pacdiff Checker'
title1='Management of Pacnew/Pacsave/Pacorig files'

files=$(mktemp)
pacdiff -o > "$files"

trap "rm -f ""$files"" ; exit" ERR EXIT

merge_function() {
    #Opening meld
    /usr/bin/meld "admin://${file%."$suffix"}" "admin://$file"
    yad --title="$title1" --image="$icon" --text="Now we will <span foreground='red'>remove</span> the $suffix file" \
    --button=Cancel:1 --button=Ok:0

    a="$?"

    if [[ "$a" -eq "0" ]]; then
        pkexec rm -f "$file" /etc/pacnew-check.file
    fi
}


wiki_link() {
    xdg-open https://wiki.manjaro.org/index.php/System_Maintenance/en#Pacnew_and_Pacsave_files 
}

forum_link() {
    xdg-open https://forum.manjaro.org/
}

disclaimer_function() {
    yad --title="$title" --use-interp --width=750 --text="This program is free software, you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 3 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Author: Stefano Capitani
stefano@manjaro.org" --button=Ok

}

export -f forum_link
export -f wiki_link
export -f merge_function
export -f disclaimer_function

yad --title="$title" --center --use-interp --width=500 --on-top --info --text-info < "$files" --image="$icon" --text='<span foreground="red">New Pacnew/Pacsave/Pacorig files found:\n</span>
Keep in mind:\n
You must be aware of your choices. If you are unsure please inquire using our social channels such as our support forum.\n' --button=Disclaimer:"disclaimer_function" --button=Wiki:"wiki_link" --button=Forum:"forum_link" --button=Ok:0

#Repeat through the conflict files and allow the user to choose what to do
for file in $conflict_files; do

    suffix="${file##*.}"
    basefile="$(basename $file)"

    choices=$(yad --title="$title1" --use-interp --height=200 --width=500 --text "What do you want to do with the file <span foreground='red'>$basefile</span>?\n" \
    --list --no-headers --column=Option --column=Action \
    1 "Keep the original and remove the $suffix file" \
    2 "View and merge the $suffix file" \
    3 "Replace the original with the $suffix file" \
    4 "Do nothing" \
    --no-buttons)
    
    choice=$(echo $choices | cut -d '|' -f1)
    
    case "$choice" in
        '1')
            # The user has chosen to keep the original file, do not do anything and remove the Pac file.
            pkexec rm -f "$file" /etc/pacnew-check.file ;;
        '2')
            # The user has chosen to compare files.
            merge_function ;;
        '3')
            # The user has chosen to replace the current configuration file with the Pac file.
            pkexec mv -f "$file" "${file%."$suffix"}" && pkexec rm -f /etc/pacnew-check.file ;;
        '4')
            continue  ;;
    esac
done

yad --title="Pacdiff Checker" --info --image="$icon" --text="Management of Pacnew/Pacsave/Pacorig complete" --button=Done

unset -f merge_function
unset -f forum_link
unset -f wiki_link
unset -f disclaimer_function

[[ -f /etc/pacnew-check.file ]] && pkexec rm -f /etc/pacnew-check.file
 
#Remove this file if present ( it comes from v0.3.2 )
[[ -f $HOME/.config/.check-pacnew ]] && rm -f $HOME/.config/.check-pacnew

#End

The commit here was not working Check and manage pacnew files - #95 by Ste74 basically the suffix was empty so it broke the rest of the script.

//EDIT: ho OK you only updated the other main repo. Please have a look to the difference from current (broken) script, and mine, please push my script with all the fixes (after you TEST it and verify all is OK of course, not sure you tested the current one you pushed).