Skip to content

Instantly share code, notes, and snippets.

@tbruckmaier
Created May 13, 2022 10:07
Show Gist options
  • Save tbruckmaier/4e80ddf163319349a24b3664b1be156c to your computer and use it in GitHub Desktop.
Save tbruckmaier/4e80ddf163319349a24b3664b1be156c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Bug report to introduce the feature in pamac:
# https://gitlab.manjaro.org/applications/pamac/-/issues/131
# how many version parts shall be compared? Default to 1 (only major versions)
N=${1-1}
{
pamac checkupdates
# cat "./pamac-checkupdates"
} | {
# only consider lines with a proper update
grep "\->"
} | {
# squeeze multiple whitespaces, so cut can properly detect the columns
# https://unix.stackexchange.com/questions/109835/how-do-i-use-cut-to-separate-by-multiple-whitespace
tr -s " "
} | {
# extract interesting columns, also ignore any non-matching lines
cut --only-delimited -d" " -f 1,2,3,4,5
} | {
while read line; do
# https://stackoverflow.com/questions/10520623/how-to-split-one-string-into-multiple-variables-in-bash-shell
IFS=" " read name v1 sep v2 repository <<< "$line"
# get the first N parts of each version. Consider only lines where these
# two parts differ
v1_prefix=$(echo "$v1" | sed -r "s/(([0-9]+[\.\-\:]){$N}).*/\1/")
v2_prefix=$(echo "$v2" | sed -r "s/(([0-9]+[\.\-\:]){$N}).*/\1/")
test "$v1_prefix" != "$v2_prefix" && echo "$line"
done
}
@tbruckmaier
Copy link
Author

Show pamac updates where the major version number has changed:

$ pamac-version-compare.sh 
adwaita-icon-theme 41.0-1 -> 42.0+r1+gc144c3d75-1 extra
akonadi-contacts 21.12.3-1 -> 22.04.0-1 extra
archlinux-appstream-data 20220327-1 -> 20220422-1 extra
ark 21.12.3-1 -> 22.04.0-1 extra
baloo-widgets 21.12.3-1 -> 22.04.0-1 extra
dav1d 0.9.2-1 -> 1.0.0-1 extra
dolphin 21.12.3-1 -> 22.04.0-1 extra
elementary-icon-theme 6.1.0-2 -> 7.0.0-1 community
...

To compare the first two parts of the version:

$ ./pamac-version-compare.sh 2
adwaita-icon-theme 41.0-1 -> 42.0+r1+gc144c3d75-1 extra
akonadi-contacts 21.12.3-1 -> 22.04.0-1 extra
antlr4-runtime 4.9.3-4 -> 4.10.1-2 community
archlinux-appstream-data 20220327-1 -> 20220422-1 extra
ark 21.12.3-1 -> 22.04.0-1 extra
attica 5.92.0-1 -> 5.93.0-1 extra
baloo 5.92.0-1 -> 5.93.0-1 extra
baloo-widgets 21.12.3-1 -> 22.04.0-1 extra
binutils 2.38-3 -> 2.38-4 core
breeze-icons 5.92.0-1 -> 5.93.0-1 extra
btrfs-progs 5.16.2-1 -> 5.17-1 core
budgie-desktop 10.6-1 -> 10.6.1-1 community
ca-certificates-mozilla 3.77-1 -> 3.78-1 core
cifs-utils 6.14-1 -> 6.15-1 extra
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment