Gentoo Linux Update Script by Felix Petzold

I have updated my script to version 2.1. It comes with an installer/updater now. It uses >=portage-2.2_rc67 and needs this for installation. But this dependency will be managed by the installer using autounmask.

What has changed?
A run without emerges is now only 8 minutes. Before it was 40 (on my Acer Aspire 7738G). This is achieved by outsourcing functions and executing them not so often. The "gentoo_ebuild_update_check_by_maggu2810" is now executed once a week and "gentoo-decruft" by bell is executed once a month.

New is, that there is a program version watcher that reacts on updates for Firefox, Thunderbird and xorg-server. If Firefox (or Firefox-bin) is updated, adobe-flash, swfdec and swfdec-mozilla will be reinstalled. If Thunderbird (or Thunderbird-bin) is updated, "emerge -1 enigmail" is executed. And if xorg-server is updated, "emerge -1 $(qlist -I -C x11-drivers/)" will be executed. If one or many watched programs are not installed on your system, this will be recognized and nothing is done for them, as you can see in the sample down at the end. I have no Thunderbird installed and watching Thunderbird is skipped on my system.

Explanation what is done:
update_sources - This function updates layman, portage und eix
get_old_versions - save versions of watched programs
update_system - update the system. If there is an error "emerge --resume --skipfirst" will be executed until there is nothing to do any more
get_new_versions - save new versions of watched programs
react_on_version_differences - if updated do what described above
emerge_depclean - executes "emerge --depclean"
lafilefixer_fixit - executes lafilefixer
preserved_rebuild - executes "emerge @preserved-rebuild"
pearl_cleaner - executes pearl cleaner
check_broken_librarys - executes "revdep-rebuild"
cfg_update - "cfg-update -ua" updates all configs marked automatic (-a) so you only have to deal with the rest
clean_system - executes "eclean packages" and "eclean distfiles"
exit_update - if there was an error a notice to the user will be given

Also will be installed:
"gentoo-decruft" by bell can be executed from the shell and will be executed by a cron job every month. Duration: ~1h
"gentoo_ebuild_update_check_by_maggu2810" can also be executed from the shell and is executed by a jron job weekly
"updateScriptVersionChecker" is my installer / updater and will be executed by a cron job weekly but can be run from the shell as well


Installation:
Things you already have installed / configured on your system can be skipped

local overlay:
A local overlay is used to add software to the portage tree.

Code:
mkdir -p /usr/local/portage/overlay # path to your local overlay
mkdir -p /usr/local/portage/overlay/profiles/ # profiles folder in your local overlay
echo "local overlay" >> /usr/local/portage/overlay/profiles/repo_name # give your local overlay the name "local overlay"
chown -R portage:portage /usr/local/portage/overlay # this is how it should be ;-)


Now you have a local overlay with the name "local overlay". If you want portage to use it, you have to set this up in /etc/make.conf

Code:
echo "PORTDIR_OVERLAY=\"/usr/local/portage/overlay\"" >> /etc/make.conf


Now you have your local overlay configured. It may be empty, but portage and my installer will use the path configured in /etc/make.conf to find it. This local overlay is where the source code of the script will be after you have run the installer. There you can take it and configure it to your needs.


elogv and portage elog messages:
elogv is a tool used to read elog messages saved by portage if you configured portage this way. We will do that now. Elog messages are the outputs running through the shell when you emerge something. And there is a lot running through what we do not want to read. We will set up a filter so make portage save all messages with the status "warn" and "error". Status "error" means that there was an error when building a package and the message will contain what you need to know about that. Status "warn" means that there is something that a package wants you to do after is was installed. A typical warning comes from xorg-server:

Quote:
* You must rebuild all drivers if upgrading from xorg-server 1.X
* or earlier, because the ABI changed. If you cannot start X because
* of module version mismatch errors, this is your problem.

* You can generate a list of all installed packages in the x11-drivers
* category using this command:
* emerge portage-utils; qlist -I -C x11-drivers/


If you don't follow this you will wake up without keyboard and mouse after reboot. And for that reason we want portage to make this message available to us. OK, in this case a bad example because my script watches for updates on xorg-server and does this for you, but there is a lot of programs that need things to be done after updating them.

OK, let set it up:
Code:
# install elogv
emerge -av elogv
# tell portage what to show (log,info,warn,error) and what to save (warn,error)
echo "PORTAGE_ELOG_CLASSES=\"log warn error info qa\"
PORTAGE_ELOG_SYSTEM=\"echo:log,info,warn,error  save:warn,error\"" >> /etc/make.conf 



There are a few configuration examples if you don't want to use what I recommended. This is how it has to look like in /etc/make.conf
Code:
Example 1 (only warn and error will be saved) (what we set up in my example)
PORTAGE_ELOG_CLASSES="log warn error info qa"
PORTAGE_ELOG_SYSTEM="echo:log,info,warn,error  save:warn,error"

Example 2 (+info messages)
PORTAGE_ELOG_CLASSES="log warn error info qa"
PORTAGE_ELOG_SYSTEM="echo:log,info,warn,error save:info,warn,error"

Example 3 (from elogv documentation)
PORTAGE_ELOG_SYSTEM="save"
and at least one out of
PORTAGE_ELOG_CLASSES="warn error info log qa"


OK, elogv is installed now and from now on portage is saving elog messages when something is emerged. If there is now message after you emerged something (or after my script has run) don't worry, everything is OK. There were only emerges that do not need to be taken care of after installation.

