Scripting Bits
Published in

Scripting Bits

Figuring Out What Changed Between Package Versions

Catching up with changes to /etc

Whenever I update the packages on my Arch Linux system, I usually have to reconcile upstream changes to files in /etc with changes I’ve made to them for my system.

Usually, I just compare the new file, conveniently suffixed with .pacnew, with what I have. It’s usually pretty clear what the 3-way diff is, even when I’m not looking at one of them. But, sometimes I need to look at all three.

So, let’s work out a way to properly 3 way diff these files!

I know that Pacman caches packages in /var/cache/pacman/pkg. I want to get a specific file out of the two most recent versions of the same package.

First, I need to know about the structure of these packages; so, I run:

tar -tvf /var/cache/pacman/pkg/filesystem-2020.05.20-1-x86_64.pkg.tar.zst

This prints a list of all of the files in the package. From there, I can list the contents of one of the files:

tar -xOf /var/cache/pacman/pkg/filesystem-2020.05.20-1-x86_64.pkg.tar.zst etc/shadow

From there, starting a three way diff in Neovim looks like:

nvim -d <(tar ...) /etc/shadow <(tar ...)

From here, I can do a bunch more to massage this into a convenient script.

I can derive the name of the package from the path of the /etc file:

pacman -Qoq /etc/shadow

Then, I could list out the package versions:

ls -1 /var/cache/pacman/pkg/$(pacman -Qoq /etc/shadow)-*

I could even go as far as to pick the two most recent files by sorting by last modified date and then taking the top two:

ls -1t /var/cache/pacman/pkg/$(pacman -Qoq /etc/shadow)-* | head -n2

From there, putting everything together into a script is straightforward:

diffpkg /etc/shadow

Line 8 puts the results of ls into an array for easy access in script. Then, because $FILE starts with a /, the first character needs to be removed for the tar command. ${FILE#?} uses a regular expression to do just that!

Overall, that didn’t take very long. I like taking the time to automate daily tasks; it makes me more productive and helps keep my scripting skills sharp!




Join me in my short coding experiments where I dive into the rabbit hole of what-ifs!

Recommended from Medium

Davey Jones’ Docker

Generics in Java Programming

What I done did in September

Creating Products using Magento API

Go: Aliases, Simple and Efficient

Three things you should do to upgrade your survival gear as a self taught programmer

Docker, DevOps, data and depravity

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vinson Chuong

Vinson Chuong

More from Medium

Redirection Operator in Linux

What happens when you run apt commands

Bash concepts | .bashrc

Introduce Async/Await in Python