* The one that syncs your portage tree
What it does?
This script is ideated for the ones that already have a gentoo computer/server at their home.
Usually /usr/portage directory is mounted through NFS to execute only one 'emerge --sync' and, by the effects of NFS mounting, this sync is automatically mirrored on other computers too.
This solution is quite good but I've had some problem in the past, furthermore when the 'other computer' is a laptop.
I prefer to sync that tree on my laptop in order to avoid problems that may happen if something goes wrong and you're not at your home.
Maybe a crash happens and you have your very old portage tree stored so you've to sync it.
Another thing I've experienced is when you forget to rebuild the kernel modules (provided by ebuilds). In these cases the system could hang on boot asking for drivers, or simply Xorg may not start at all. What if the driver is the wireless one? You'll probably have to attach your laptop to the router, download through normal eth cable and so on..
So I've written a small script that:
- Sync portage tree remotely
- Sync the remote portage tree locally
- Auto fetch module-rebuild packages (works only with portage v >=2.2)
- Update layman repositories
- Update eix cache and show diff
Every task could be performed either using eix or emerge.
These parameters can be easily configured by editing variables at the beginning of the script.
Little note
Using '-s' switch you can force the script to run an eix/emerge sync even if it's has been disabled by the settings.
External tools: portage rsync [eix] [layman]
Script code
- #!/bin/sh
- # A small script to sync remote portage tree with local one
- # Written by Fabiano 'elbryan' Francesconi
- # Please report any feedback/error/suggestion to fabiano 'dot' francesconi 'at' gmail 'dot' com
- # Changelog
- # v0.2-r3 17/09/09
- # - Now using trap to trap SIGINT and terminate the script
- # v0.2-r2 16/09/09
- # - Code improvement (thanks to drizztbsd & exg)
- # v0.2-r1 25/08/09
- # - Fixed code for using new eix commands
- # v0.2 - 06/07/09
- # - Refactored everything
- # - Now uses fucntions.sh and ewarn/einfo/eerror functions
- # - Improved output beautyness
- # - Minor bugs fix
- # v0.1 - 03/07/09
- # - added auto fetching options
- # - improved layman update command
- # you want to run a remote 'eix-sync' on remote_server?
- # yes = eix-sync
- # no = nothing
- # emerge = use emerge --sync
- run_remote_eix_sync="no"
- # remote server. Hostname or IP here.
- remote_server=""
- # remote directory. remember rsync syntax as trailing '/' at the end of the directory
- remote_dir="/usr/portage/"
- # remote username, probably you want to leave root here
- remote_username="root"
- # local directory where portage is placed
- local_dir="/usr/portage"
- # auto fetch module-rebuild packages
- # since rsync would delete/alterate your current /usr/portage/distfiles directory, you may want
- # this script to simply fetch your module-rebuild packages (useful when you have in there some important drivers - like wireless/ethernet ones -)
- # that will be unable to download if missing.
- # WARNING: You *MUST* have portage version 2.2 or major to make this to work
- auto_fetch_module_rebuild="no"
- # if you have layman just choose yes here
- update_layman="no"
- # if you want the script to update your portage cache
- update_eix_cache="yes"
- # ... and show the differences from the previous sync
- show_eix_diff="yes"
- # look for functions.sh
- # baselayout 2
- [ -r /lib/rc/sh/functions.sh ] && . /lib/rc/sh/functions.sh
- # baselayout 1
- [ -r /sbin/functions.sh ] && . /sbin/functions.sh
- # set trap for interrupting the script if SIGINT is received
- message="SIGINT received. Script halted."
- trap " trap sees INT; echo -e ${message}; exit 1" INT
- if [ "${1}" = "-s" ]; then
- if [ "${2}" = "emerge" ]; then
- run_remote_eix_sync="emerge"
- else
- run_remote_eix_sync="yes"
- fi
- fi
- ebegin "Checking tools"
- rsync_path=$(qfile -Ceq rsync)
- if [ -z "${rsync_path}" ]; then
- eerror "Unable to find rsync in your system. Aborting"
- exit -1
- fi
- eix_path=$(qfile -Ceq eix)
- if [ -z "${eix_path}" ]; then
- eerror "Unable to find eix in your system."
- ewarn "Disabling eix-driven options.."
- update_eix_cache="no"
- show_eix_diff="no"
- if [ ${run_remote_eix_sync} = "yes" ]; then
- ewarn "..and falling back to emerge --sync....."
- run_remote_eix_sync="emerge"
- fi
- fi
- eend $?
- if [ ${run_remote_eix_sync} = "yes" ]; then
- ebegin "Running remote eix-sync.."
- ssh ${remote_username}@${remote_server} 'eix-sync -q'
- eend $?
- elif [ ${run_remote_eix_sync} = "emerge" ]; then
- ebegin "Running remote emerge --sync.."
- ssh ${remote_username}@${remote_server} 'emerge --sync -q'
- eend $?
- fi
- ebegin "Syncing ${remote_server}:${remote_dir} with local dir (${local_dir}).."
- rsync -raz -e "ssh -l ${remote_username}" --delete "${remote_server}:${remote_dir}" "${local_dir}"
- eend $?
- if [ ${auto_fetch_module_rebuild} = "yes" ]; then
- ebegin "Auto fetching module-rebuild packages.."
- emerge -Fq @module-rebuild > /dev/null
- eend $?
- fi
- if [ ${update_layman} = "yes" ]; then
- ebegin "Updating layman repositories.."
- layman -Sq > /dev/null
- eend $?
- fi
- if [ ${update_eix_cache} = "yes" ]; then
- ebegin "Copying old eix cache to eix.previous.."
- cp /var/cache/eix /var/cache/eix.previous
- eend $?
- ebegin "Updating local eix cache.."
- eix-update -q
- eend $?
- fi
- if [ ${show_eix_diff} = "yes" ]; then
- einfo "Showing eix differences.."
- eix-diff /var/cache/eix.previous
- fi
- einfo "Script Completed"
Or you can download the script file HERE
Issue that you may encounter
An ssh connection needs to be enstablished through the systems involved with the operations.
It's strongly encouraged (by me) to use private/public RSA authentication in order to avoid explicit login (this is mandatory if you're going to run this script through cron).
