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. 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.

notification when the repository has been updated
cron doesn't know about the display or dbus environment variables and it cannot easily be tricked to send desktop notification. Instead, a small utility script can be started in a dbus-aware environment (a desktop environment or a display manager). The principle would also be to use unix timestamp: at best, it would be useful to compare the timestamp of the gentoo repo with the date of the last emerge command. A simple way to implement this is to use portage bashrc to simply touch a file after each install: