For those Gentoo users out there, you know how big a pain it can be to have to continually update a set of Gentoo systems. The following script assumes you have /usr/portage shared between all your Gentoo systems. It also requires that the system it is run from has SSH keys setup so it can connect to all the remote systems as root without requiring a password. Simply adjust the variables at the top of the script to your preferences. This script can be combined with the Ruby Email Script to keep logs of updates and errors. Be sure to check the emails daily for errors that may occur during the update.
#!/bin/sh # # Gentoo Update v1.0 # # Script to handle auto-updates on multiple Gentoo Linux systems. # -Be sure to set the LOCKFILE, SERVERS and LOGDIR variables at the top # -This script assumes that /usr/portage is shared via NFS (or some other # means) between all systems and is therefore only synced once. # -SSH keys must be setup so the server this script is running from can # automatically login to each of the servers in the list without # requiring a password # # Sumit Khanna <firstname.lastname@example.org> # http://penguindreams.org # # Free for noncommercial use # LOCKFILE=/var/run/gentoo-update.sh.pid SERVERS="raphael.turtles bebop.turtles donatello.turtles splinter.wireless" LOGDIR="/var/log/gentoo-update" DATE=`date +%Y%m%d_%H%M` LOG="$LOGDIR/update.log"; if [ -f "$LOCKFILE" ]; then echo "Can not Start. Update-all is running (`cat $LOCKFILE`)"; exit 2; fi echo $$ > $LOCKFILE echo "---$DATE---" > $LOG echo "Starting Update Process" >> $LOG emerge --sync &> $LOGDIR/sync.out if [ "$?" != 0 ]; then echo "Sync Failed!!!" >> $LOG tail $LOGDIR/sync.out >> $LOG 2>&1 cat $LOGDIR/update.log exit 1 fi for i in $SERVERS; do echo "Updating $i" >> $LOG ssh $i "emerge -uDN world" > $LOGDIR/$i.out 2>&1 CHECK=$? cat $LOGDIR/$i.out | grep ">>>" | grep merged | grep -v unmerged | sed 's/^>>>//' >> $LOG tail $LOGDIR/$i.out | grep IMPORTANT >> $LOG if [ "$CHECK" != 0 ]; then echo "Error:" >> $LOG tail -n 20 $LOGDIR/$i.out >> $LOG fi echo "Rebuilding $i" >> $LOG ssh $i "rm /root/.revdep-rebuild*.?_*" &> /dev/null ssh $i "revdep-rebuild" > $LOGDIR/$i.rebuild.out 2>&1 CHECK=$? cat $LOGDIR/$i.rebuild.out | grep ">>>" | grep merged | grep -v unmerged | sed 's/^>>>//' >> $LOG if [ "$CHECK" != 0 ]; then echo "Error:" >> $LOG tail $LOGDIR/$i.rebuild.out >> $LOG fi done cat $LOGDIR/update.log rm $LOCKFILE