You are not logged in.

#1 2010-08-27 16:48:47

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

Show installed version and current version for out of date packages

By popular demand https://bbs.archlinux.org/viewtopic.php?id=103494

for pkg in $(pacman -Quq); do
     echo $(pacman -Q $pkg) $(sudo pacman -Sdp --print-format "=> %v" $pkg)
done

'-Qu' prints out-of-date packages
'-Sdp ... %v' skips dependency checks and prints the version number

[karol@black ~]$ ./new
intel-dri 7.5.1-2 => 7.8.2-1
kernel26 2.6.34.3-1 => 2.6.35.3-1
libdrm 2.4.19-1 => 2.4.21-2
libgl 7.5.1-2 => 7.8.2-1
xf86-input-evdev 2.2.5-1 => 2.4.0-2
xf86-input-keyboard 1.3.2-2 => 1.4.0-2
xf86-input-mouse 1.4.0-2 => 1.5.0-2
xf86-video-vesa 2.2.0-1 => 2.3.0-2
xorg-server 1.6.3.901-1 => 1.8.1.902-1
xorg-server-utils 7.4-7 => 7.5-6

It's just a three-liner so you can get all kinds of unwanted behavior. I have xf86-video-intel-legacy installed, but it's not in the repos anymore so 'pacman -Qu' won't show it.
Feel free to extend it.

Offline

#2 2010-08-28 04:38:37

quigybo
Member
Registered: 2009-01-15
Posts: 220

Re: Show installed version and current version for out of date packages

I was getting this error on my IgnorePkgs

error: '$pkg': could not find or read package

so I added a quick and dodgy check on the exit status of -Sdp:

for pkg in $(pacman -Quq); do
     if ver="$(sudo pacman -Sdp --print-format '=> %v' $pkg 2>/dev/null)" ; then
         echo $(pacman -Q $pkg) $ver
     fi
done

edit: fixed nested quotes...

Last edited by quigybo (2010-08-28 04:44:44)

Offline

#3 2010-08-28 18:59:40

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

Re: Show installed version and current version for out of date packages

I think a better way is to specify via '--config' a config file that has no ignored packages.

grep -v IgnorePkg /etc/pacman.conf > ~/no-ignore-pkgs-pacman.conf

Version 0.2

config="/home/karol/no-ignore-pkgs-pacman.conf"

main () {
for pkg in $(pacman -Quq); do
     echo $(pacman -Q $pkg) "=>" $(sudo pacman -Sdp --config $config --print-format "%v" $pkg)
done | column -t;
}

main

Sample output:

intel-dri            7.5.1-2      =>  7.8.2-1
kernel26             2.6.34.3-1   =>  2.6.35.3-1
libdrm               2.4.19-1     =>  2.4.21-2
libgl                7.5.1-2      =>  7.8.2-1
086-input-evdev      2.2.5-1      =>  2.4.0-2
086-input-keyboard   1.3.2-2      =>  1.4.0-2
086-input-mouse      1.4.0-2      =>  1.5.0-2
086-video-vesa       2.2.0-1      =>  2.3.0-2
xorg-server          1.6.3.901-1  =>  1.8.1.902-1
xorg-server-utils    7.4-7        =>  7.5-6

Known issues:
None so far.


Features:
1. Buffered [1] and pretty-printed output.

[1] The output isn't written line-by-line but at once.

Offline

#4 2010-08-28 19:22:49

itsbrad212
Member
From: Chicago, USA
Registered: 2010-01-23
Posts: 1,848

Re: Show installed version and current version for out of date packages

Err, shouldn't you include a:

pacman -Sy &> /dev/null

so you don't have to manually refresh the database to see new packages? wink

EDIT: Also, use full program paths. smile

/usr/bin/pacman -Sy &> /dev/null
for pkg in $(/usr/bin/pacman -Quq); do
     echo $(/usr/bin/pacman -Q $pkg) $(/usr/bin/sudo /usr/bin/pacman -Sdp --print-format "=> %v" $pkg)
done

