You are not logged in.

#1 2011-06-02 16:42:43

firyice
Member
From: NJ
Registered: 2011-05-27
Posts: 15

Safely displaying the number of updates

I like my status bar in dwm displaying the number of pacman updates available. Its a nice constant reminder bugging me to update my system every once in a while.

At first, I simply had something like this in my status bar script "dwm-status":

sudo pacman -Qu | wc -l

This always displayed 0 updates because I was not syncing my local database.  So I added something like this to .xinitrc:

sudo pacman -Sy

This did not work because sudo required a password, so I added something like this to my sudoers file:

%wheel NOPASSWD: /bin/pacman

Staying logged into X11, this was useless, so I made it a daily cron job, which is my current solution.

I'm worried about this being unsafe as described in here: https://bbs.archlinux.org/viewtopic.php?id=89328

This thread: https://bbs.archlinux.org/viewtopic.php?id=89484 discusses this topic a bit, and provides an ugly solution.  something like this:

dir=/tmp/somedir
if [ ! -d ${dir}]
    makedir ${dir}
sudo pacman -Sy --dbpath
ln -s /var/lib/pacman/local /tmp/somedir
sudo pacman -Qu --dbpath /tmp/somedir | wc -l
rm -r ${dir}

oh man is that messy for something that I feel like should be one line.  Anyone have any better suggestion? 

bonus:
a solution that allows me to take that nopasswd line out of my sudoers file
a solution that works with yoaurt too


EDIT:  Formatting, spelling, etc..

Last edited by firyice (2011-06-02 18:21:12)

Offline

#2 2011-06-02 17:23:15

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

Re: Safely displaying the number of updates

You don't need sudo for 'pacman -Qu'.

Offline

#3 2011-06-02 18:19:41

firyice
Member
From: NJ
Registered: 2011-05-27
Posts: 15

Re: Safely displaying the number of updates

karol wrote:

You don't need sudo for 'pacman -Qu'.

good call.  still need it for 'pacman -Sy' though

Offline

#4 2011-06-02 18:24:56

ebirtaid
Member
From: USA
Registered: 2007-11-18
Posts: 52

Re: Safely displaying the number of updates

I have pacman -Sy as a cronjob; just make sure to run -Syu (if there are updates) before installing anything and you shouldn't run into any problems.  On the other hand, you can not bother updating and just be ready for breakage big_smile

Offline

#5 2011-06-02 18:30:45

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

Re: Safely displaying the number of updates

ebirtaid wrote:

I have pacman -Sy as a cronjob; just make sure to run -Syu (if there are updates) before installing anything

Umm, 'pacman -Syu' already installs packages, so the only thing that needs to be updated are the packages from AUR.

I think updating once a week is enough. You should always take care when updating so you may want to check the MLs, bugtarcker and forums beforehand.

Offline

#6 2011-06-02 18:32:57

ebirtaid
Member
From: USA
Registered: 2007-11-18
Posts: 52

Re: Safely displaying the number of updates

karol wrote:
ebirtaid wrote:

I have pacman -Sy as a cronjob; just make sure to run -Syu (if there are updates) before installing anything

Umm, 'pacman -Syu' already installs packages, so the only thing that needs to be updated are the packages from AUR.

I mean run pacman -Syu before running pacman -S foo.  If you have pacman -Sy as a cronjob and it shows updates, and you run pacman -S foo after the cronjob'd pacman -Sy but before pacman -Syu, then it is the equivalent of running pacman -Sy foo.

E: also it's been a while since I have used yaourt but wouldn't yaourt -Syu --aur display the amount of packages to be updated between both the repos and aur or just the aur packages?

Ex2:  In any event if you install cower you can get what aur packages need to be updated with cower -u.  Then if you put pacman -Sy as a cronjob and use 'sudo pacman -Qu | wc -l' to get the avilable pacman updates, you can then use 'cower -u|wc -l' to get the aur updates count to display as well.

Last edited by ebirtaid (2011-06-02 18:52:08)

Offline

#7 2011-06-02 18:55:37

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

Re: Safely displaying the number of updates

http://code.google.com/p/pacupdate/ - I don't think it's all that unsafe, so why not give it a shot?

Offline

#8 2011-06-02 19:03:21

firyice
Member
From: NJ
Registered: 2011-05-27
Posts: 15

Re: Safely displaying the number of updates

ebirtaid wrote:

I have pacman -Sy as a cronjob; just make sure to run -Syu (if there are updates) before installing anything and you shouldn't run into any problems.

This is the solution I already have.  As I stated, I'm hoping for a safer solution.

karol wrote:

http://code.google.com/p/pacupdate/ - I don't think it's all that unsafe, so why not give it a shot?

I currently am running dwm without any system tray application.  I'd prefer not to use a system tray if I can avoid it.

Last edited by firyice (2011-06-02 19:06:10)

Offline

#9 2011-06-02 19:34:36

ebirtaid
Member
From: USA
Registered: 2007-11-18
Posts: 52

Re: Safely displaying the number of updates

pacupdate seems to do the same thing you are doing anyway, from the site:

Fetches ArchLinux package lists using pacman -Sy and parses output of pacman -Qu

The other way to do it using the code from your first post would be to create a directory in your home directory like ~/pacupdate.  Run 'ln -s /var/lib/pacman/local ~/pacupdate'.  Change the cronjob to 'pacman -Sy --dbpath /home/user/pacupdate' and the other to 'pacman -Qu --dbpath /home/user/pacupdate|wc -l' and in theory it should all work.

Offline

#10 2011-06-02 19:55:26

firyice
Member
From: NJ
Registered: 2011-05-27
Posts: 15

Re: Safely displaying the number of updates

ebirtaid wrote:

The other way to do it using the code from your first post would be to create a directory in your home directory like ~/pacupdate.  Run 'ln -s /var/lib/pacman/local ~/pacupdate'.  Change the cronjob to 'pacman -Sy --dbpath /home/user/pacupdate' and the other to 'pacman -Qu --dbpath /home/user/pacupdate|wc -l' and in theory it should all work.

So far, this seems like the best option

Last edited by firyice (2011-06-03 12:50:00)

Offline

#11 2011-06-02 20:04:17

eldragon
Member
From: Buenos Aires
Registered: 2008-11-18
Posts: 1,029

Re: Safely displaying the number of updates

why is it unsafe to do pacman -Sy in root's cronjob
and have your user's cronjob do pacman -Q without sudo?

Offline

#12 2011-06-02 22:18:49

firyice
Member
From: NJ
Registered: 2011-05-27
Posts: 15

Re: Safely displaying the number of updates

eldragon wrote:

why is it unsafe to do pacman -Sy in root's cronjob
and have your user's cronjob do pacman -Q without sudo?

because if a user runs 'pacman -S foo' after a sync, but before an update, pacman can bring in dependencies based upon a newer pacman database, which your system is not fully updated to.  This can break programs.  There is a more in-depth discussion on this in the two threads I linked to in the original post.

Offline

Board footer

Powered by FluxBB