Gentoo Linux Cron Update
Autor: Michael Panhorst
Oryginalny post:
http://forums.gentoo.org/viewtopic.php? ... 52#1304452
Wymagania: mailx, esearch, gentoolkit
Sposób instalacji: Najprostszy - umieszczenie skryptu w katalogu /etc/cron.weekly, inny - umieszczenie w crontabie.
Opis: Skrypt służy do automatycznego synchronizowania komputera(zalecane raz na tydzień - chodzi głównie o obciążenie serwerów rsync)
Co robi skrypt:
1. emerge sync
2. fixpackages, jeśli trzeba
3. Sprawdzenie GLSA
4. Jeśli wystąpiły błędy przy emerge sync albo są nowe GLSA, skrypt wysyła email z informacją
5. Sprawdzenie czy są nowe wersje (emerge system or emerge world)
6. Paczkowanie nowych wersji jeśli spełnione są zależności(emerge -B)
7. Wysłanie emaila (jeśli są pakiety do zaktualizowania), a także informacji w jaki sposób tego dokonać (używając juz skompilowanych paczek - emerge -avK)
Code: Select all
#!/bin/bash
#
#
# glcu - gentoo linux cron update
# script for keeping your Gentoo linux up to date
#
# Version 0.65 - written by Michael Panhorst - Michael [at] untiefe [dot] de
#
# put this script in the /etc/cron.weekly directory
# You need to have mailx, esearch and gentoolkit emerged
# Set your eMail address first:
EMAILADRESS=root
# set if you want to test (and build) emerge 'system' or 'world'
UPDATE=system
################################################################
# You shouldn't need to change anything below this line
PKGDIR="/usr/portage/packages"
source /etc/make.conf # in case you set PKGDIR different
SUBJECT="glcu: New ebuilds for emerge $UPDATE on $HOSTNAME"
FS=""
EXTRA=""
# 1. emerge sync ############## (sync first) ####################
emerge sync 2>/tmp/emergesync.$$
# and run fixpackages (if needed)
grep "Skipping packages. Run 'fixpackages' or set it in FEATURES" /tmp/emergesync.$$
if [ $? == 0 ]
then
echo "" >>/tmp/ecdep.$$
echo "Running fixpackages" >>/tmp/ecdep.$$
echo "" >>/tmp/ecdep.$$
fixpackages 2>>/tmp/ecdep.$$
echo "" >>/tmp/ecdep.$$
fi
# 2. update database for esearch ################################
eupdatedb 2>>/tmp/emergesync.$$
# 3. glsa-check - check for security updates ####################
glsa-check -l -n|grep " \[N\] " >/tmp/eupdate.$$
if [ $? == 0 ]
then
echo "" >>/tmp/emergesync.$$
echo "----------------------------------------------------------------------" >>/tmp/emergesync.$$
echo "Important Security updates for $HOSTNAME:" >>/tmp/emergesync.$$
echo "" >>/tmp/emergesync.$$
cat /tmp/eupdate.$$ >> /tmp/emergesync.$$
echo "" >>/tmp/emergesync.$$
echo "" >>/tmp/emergesync.$$
echo "*** Run 'glsa-check --fix new' to auto-apply all security updates" >>/tmp/emergesync.$$
echo " ====================" >>/tmp/emergesync.$$
echo "" >>/tmp/emergesync.$$
echo "----------------------------------------------------------------------" >>/tmp/emergesync.$$
FS="- SECURITY UPDATES!"
fi
# only send a mail if errors ocurred
if [ -s /tmp/emergesync.$$ ]
then
if [ -s /tmp/ecdep.$$ ]
then
cat /tmp/ecdep.$$ >> /tmp/emergesync.$$
fi
cat /tmp/emergesync.$$ | mail -s "glcu($HOSTNAME): emerge sync $FS" $EMAILADRESS
fi
# 4. emerge -pv system/world (check for needed/new ebuilds) ###
emerge --pretend --deep $UPDATE > /tmp/eupdate.$$ 2>&1
# prebuild (emerge --buildpkgonly) all needed packages
grep ebuild /tmp/eupdate.$$
if [ $? == 0 ]
then
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" >> /tmp/ecdep.$$
echo "List of new Packages:" > /tmp/ecdep.$$
echo "---------------------" >> /tmp/ecdep.$$
grep ebuild /tmp/eupdate.$$ >> /tmp/ecdep.$$
echo "---------------------------------------------------------------------" >> /tmp/ecdep.$$
for package in `cat /tmp/eupdate.$$ | grep ebuild | cut -f 2- -d "/" | cut -f 1 -d " "` ;
do
if [ ! -f $PKGDIR/All/$package.tbz2 ]
then
echo "" >> /tmp/ecdep.$$
echo "Building binary package for $package :" >> /tmp/ecdep.$$
emerge --pretend --buildpkgonly --oneshot =$package > /tmp/eupdate.$$
if [ ` grep -c ebuild /tmp/eupdate.$$ ` == 1 ]
then
nice -n +19 emerge --buildpkgonly --oneshot =$package 2>> /tmp/ecdep.$$
if [ $? == 0 ]
then
PACKAGES="$PACKAGES =$package"
else
echo "" >> /tmp/ecdep.$$
echo " *** Error while building $package!" >> /tmp/ecdep.$$
SUBJECT="glcu: DEPENDENCY PROBLEM, COULDN'T PREBUILD ALL PACKAGES ON $HOSTNAME"
DEP=1
fi
else
echo " *** Dependencies for $package not met." >> /tmp/ecdep.$$
echo " *** Cannot prebuilt $package!" >> /tmp/ecdep.$$
SUBJECT="glcu: DEPENDENCY PROBLEM, COULDN'T PREBUILD ALL PACKAGES ON $HOSTNAME"
DEP=1
fi
fi
done
echo "New packages for 'emerge $UPDATE'!" > /tmp/glcu.$$
echo " =============" >> /tmp/glcu.$$
echo "" >> /tmp/glcu.$$
if [ -n "$PACKAGES" ]
then
echo "To update your gentoo linux, execute:" >> /tmp/glcu.$$
echo "" >> /tmp/glcu.$$
echo " emerge -avK $PACKAGES" >> /tmp/glcu.$$
echo "" >> /tmp/glcu.$$
EXTRA=further
SEND=1
fi
if [ $DEP ]
then
echo "check for $EXTRA packages with:" >> /tmp/glcu.$$
echo "" >> /tmp/glcu.$$
echo " emerge -av $UPDATE" >> /tmp/glcu.$$
echo "" >> /tmp/glcu.$$
SEND=1
fi
cat /tmp/ecdep.$$ >> /tmp/glcu.$$
# send mail, how to update the system
if [ $SEND ]
then
cat /tmp/glcu.$$ | mail -s "$SUBJECT" $EMAILADRESS
fi
# rm all used files
rm /tmp/glcu.$$
fi
rm /tmp/emergesync.$$ /tmp/eupdate.$$ /tmp/ecdep.$$