You are not logged in.

#1 2017-07-23 12:46:15

hermes666
Member
From: Lloret de Mar
Registered: 2017-07-09
Posts: 3

Display pacman updates conky

Hello to everybody!

This is my first small contribution to this awesome community!

I'm sure that many of you have seen hundreds, or even thousands of posts like this.
But by myself, I only found these two:
https://bbs.archlinux.org/viewtopic.php?id=37284
https://bbs.archlinux.org/viewtopic.php?id=149033

They are useful if you want to show the complete list of packages to be updated,
but if you only want to know how many packages need an update, they are sort of "bloatware".
So then, I made my own python script that only shows how many packages needs an update.
Finally I realized that I could do the same using Bash instead of Python, it would be shorter, and maybe a little bit faster.

So, this is my script written in Bash

#!/bin/bash

pkgNumber=$(pacman -Qu | wc -l)

if [ $pkgNumber -eq 0 ]; then
	echo "System up to date"
else
	pkgStr="package"
	if [ $pkgNumber -gt 1 ]; then
		pkgStr+="s"
	fi
	echo "$pkgNumber $pkgStr"
fi

As you can see this is a very short script, but if anybody knows any kind of improvement, is welcomed!

P.S.: Sorry if I made some mistyping, english is not my native language

Offline

#2 2017-07-23 12:50:28

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

Re: Display pacman updates conky

First, that script on it's own will never show any updates as available.  Presumably you have something else running that does a periodic `pacman -Sy`.  This is very bad - don't do this.  Use `checkupdates`.

And whether you use pacman -Qu or checkupdates, or anything else that lists the updates available, you can do all the above with an awk onliner:

pacman -Qu | awk 'END { print (NR == 0 ? "System up to date" : NR " package" (NR > 1 ? "s" : "")); }'

Or directly in conky (with the better checkupates):

${execpi 3600 checkupdates | awk 'END { print (NR == 0 ? "System up to date" : NR " package" (NR > 1 ? "s" : "")); }'}

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

Online

#3 2017-07-23 13:16:38

hermes666
Member
From: Lloret de Mar
Registered: 2017-07-09
Posts: 3

Re: Display pacman updates conky

Trilby wrote:

First, that script on it's own will never show any updates as available.  Presumably you have something else running that does a periodic `pacman -Sy`.  This is very bad - don't do this.  Use `checkupdates`.

Thanks for pointing out `checkupdates` script!
I didn't know about `checkupdates` existence.
As long as I can see, the other two posts are pretty old, maybe back then `checkupdates` didn't existed, I don't know.
And yes, I do a periodic `pacman -Sy` in a cron job.
So in the cron job I should replace `pacman -Sy` to `checkupdates`?
Or using directly `checkupdates`  into conky configuration file will do the job?

Edit:
The last line is absolute fabolous!
Thanks!

Last edited by hermes666 (2017-07-23 13:17:31)

Offline

#4 2017-07-23 13:21:54

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

Re: Display pacman updates conky

Checkupdates is noted in the conky wiki for this exact task.  Up until a few minutes ago there were several other options also listed there, but they all use the ill-advised -Sy approach, so I removed them.

hermes666 wrote:

So in the cron job I should replace `pacman -Sy` to `checkupdates`?
Or using directly `checkupdates`  into conky configuration file will do the job?

Using checkupates directly in the conky config (optionally with that awk line) will do the job.

The awk line should be efficient, but it is fairly dense as there are nested ternary operators.  Basically it just acts after the last line is read and uses the NR variable which is effectively the number of lines of input.  Then it prints a different message conditional on what that variable is: if it's 0 it prints the up to date message, otherwise it prints the number followed by the word package and appends an "s" if NR > 1.


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

Online

#5 2017-07-23 13:23:18

adesh
Member
Registered: 2016-10-05
Posts: 167

Re: Display pacman updates conky

hermes666 wrote:

And yes, I do a periodic `pacman -Sy` in a cron job.

Off-Topic: Never run "pacman -Sy" alone.
See https://wiki.archlinux.org/index.php/Sy … nsupported

Offline

#6 2017-07-23 13:29:51

hermes666
Member
From: Lloret de Mar
Registered: 2017-07-09
Posts: 3

Re: Display pacman updates conky

Deleted the cron job, and using checkupdates with awk.

This is definitely the best, short and safest way to do it, thanks again for pointing me the checkupdates approach!

Last edited by hermes666 (2017-07-23 13:32:45)

Offline

Board footer

Powered by FluxBB