#!/bin/bash # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id: /var/cvsroot/gentoo-src/portage/bin/Attic/emerge-webrsync,v 1.8.2.4 2005/02/26 11:22:38 carpaski Exp $ # Author: Karl Trygve Kalleberg # Rewritten from the old, Perl-based emerge-webrsync script # Author: Robin Hugh Johnson # Converted to use -latest symlink echo -n "Getting settings... " GENTOO_MIRRORS="${GENTOO_MIRRORS} $(/usr/lib/portage/bin/portageq gentoo_mirrors)" PORTDIR="$(/usr/lib/portage/bin/portageq portdir)" FETCHCOMMAND="$(/usr/lib/portage/bin/portageq envvar FETCHCOMMAND)" USERLAND="$(/usr/lib/portage/bin/portageq envvar USERLAND)" DISTDIR="$(/usr/lib/portage/bin/portageq envvar PORTAGE_TMPDIR)/emerge-webrsync" RSYNC_EXCLUDEFROM="$(/usr/lib/portage/bin/portageq envvar RSYNC_EXCLUDEFROM)" echo "done" if [ ! -d $DISTDIR ] ; then mkdir -p $DISTDIR fi cd "$DISTDIR" found=0 if [ "$1" == "-v" ] ; then wgetops= else #this sucks. probably better to do 1> /dev/null #that said, waiting on the refactoring. if [ "${FETCHCOMMAND/wget}" != "${FETCHCOMMAND}" ]; then wgetops="-q" elif [ "${FETCHCOMMAND/curl}" != "${FETCHCOMMAND}" ]; then wgetops="-s -f" fi fi if type -p md5sum > /dev/null; then md5_com='md5sum -c "${FILE}.md5sum" >/dev/null 2>/dev/null' elif type -p md5 > /dev/null; then md5_com='[ "$(md5 -q ${FILE})" == "$(cut -d \ -f 1 ${FILE}.md5sum)" ]' else echo "warning, unable to do md5 verification of the snapshot!" 1>&2 echo "no suitable md5/md5sum binary was found!" 1>&2 md5_com='true' fi sync_local() { #echo "Syncing local tree..." echo -n "Untarring ${FILE}... " if ! tar jxf ${FILE} --owner 0 --group 0 ; then echo "failed" echo "Tar failed to extract the image. Please review the output." 1>&2 echo "Executed command: tar jxf $FILE" 1>&2 exit 1 fi echo "done" # Make sure user and group file ownership is root # we avoid this using --owner/--group in tar #chown -R 0:0 portage if [ -n "${RSYNC_EXCLUDEFROM}" -a -s "${RSYNC_EXCLUDEFROM}" ]; then RSYNC_EXCLUDEFROM="--exclude-from ${RSYNC_EXCLUDEFROM}" else RSYNC_EXCLUDEFROM="" fi rsync -av --progress --stats --delete \ --delete-after ${RSYNC_EXCLUDEFROM} \ --exclude='/distfiles' --exclude='/packages' \ --exclude='/local' \ portage/ ${PORTDIR%%/} echo -n " Cleaning up tarball contents... " rm -rf portage && echo "done" || echo "failed" echo "Transferring metadata/cache..." emerge metadata && echo "done" || echo "failed" echo "Cleaning up ${FILE}..." rm $FILE && echo "done" || echo "failed" } echo -n "Fetching most recent checksum... " FILE_CURRENT="portage-latest.tar.bz2" MD5_CURRENT="${FILE_CURRENT}.md5sum" got_md5=0 for i in $GENTOO_MIRRORS ; do URI="${i}/snapshots/${MD5_CURRENT}" if (eval "$FETCHCOMMAND $wgetops") && [ -s "${MD5_CURRENT}" ]; then got_md5=1 echo "done" break fi done if (($got_md5 == 0 )); then echo "failed" echo " === No checksum present on the mirror. Fatal error." exit 1 fi # ok, so we got portage-latest.tar.bz2.md5sum MD5STR="$(<${MD5_CURRENT})" FILE="${MD5STR//* }" DATE="${FILE/portage-}" DATE="${DATE%%.tar.bz2}" # if ${FILE}.md5sum already exists # this might be case where the snapshot has been altered # in which case we should force a download # so we just overwrite the md5sum file to ensure it. mv -f "${MD5_CURRENT}" "${FILE}.md5sum" echo -n "Checking for existing ${FILE}... " if [ -s "${FILE}" ]; then echo "found" echo -n "Checking checksum on existing ${FILE}... " if eval "$md5_com"; then echo "valid" sync_local echo echo " === Completed websync" echo " === Update is current as of: ${DATE}" echo exit 0 else echo "invalid" rm $FILE fi else echo "not found" fi for i in $GENTOO_MIRRORS ; do echo -n "Attempting to fetch ${FILE}... " URI="${i}/snapshots/$FILE" rm -f "$FILE" if (eval "$FETCHCOMMAND $wgetops") && [ -s "$FILE" ]; then echo "done" echo -n "Checking checksum on ${FILE}... " if ! eval "$md5_com"; then echo "invalid ($URI)" rm ${FILE} continue else echo "valid" sync_local echo echo " === Completed websync, please now perform a normal rsync if possible." echo " === Update is current as of: ${DATE}" echo exit 0 fi else echo "failed" fi done rm -rf "${DISTDIR}/portage" exit 1