You are not logged in.

#1 2014-02-23 16:06:51

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

[SOLVED] pacman -Qkk, getting diffs?

I am searching for an easy way for getting diffs on .conf (or any other) files from a given package.

I'll give one example to better explain: suppose I want to see which config files from the pacman package I have modified. I could start with

pacman -Qkk pacman

which is really nice, listing (in my case):

warning: pacman: /etc/makepkg.conf (Modification time mismatch)
warning: pacman: /etc/makepkg.conf (Size mismatch)
warning: pacman: /etc/pacman.conf (Modification time mismatch)
warning: pacman: /etc/pacman.conf (Size mismatch)

But I want a little more of just finding the modified files: I want to see which modifications have been made to them. Exactly a diff between the current file and the original file from the package.

Question is: does pacman have an integrated way to do it, maybe other addicional flag to -Qkk that I've missed? If not, what could I do trying to Keep it Simple?
(Of course, I could just find the original files, then manually doing the diffs, but I am trying to find if something more practical/direct already exists.)

Last edited by thiagowfx (2014-02-23 17:23:54)

Offline

#2 2014-02-23 16:13:07

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] pacman -Qkk, getting diffs?

Both /etc/pacman.conf and /etc/makepkg.conf are meant to be configured by users. There's nothing wrong with these files being a bit different than the ones originally included in the package.

Offline

#3 2014-02-23 16:24:12

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

Re: [SOLVED] pacman -Qkk, getting diffs?

Sorry, thought I made myself clear, pacman was only an example.

What I am trying to do is to find a way to list the diffs of any package.

Offline

#4 2014-02-23 16:27:20

Slithery
Forum Moderator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 4,750

Re: [SOLVED] pacman -Qkk, getting diffs?

Extract the original file from the package in your cache and redirect it into diff.

bsdtar -xOf /var/cache/pacman/pkg/pacman-4.1.2-5-x86_64.pkg.tar.xz etc/pacman.conf | diff - /etc/pacman.conf

Wrap that into a script or function of some sort.

Last edited by Slithery (2014-02-23 16:31:59)


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#5 2014-02-23 16:45:36

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,894
Website

Re: [SOLVED] pacman -Qkk, getting diffs?

This is a handy idea:

pkg="$(pacman -Qo $1 | awk '//{printf "%s-%s", $(NF-1), $NF;}')"

bsdtar -xOf /var/cache/pacman/pkg/${pkg}-x86_64.pkg.tar.xz ${1/\//} | diff - $1

pass the file name as the first parameter.

Last edited by Trilby (2014-02-23 16:46:19)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2014-02-23 16:46:00

Spider.007
Member
Registered: 2004-06-20
Posts: 1,174

Re: [SOLVED] pacman -Qkk, getting diffs?

You could combine slithery's suggestion with a simple loop eg; pacman -Qkk `pacman -Qq` 2>&1 >/dev/null | while read type pkg file; do bsdtar -xOf .... $file | diff - $file ; done

Offline

#7 2014-02-23 16:51:05

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

Re: [SOLVED] pacman -Qkk, getting diffs?

Thanks slithery, that's exactly what I wanted. I'll try to create a wrapper for this.

Edit: ops, you guys are fast. I'll test your wrappers first.

Last edited by thiagowfx (2014-02-23 16:51:31)

Offline

#8 2014-02-23 17:22:56

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

Re: [SOLVED] pacman -Qkk, getting diffs?

Nice, everything is working properly. I defined these:

qkkdiff () {
	ver=$(pacman -Q $1 | cut -f2 -d' ') 
	pacman -Qkkq $1 | while read package file
	do
		echo $file
		bsdtar -xOf /var/cache/pacman/pkg/${package}-${ver}-x86_64.pkg.tar.xz ${file/\//} | diff -uN - $file
	done
	return 0
}

qkkdiff-file () {
	pkg="$(pacman -Qo $1 | awk '//{printf "%s-%s", $(NF-1), $NF;}')" 
	bsdtar -xOf /var/cache/pacman/pkg/${pkg}-x86_64.pkg.tar.xz ${1/\//} | diff -uN - $1
	return 0
}

You are supposed to use the first one on a package, and the second one on a file.

Last edited by thiagowfx (2014-02-23 17:47:01)

Offline

#9 2014-02-23 17:44:57

Slithery
Forum Moderator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 4,750

Re: [SOLVED] pacman -Qkk, getting diffs?

Nice one thiagowfx, I'm stealing these.
Should prove useful for when I forget to document stuff as I'm going along smile

You may want to tweak them a bit though, at the minute they only work for x86_64 packages. They'll fall over if the package architecture is any or i686.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#10 2014-02-23 17:56:44

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,586
Website

Re: [SOLVED] pacman -Qkk, getting diffs?

@ thiagowfx,

While not a full replacement for what you want, pacman ships with pacdiff, which provides a way to diff the files which generate a pacnew file.

Last edited by x33a (2014-02-23 17:57:19)

Offline

#11 2014-05-31 22:19:34

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

Re: [SOLVED] pacman -Qkk, getting diffs?

Slightly updated version of the wrappers:

function qkkdiff-file {
    if [[ "$1" == "" ]];
    then
        echo "Example usage: qkkdiff-file /etc/pacman.conf"
    elif [[ -f "$1" ]];
    then
        pkg="$(pacman -Qo $1 | awk '//{printf "%s-%s", $(NF-1), $NF;}')"
        bsdtar -xOf /var/cache/pacman/pkg/${pkg}-$(uname -m).pkg.tar.xz "${1/\//}" | diff - "$1"
        return 0
    else
        echo "The provided file \e[0;31m${1}\e[0m does not exist."
        return 1
    fi
}

function qkkdiff {
    if [[ "$1" == "" ]];
    then
        echo "Example usage:\nqkkdiff pacman"
    elif ! pacman -Q "$1";
    then
        return 1
    else
        # Example usage: qkkdiff pacman
        ver=$(pacman -Q "$1" | cut -f2 -d' ')
        pacman -Qkkq "$1" | while read package file; do echo $file; bsdtar -xOf /var/cache/pacman/pkg/${package}-${ver}-$(uname -m).pkg.tar.xz ${file/\//} | diff - $file  ; done
        return 0
    fi
}

I'll not be posting more updates here. Those are available in ~/.aliases of my dotfiles.

Offline

Board footer

Powered by FluxBB