User:Bastien/Some-custom-gentoo-scripts

This page simply presents some simple scripts I use to manage my gentoo machines, that might be interesting for other users.

syncing gentoo between local machines
Since I have several gentoo machines, it would be a waste of bandwidth for everyone to let all of them sync the repo against the same gentoo mirrors in turn. Instead, one of the machine can be defined as a server -- the server would sync the repo against upstream mirrors -- then let the other machine on the same network fetch the upgrades from the local server. When using the default rsync method, a rsync daemon

syncing the gentoo repo automatically
It is simple to create a cronjob to run emerge --sync at a specific time. Yet, when a machine is not up all the time, or doesn't have access to internet all the time like a laptop, this setup can be quite unreliable, as cron or anacron normally don't care for the output of a command: if the machine is down a the time defined when the cronjob should start, then not online when anacron spawns the command,. I found a workaround with a script that actually run hourly:

This script reads the timestamp of local repo metadata file (.git when using git, replace it by metadata if using rsync), compares it with the actual time, and if the difference doesn't exceed 259200 seconds (72h - adapt as needed), it exits with 0, else, it sends the command "emerge --sync". if the command fails because there is no internet connection, it will try again every hour until the local repo are actually updated. The only downside of it is when the command fails for whatever reason (profile not set correctly, ):

notification when the repository has been updated
Cron doesn't normally know about the display and it cannot easily be tricked to send desktop notifications. Instead, a small utility script can be started in a dbus-aware environment (a desktop environment or a display manager). The principle behind the following scripts is also to use unix timestamps. The easier and more useful way is to compare the timestamp of the gentoo repo with the date of the last emerge command. A simple way to know when the last emerge command was run is to use portage to simply touch a file after each install:

Then, a simple script would be:

Start this script within a graphical environment: it sleeps most of the time, reads and compares the values every hour, and sends a notification if the gentoo repo is more recent than the last emerge command.

gentoo update
When using regular updates, I tend to always use the same commands. So I wrapped it all in a script that uses the package. First, an emerge --pretend command shows which packags will be installed - at this point, it is possible to exit the script, for example to edit some use flags -- then a menu offers a comfortable way to select the right options depending on right:

The script "gentoo_postupdate" is simple: