My *nix world

Check Gentoo updates and notify

In Gentoo, to update your portage tree to the latest version one can do:

emerge --sync

In Gentoo, to fetch and merge the latest available packages into your system one can do:

emerge -pvDuN world

emerge -DuN world

In Gentoo, to remove the unnecessary dependencies that might remain and must to be removed one can do:

emerge -p --depclean

emerge --depclean

In Gentoo, to rebuild the missing dependencies one can do:

revdep-rebuild -pv

revdep-rebuild

In Gentoo, sometimes you need to update some configuration files after an package update. One can do that by:

dispatch-conf

In Gentoo, is sometimes also necessary to handle the new configuration files, so one can do:

etc-update

Many things can be done in Gentoo. That's why for me Gentoo means power. BUT I like to do Gentoo in my own way so I wrote a little daemon (sync-emerge) which synchronize (once, in background)  the portage tree at system start-up and a second bash script (which start once at session start-up) that check if exists new packages are available to be merged and if there are then send a balloon notification on the desktop informing user about that.

Later you can emerge those new packages by traditional means (emerge is your friend).

The daemon which  check Gentoo updates (sync-emerge):

 #!/sbin/runscript

opts="reload"

depend() {
after net
}

start() {
ebegin "Starting to synchronize the portage tree"
emerge --sync 1>/dev/null
eend $?
return 0
}

stop() {
ebegin "Stopping the sync-emerge daemon"
eend $?
return 0
}

reload() {
ebegin "Reloading sync-emerge"
eend $?

start
}

Copy this daemon at /etc/init.d/sync-emerge and configure your system to start it at start-up:

rc-update add sync-emerge default

The session bash script (check-emerge):

#!/bin/bash

while [ -n "$(/etc/init.d/sync-emerge status|awk '/starting/ {print 1}')" ];do
sleep 10 #wait 5 minutes, until the X daemon will synchronize the emerge database
done

NEWS=$(emerge -pvDuN world|awk '/[ebuild/ {if ($2=="U") {u++}; if ($2=="R") {r++}; if ($2=="D") {d++}; if($2=="F"){f++}; if($2=="I"){i++}; if($2=="B"){b++};} END {total=u+r+d+f+i+b; if(total>0){ print total" package available for update :"; if (u>0) {print " - updating : "u}; if (r>0){print " - replacing : "r};if(d>0){print " - downgrading : "d};if(f>0){print " - fetch restricted : "f};if(i>0){print " - interactive : "i};if(b>0){print " - blocked : "b};}}')

if [ -n "$NEWS" ];then
notify-send -i "/usr/share/icons/Tango/48x48/status/dialog-information.png" "Update available" "$NEWS"
fi

If you are using Xfce then you can go into Settings -> Session and Startup -> Application Autostart and define a new startup application like:

  • name=check-emerge
  • command=[path-to]/check-emerge

where [path-to] is the path to check-emerge bash script.

Note: don't forget to set both scripts as executable (chmod +x )

Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.

The following two tabs change content below.
Check Gentoo updates and notify

Eugen Mihailescu

Founder/programmer/one-man-show at Cubique Software
Always looking to learn more about *nix world, about the fundamental concepts of math, physics, electronics. I am also passionate about programming, database and systems administration. 16+ yrs experience in software development, designing enterprise systems, IT support and troubleshooting.
Check Gentoo updates and notify

Latest posts by Eugen Mihailescu (see all)

Tagged on: , ,

2 thoughts on “Check Gentoo updates and notify

  1. Sean Lijek

    If I turn off my computer before I go out somewhere, and turn it back on, can't I get in trouble if I sync the portage tree more than once per day?

Leave a Reply

Your email address will not be published. Required fields are marked *