Last edited by itsbrad212 (2010-08-28 19:26:05)

Offline

#5 2010-08-28 19:39:31

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

Re: Show installed version and current version for out of date packages

itsbrad212 wrote:

Err, shouldn't you include a:

pacman -Sy &> /dev/null

so you don't have to manually refresh the database to see new packages? wink

Makes sense.

itsbrad212 wrote:

EDIT: Also, use full program paths. smile

I'll fix it in the next release - tomorrow ;P

BTW, is there a canonical way of naming functions? 'main' seemed better than 'foo'.

Offline

#6 2010-08-28 19:50:40

itsbrad212
Member
From: Chicago, USA
Registered: 2010-01-23
Posts: 1,848

Re: Show installed version and current version for out of date packages

karol wrote:

BTW, is there a canonical way of naming functions? 'main' seemed better than 'foo'.

I just name them for what they do. For example, if I have a function to parse an HTML file, then I would name it "parsehtml()". For the actual function that is run when your program is run, I like to stick to main.

Offline

#7 2010-08-28 20:17:36

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,097
Website

Re: Show installed version and current version for out of date packages

Nuts to your for loops, do it in one command.

paste <(printf "%20s %15s =>\n" $(pacman -Qu)) <(pacman -Sdp --print-format "%v" $(pacman -Qqu))

Shameless plug for Xyne: powerpill does this by default. Took me a while to figure out why this thread existed.

Offline

#8 2010-08-28 20:38:45

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

Re: Show installed version and current version for out of date packages

falconindy wrote:

Nuts to your for loops, do it in one command.

paste <(printf "%20s %15s =>\n" $(pacman -Qu)) <(pacman -Sdp --print-format "%v" $(pacman -Qqu))

That was my version 0.0 which I didn't post ;P

falconindy wrote:

Shameless plug for Xyne: powerpill does this by default. Took me a while to figure out why this thread existed.

Oh yes, if somebody wants to do it like a pro, use

karol@black ~]$ bauerbill -Qu
core/kernel26 2.6.34.3-1 -> 2.6.35.3-1

extra/intel-dri 7.5.1-2 -> 7.8.2-1
extra/libdrm 2.4.19-1 -> 2.4.21-2
extra/libgl 7.5.1-2 -> 7.8.2-1
extra/xf86-input-evdev 2.2.5-1 -> 2.4.0-2
extra/xf86-input-keyboard 1.3.2-2 -> 1.4.0-2
extra/xf86-input-mouse 1.4.0-2 -> 1.5.0-2
extra/xf86-video-vesa 2.2.0-1 -> 2.3.0-2
extra/xorg-server 1.6.3.901-1 -> 1.8.1.902-1
extra/xorg-server-utils 7.4-7 -> 7.5-6

instead. :-) And with bauerbill you don't have to use another config file.

Offline

#9 2010-08-28 21:34:37

itsbrad212
Member
From: Chicago, USA
Registered: 2010-01-23
Posts: 1,848

Re: Show installed version and current version for out of date packages

karol wrote:

Oh yes, if somebody wants to do it like a pro, use

karol@black ~]$ bauerbill -Qu
core/kernel26 2.6.34.3-1 -> 2.6.35.3-1

extra/intel-dri 7.5.1-2 -> 7.8.2-1
extra/libdrm 2.4.19-1 -> 2.4.21-2
extra/libgl 7.5.1-2 -> 7.8.2-1
extra/xf86-input-evdev 2.2.5-1 -> 2.4.0-2
extra/xf86-input-keyboard 1.3.2-2 -> 1.4.0-2
extra/xf86-input-mouse 1.4.0-2 -> 1.5.0-2
extra/xf86-video-vesa 2.2.0-1 -> 2.3.0-2
extra/xorg-server 1.6.3.901-1 -> 1.8.1.902-1
extra/xorg-server-utils 7.4-7 -> 7.5-6

instead. :-) And with bauerbill you don't have to use another config file.

Yes, but then you don't get the satisfaction of thinking "karol made this"! tongue

