#!/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. DNS 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 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 ${remote_dir} dir with local one (${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"