To start elogv you have to be root or in the group portage (gpasswd -a ${user} portage). Now type "elogv".

If there are messages you can do the following:


layman
Layman is a tool to add remote overlays into your portage tree. Here (http://gpo.zugaina.org/) you can search what overlays are available and what kind of packages is inside them.

Code:
echo "app-portage/layman git subversion
dev-util/subversion -dso" >> /etc/portage/package.use
emerge -av layman
echo "source /var/lib/layman/make.conf" >> /etc/make.conf


Now you have to look into /etc/layman/layman.cfg to make sure you have a source configured following the new rules. It has to be "storage : /var/lib/layman" !!!
Code:
nano -w /etc/layman/layman.cfg

Now you can sync layman with "layman -S", see the overlays available with "layman -L", see what you added with "layman -l", add something with "layman -a foo" and see more with "layman --help"

cfg-update
cfg-update is the tool I use to update all config files marked automatic by portage. With "cfg-update -ua" (update automatic) I make sure that you only have to deal with config files where you changed something when you run "etc-update or "dispatch-conf" or cfg-update -u" after my script finished. cfg-update needs a diff tool. Gnome users like me become dev-util/meld installed with cfg-update because of their USE-Flag gnome. Others have to install and setup something else from the list.

Code:
emerge -av cfg-update
nano -w /etc/cfg-update.conf


As I told you, I have meld configured as MERGE_TOOL in /etc/cfg-update.conf. Here you can see what else you can install and configure. But you have to configure one! If you start cfg-update without parameter "cfg-update" it shows you the help.
Quote:
# +----------+
# | MERGETOOL \
# +------------+-------------------------------------------------------------+
# | The recommended tool for merging is xxdiff but you can also use other |
# | tools if you don't like xxdiff. The Supported tools are listed below: |
# +----------+-----+--------------------------+------------------------------+
# | xxdiff | GUI | KDE (or Gnome with QT) | |
# | kdiff3 | GUI | KDE (or Gnome with QT) | |
# | meld | GUI | Gnome (or KDE with GTK) | |
# | gtkdiff | GUI | Gnome (or KDE with GTK) | STAGE 3 not supported! |
# | gvimdiff | GUI | Gnome (or KDE with GTK) | STAGE 3 not supported! |
# | tkdiff | GUI | Gnome (or KDE with TK) | |
# | vimdiff | CLI | Systems without X | STAGE 3 not supported! |
# | sdiff | CLI | Systems without X | STAGE 3 not supported! |
# | imediff2 | CLI | Systems without X | STAGE 3 not supported! |
# +----------+-----+--------------------------+------------------------------+
MERGE_TOOL = /usr/bin/meld



OK, everything is set up now. What you have to do after my script ran will be described later.
Code:
BitKiller ~ # emerge -pv update

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] app-admin/update-2.1_rc3  USE="X daily -weekly" 0 kB [1]

Total: 1 package (1 reinstall), Size of downloads: 0 kB
Portage tree and overlays:
[0] /usr/portage
[1] /overlay
BitKiller ~ #


As you can see there is 3 USE-Flags. The USE-Flag X is managed by your profile and is meant to disable the dependency x11-misc/xdialog and its functionality so systems without graphical user interface can use this script as well.

Interesting for you are the USE-Flags "daily" and "weekly". I recomend and use "daily". OK, what happens, when you chose daily or weekly?

daily:
weekly:

I recomend setting up:
Code:
echo "app-admin/update daily" >> /etc/portage/package.use


My install script finds your local overlay be looking into /etc/make.conf. Therefore you can start the installer where ever you want. It created app-admin/update inside your local overlay, changes into this directoy, get latest-version.txt from my website, downloads latest version of app-admin/update, decompresses it, creates the manifest for you, installs autounmask, unmasks all dependencies for app-admin/update and installs app-admin/update.

Code:
wget http://www.felixpetzold.de/Gentoo/update/InstallUpdateScript
chmod +x InstallUpdateScript
./InstallUpdateScript
rm InstallUpdateScript


Now you have to set up your user name in /etc/conf.d/update
Code:
nano -w /etc/conf.d/update


Quote:
USER_NAME="felix

This is the user that gets a message on his Desktop when there was an error. I know that elogv is doing the same and will make the config file optional soon.

Now everything is installed. When root you can execute now the following commands

How does it work with cron and automatic and so on? Is there nothing I have to do?

And that is it. You only have to run 2 commands (elogv + cfg-update -u) after my script finished!

Sample run:
Code:
Update-Script v2.1 for Gentoo Linux by Felix Petzold
----------------------------------------------------
Syncing Portage, Eix & Layman.
Finished

Saving installed version-nr of firefox, thunderbird and xorg-server
Found www-client/firefox-3.6.8-r1
Found x11-base/xorg-server-1.8.2
Finished

Updating System.
Finished

Getting new version-nr of firefox, thunderbird and xorg-server
Found www-client/firefox-3.6.8-r1
Found x11-base/xorg-server-1.8.2
Finished

Checking version differences to react on updates
Finished

Running emerge --depclean.
Finished

Running lafilefixer --justfixit
Finished.

Running emerge @preserved-rebuild.
Finished

Running perl-cleaner --all
Finished.

Running revdep-rebuild.
Finished

Running cfg-update -ua
Finished

Running eclean packages.
Finished

Running eclean distfiles.
Finished

Exiting update script