Last edited by itsbrad212 (2010-08-28 21:34:59)

Offline

#10 2010-08-29 01:50:41

itsbrad212
Member
From: Chicago, USA
Registered: 2010-01-23
Posts: 1,848

Re: Show installed version and current version for out of date packages

Don't forget pretty colored output:

echo "\e[1;33m" $(/usr/bin/pacman -Q $pkg) "\e[1;0m" $(/usr/bin/sudo /usr/bin/pacman -Sdp --print-format "\e[1;32m=>\e[0m %v" $pkg) "\e[0;0m"

Offline

#11 2010-08-29 13:57:28

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

Re: Show installed version and current version for out of date packages

itsbrad212 wrote:

Don't forget pretty colored output:

echo "\e[1;33m" $(/usr/bin/pacman -Q $pkg) "\e[1;0m" $(/usr/bin/sudo /usr/bin/pacman -Sdp --print-format "\e[1;32m=>\e[0m %v" $pkg) "\e[0;0m"

It just crashed all my terminals :-(

Aug 29 16:02:10 black kernel: urxvtd[2891]: segfault at 6d305b65 ip b73d53c4 sp bfa937a8 error 4 in libc-2.12.1.       so[b73a8000+145000]

I think it should be 'echo -e' to interpret the escape sequences.

Last edited by karol (2010-08-29 20:33:27)

Offline

#12 2010-08-29 21:33:45

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

Re: Show installed version and current version for out of date packages

I won't use colors, because there's no need for them: the columns say it all.

I think paste + printf is a neat way, but 'column -t' is great for lazy people like me :-)

Version 0.3

config="/home/karol/no-ignore-pkgs-pacman.conf"

/usr/bin/sudo /usr/bin/pacman -Sy &> /dev/null


foo () {
for pkg in $(/usr/bin/pacman -Quq); do
     echo $(/usr/bin/pacman -Q $pkg) "=>" $(/usr/bin/sudo /usr/bin/pacman -Sdp --config $config --print-format "%v"   $pkg)
done | /usr/bin/column -t;
}

foo

Version 0.3-paste

config="/home/karol/no-ignore-pkgs-pacman.conf"

/usr/bin/sudo /usr/bin/pacman -Sy &> /dev/null

# printf: hard precision on package names, easy on version numbers
/usr/bin/paste -d " " <(/usr/bin/printf "%-20.20s %-12s => \n" $(/usr/bin/pacman -Qu)) <(/usr/bin/sudo /usr/bin/pacman -Sdp --config $config --print-format "%v" $(/usr/bin/pacman -Qqu))

Last edited by karol (2010-08-29 21:35:06)

Offline

#13 2010-08-29 21:42:45

itsbrad212
Member
From: Chicago, USA
Registered: 2010-01-23
Posts: 1,848

Re: Show installed version and current version for out of date packages

karol wrote:
itsbrad212 wrote:

Don't forget pretty colored output:

echo "\e[1;33m" $(/usr/bin/pacman -Q $pkg) "\e[1;0m" $(/usr/bin/sudo /usr/bin/pacman -Sdp --print-format "\e[1;32m=>\e[0m %v" $pkg) "\e[0;0m"

