TIP automatically update portage
From Gentoo Linux Wiki
| Terminals / Shells • Network • X Window System • Portage • System • Filesystems • Kernel • Other |
Contents |
[edit] Introduction
This TIP will introduce a short script that can do the following things for you:
- Update your portage tree using 'emerge --sync'
- Clean out distfiles that have not recently been used
- Send you a mail about newly available package-updates concerning your system
The script is intended to be run on a regular basis (eg weekly) by your cron-daemon.
So, you won't have to run 'emerge --sync' by hand, wait till it's finished, type 'emerge -avuDN world', wait for the dependencies to be calculated, review the list of packages and after this start the merge or even decide you don't see any required updates. Instead you will receive a mail, including all revelant news, and can immediately start the merge or decide to update next week.
Also your portage tree will always be up-to-date and distfiles you haven't recently needed are automatically deleted.
[edit] Warning
This article details how to get notifications of updates automatically but does not actually perform the updates. You should not update packages automatically by cronjob. The main reason for this is that if, for example, PAM is updated and requires configuration updates, but they aren't performed correctly, you could easily be locked out of all logins to your system. You have been warned!
[edit] Requirements
All you will need is:
- A cron-daemon
- An implementation of the mail program, eg nail, configured and capable of sending mailing
[edit] Installation
[edit] Get the script
First become root and copy/paste the script to your system:
|
| File: pretend-system-update.sh |
#!/bin/bash
# Files in /usr/portage/distfiles that have not been useful since DISTFILES_MAX_AGE days will be deleted
DISTFILES_MAX_AGE="7"
# Recipient of system-software-update-report-mails ;) (can be any valid mail address)
MAIL_TO="root"
# The text you would like to see as the mail's subject
MAIL_SUBJECT="Weekly system software update report for $(hostname -f) and the week of $(date '+%B %d')"
# If you want the list of packages to be encased in lines set this to '0', otherwise to your favorite number
SHOW_SPLITTERS=-1
# In case you want to see all the USE flags this is '0' for you, otherwise any number
SHOW_USE_FLAGS=-1
(echo -e "This is the pretend-system-update script on $(hostname -f); $(date).\n"
echo -n "Updating portage tree ... "
emerge --sync &> /dev/null && echo "done" || echo "failed"
cd /usr/portage/distfiles
echo -n "Trashing out-dated distfiles ... $(du -sch dummy_file $(find -atime +${DISTFILES_MAX_AGE} -print | grep -vx ".") 2>&1 | tail -n 1 | sed -r 's/\s*total//g') to be deleted ... "
find -atime +${DISTFILES_MAX_AGE} -delete && echo "done" || echo "failed"
echo -e "\nThe script does _not_ install any packages; it just informs about available updates:"
test ${SHOW_SPLITTERS} -eq 0 && echo -e "=======================================================================\n" || echo
test ${SHOW_USE_FLAGS} -eq 0 && emerge -pvuDNq world || emerge -puDNq world; SUCCESS=$?
test ${SHOW_SPLITTERS} -eq 0 && echo -e "\n======================================================================="
if [ ${SUCCESS} -eq 0 ]; then
echo -e "\nTo install these package updates just type 'emerge -uDN world'.\n\n"
else
echo -e "\nI'm sorry, something went wrong while calculating dependencies; propably some required packages are masked. You'll have to fix it manually. Please see http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=3&chap=3#doc_chap2 if you don't yet know how to handle this.\n\n"
fi
echo "Love & Kisses - Your pretend-system-update script") | mail -s "${MAIL_SUBJECT}" "${MAIL_TO}"
|
Now change the variables until you like them ;)
- All files in /usr/portage/distfiles that have not been accessed for $DISTFILES_MAX_AGE days will be cleaned-out (caused by the way find works this is actually $DISTFILE_MAX_AGE + 1 days)
- $MAIL_TO can be set to a system account that is mapped by your mail-system or to your mail-address eg 'info@moes-taverne.sf'
Next review the permissions set on the file:
| ||
|
After that 'ls -l' should look something like this:
| Code: Checking permissions of /usr/local/bin/pretend-system-update.sh |
-rwxr-x--- 1 root cron 827 2007-03-23 02:50 /usr/local/bin/pretend-system-update.sh |
[edit] Add the cronjob
To add a cronjob running the script on a regular basis run 'crontab -e' and append the following line:
|
| Code: Add this to root's crontab |
@weekly /usr/local/bin/pretend-system-update.sh > /dev/null |
[edit] Usage
So, now your system will keep you informed about fresh packages :) To see if it works you can invoke the script manually, by typing:
|