It just crashed all my terminals :-(

Aug 29 16:02:10 black kernel: urxvtd[2891]: segfault at 6d305b65 ip b73d53c4 sp bfa937a8 error 4 in libc-2.12.1.       so[b73a8000+145000]

I think it should be 'echo -e' to interpret the escape sequences.

You're right, it should be that. Interesting that it didn't crash for me, as I use urxvt as well.

Offline

#14 2010-08-29 21:48:51

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,097
Website

Re: Show installed version and current version for out of date packages

Instead of defining a config, create it on the fly...

--config <(grep -v "^Ignore" /etc/pacman.conf)

This does, however, mean that you have to fork for each iteration of the loop. Perhaps use a cache file?

You also don't need sudo for -Sdp.

Offline

#15 2010-08-29 21:54:41

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

Re: Show installed version and current version for out of date packages

itsbrad212 wrote:
karol wrote:
itsbrad212 wrote:

Don't forget pretty colored output:

echo "\e[1;33m" $(/usr/bin/pacman -Q $pkg) "\e[1;0m" $(/usr/bin/sudo /usr/bin/pacman -Sdp --print-format "\e[1;32m=>\e[0m %v" $pkg) "\e[0;0m"

It just crashed all my terminals :-(

Aug 29 16:02:10 black kernel: urxvtd[2891]: segfault at 6d305b65 ip b73d53c4 sp bfa937a8 error 4 in libc-2.12.1.       so[b73a8000+145000]

I think it should be 'echo -e' to interpret the escape sequences.

You're right, it should be that. Interesting that it didn't crash for me, as I use urxvt as well.

Well, honestly, I just wanted you to feel bad ;P It could have been completely unrelated as I can't reproduce it.
I've used your line twice and it printed all the escape codes and then all urxvt instances happily folded :-)

Offline

#16 2010-08-29 21:56:42

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

Re: Show installed version and current version for out of date packages

falconindy wrote:

You also don't need sudo for -Sdp.

That means there will be another version. Back to reading 'man pacman' and friends.

Offline

#17 2010-08-30 12:01:11

quigybo
Member
Registered: 2009-01-15
Posts: 220

Re: Show installed version and current version for out of date packages

falconindy wrote:

Instead of defining a config, create it on the fly...

--config <(grep -v "^Ignore" /etc/pacman.conf)

This does, however, mean that you have to fork for each iteration of the loop. Perhaps use a cache file?

No need for a cache file if you use this with the paste method, it is only called once as there is no loop.

This along with the paste method is amazingly quicker than the for loop, tis definitely the winner imo.

I know it is personal preference, but I prefer something like this for printf and -d "" for paste:

"%-20.20s %12s  =>  \n"

Last edited by quigybo (2010-08-30 12:07:19)

Offline

#18 2010-08-31 13:15:59

quigybo
Member
Registered: 2009-01-15
Posts: 220

Re: Show installed version and current version for out of date packages

One thing I just realised about using -Qu to get the list of packages is that it will not show any new dependencies that the to-be-upgraded version of a package may have, so I propose using -Sup instead:

for pkg in $(/usr/bin/pacman -Sup --print-format "%n" | grep -v "Starting full system upgrade\|nothing to do"); do
     /bin/echo $(/usr/bin/pacman -Q $pkg 2>/dev/null || /bin/echo $pkg new) "=>" $(/usr/bin/pacman -Sdp --print-format "%v" $pkg)
done | /usr/bin/column -t

Annoyingly pacman will still show "Starting full system upgrade" when using -u with -p (which you would think is mostly used for scripting). I wonder if it is worthy of a feature request on the bug tracker, as it is even the case when using --quiet? I'm happy to file it if people agree with me? edit: submitted here

I still think that the paste method is the way to go as it is quicker, however I couldn't see an easy/clean way to do it with the output of -Sup, as it can also contain new packages not yet in pacman's -Q database.

One side-effect of using -Sup instead is that it honours IgnorePkg properly, which is imo better than using a 'clean' config file. At least for me when I ignore a package I don't want to know or hear about it again. You can always include falconindy's --config <(grep ...) where appropriate if you feel otherwise.

Last edited by quigybo (2010-08-31 13:41:31)

Offline

#19 2010-08-31 13:26:33

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

Re: Show installed version and current version for out of date packages

$ pacman -Sup --print-format "%n"
:: Starting full system upgrade...
 there is nothing to do
$ pacman -Qu
intel-dri 7.5.1-2
kernel26 2.6.34.3-1
libdrm 2.4.19-1
libgl 7.5.1-2
xf86-input-evdev 2.2.5-1
xf86-input-keyboard 1.3.2-2
xf86-input-mouse 1.4.0-2
xf86-video-vesa 2.2.0-1
xorg-server 1.6.3.901-1
xorg-server-utils 7.4-7

I have a bunch of IgnoredPkgs and -Qu sees them, -Sup does not.

Offline

#20 2010-08-31 13:39:04

quigybo
Member
Registered: 2009-01-15
Posts: 220

Re: Show installed version and current version for out of date packages

karol wrote:

I have a bunch of IgnoredPkgs and -Qu sees them, -Sup does not.

I actually prefer this behaviour, but as I mentioned you can easily add --config where needed if you feel otherwise. The main reason for using -Sup instead of -Qu is to show new (as yet uninstalled) dependencies that may arise when an installed package upgrades and its dependencies change.

Also, I submitted a feature request on pacman's -Supq behaviour here anyway, as it is relevant to another pacman script I have too.

Offline

#21 2010-08-31 13:50:15

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

Re: Show installed version and current version for out of date packages

quigybo wrote:
karol wrote:

I have a bunch of IgnoredPkgs and -Qu sees them, -Sup does not.

I actually prefer this behaviour, but as I mentioned you can easily add --config where needed if you feel otherwise. The main reason for using -Sup instead of -Qu is to show new (as yet uninstalled) dependencies that may arise when an installed package upgrades and its dependencies change.

Also, I submitted a feature request on pacman's -Supq behaviour here anyway, as it is relevant to another pacman script I have too.

Even -Sup won't show xf86-video-intel as a "new version" of my xf86-video-intel-legacy, neither will 'bauerbill -Qu'.

[karol@black ~]$ sudo pacman -Su
:: Starting full system upgrade...
warning: hdparm: local (9.29-1) is newer than core (9.28-1)
warning: lrzip: local (0.46-1) is newer than archlinuxfr (0.45-1)
warning: stfl: local (0.21-2) is newer than dragonlord (0.21-1)
:: Replace xf86-video-intel-legacy with archstuff/xf86-video-intel-newest? [Y/n] n
resolving dependencies...
looking for inter-conflicts...
:: xorg-server and xf86-video-intel-legacy are in conflict. Remove xf86-video-intel-legacy? [y/N] n
error: unresolvable package conflicts detected
error: failed to prepare transaction (conflicting dependencies)
:: xorg-server and xf86-video-intel-legacy are in conflict

I answered 'no' to both questions.

Can you post the output where you get new dependencies? How will you know what they are? Won't it look like:

intel-dri            7.5.1-2      =>  7.8.2-1
jumanji-git          20100727-1   =>  20100830-1
kernel26             2.6.34.3-1   =>  2.6.35.4-1
libdrm               2.4.19-1     =>  2.4.21-2
libgl                7.5.1-2      =>  7.8.2-1
tcp_wrappers         7.6-11       =>  7.6-12
udev                 161-1        =>  161-2
xf86-input-evdev     2.2.5-1      =>  2.4.0-2
xf86-input-keyboard  1.3.2-2      =>  1.4.0-2
xf86-input-mouse     1.4.0-2      =>  1.5.0-2
                                  =>  1.2.3.4
xf86-video-vesa      2.2.0-1      =>  2.3.0-2
xorg-server          1.6.3.901-1  =>  1.8.1.902-1
xorg-server-utils    7.4-7        =>  7.5-6

Offline

#22 2010-08-31 14:26:14

quigybo
Member
Registered: 2009-01-15
Posts: 220

Re: Show installed version and current version for out of date packages

karol wrote:

Can you post the output where you get new dependencies? How will you know what they are?

Thats why I have "|| echo $pkg new" if you look closely. A little dodgy but oh well...

So as in your example it will look something like this:

xf86-input-mouse     1.4.0-2      =>  1.5.0-2
newdependency        new          =>  1.2.3.4
xf86-video-vesa      2.2.0-1      =>  2.3.0-2
karol wrote:
[karol@black ~]$ sudo pacman -Su
:: Starting full system upgrade...
warning: hdparm: local (9.29-1) is newer than core (9.28-1)
warning: lrzip: local (0.46-1) is newer than archlinuxfr (0.45-1)
warning: stfl: local (0.21-2) is newer than dragonlord (0.21-1)
:: Replace xf86-video-intel-legacy with archstuff/xf86-video-intel-newest? [Y/n] n
resolving dependencies...
looking for inter-conflicts...
:: xorg-server and xf86-video-intel-legacy are in conflict. Remove xf86-video-intel-legacy? [y/N] n
error: unresolvable package conflicts detected
error: failed to prepare transaction (conflicting dependencies)
:: xorg-server and xf86-video-intel-legacy are in conflict

What happens with -Sup instead of just -Su? Sorry I don't have any replaces at the moment.

Offline

#23 2010-08-31 14:42:27

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

Re: Show installed version and current version for out of date packages

[karol@black code]$ pacman -Sup
:: Starting full system upgrade...
http://darkstar.ist.utl.pt/archlinux/extra/os/i686/libdrm-2.4.21-2-i686.pkg.tar.xz
http://darkstar.ist.utl.pt/archlinux/extra/os/i686/libgl-7.8.2-1-i686.pkg.tar.xz
http://darkstar.ist.utl.pt/archlinux/extra/os/i686/intel-dri-7.8.2-1-i686.pkg.tar.xz
http://repo.archlinux.fr/i686/jumanji-git-20100830-1-i686.pkg.tar.xz
http://darkstar.ist.utl.pt/archlinux/core/os/i686/kernel26-2.6.35.4-1-i686.pkg.tar.xz
http://darkstar.ist.utl.pt/archlinux/core/os/i686/tcp_wrappers-7.6-12-i686.pkg.tar.xz
http://darkstar.ist.utl.pt/archlinux/core/os/i686/udev-161-2-i686.pkg.tar.xz
http://darkstar.ist.utl.pt/archlinux/extra/os/i686/xf86-input-evdev-2.4.0-2-i686.pkg.tar.xz
http://darkstar.ist.utl.pt/archlinux/extra/os/i686/xf86-input-keyboard-1.4.0-2-i686.pkg.tar.xz
http://darkstar.ist.utl.pt/archlinux/extra/os/i686/xf86-input-mouse-1.5.0-2-i686.pkg.tar.xz
http://darkstar.ist.utl.pt/archlinux/extra/os/i686/xf86-video-vesa-2.3.0-2-i686.pkg.tar.xz
http://darkstar.ist.utl.pt/archlinux/extra/os/i686/xorg-server-utils-7.5-6-i686.pkg.tar.xz
http://darkstar.ist.utl.pt/archlinux/extra/os/i686/xorg-server-1.8.1.902-1-i686.pkg.tar.xz

Edit: Is there a way to show just the version numbers with 'pacman -Q' other than

pacman -Qu | cut -d " " -f 2

or some similar awking? '-Qp' means something entirely different than '-Sp'.

Last edited by karol (2010-08-31 15:02:26)

Offline

#24 2010-08-31 15:07:15

quigybo
Member
Registered: 2009-01-15
Posts: 220

Re: Show installed version and current version for out of date packages

Strange that it doesn't list archstuff/xf86-video-intel-newest, maybe it has something to do with the fact that it is (I'm guessing) a local repo? I doubt it, but does -Sup --print-format "%n" make a difference?

Maybe -Sup doesn't list replaces properly, but it does list new dependencies when an installed package changes its dependency list, so at least it is a little step up from -Qu.

Offline

#25 2010-08-31 15:12:55

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

Re: Show installed version and current version for out of date packages

intel-legacy is not in the repos anymore (the package shows up in 'pacman -Qm') and when I upgrade I have to explicitly install xf86-video-intel, because pacman only warns me about conflicts.

[karol@black code]$ pacman -Sup --print-format "%n"
:: Starting full system upgrade...
libdrm
libgl
intel-dri
jumanji-git
kernel26
tcp_wrappers
udev
xf86-input-evdev
xf86-input-keyboard
xf86-input-mouse
xf86-video-vesa
xorg-server-utils
xorg-server

No Intel drivers here.

Last edited by karol (2010-08-31 16:00:06)

Offline

Board footer

Powered by FluxBB