--- emerge-webrsync.orig Mon Aug 2 19:46:38 2004 +++ emerge-webrsync.orig Tue Aug 3 02:09:57 2004 @@ -7,21 +7,27 @@ GENTOO_MIRRORS="$(/usr/lib/portage/bin/portageq gentoo_mirrors)" PORTDIR="$(/usr/lib/portage/bin/portageq portdir)" -syncpath="/var/tmp/emerge-webrsync" +FETCHCOMMAND="$(/usr/lib/portage/bin/portageq envvar FETCHCOMMAND)" +USERLAND="$(/usr/lib/portage/bin/portageq envvar USERLAND)" +DISTDIR="/var/tmp/emerge-webrsync" -if [ ! -d $syncpath ] ; then - mkdir -p $syncpath +if [ ! -d $DISTDIR ] ; then + mkdir -p $DISTDIR fi -cd $syncpath - found=0 attempts=0 download=1 if [ "$1" == "-v" ] ; then wgetops= else - wgetops=-q + #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 [ "$1" == "-n" ] ; then @@ -29,11 +35,12 @@ fi sync_local() { + cd $DISTDIR echo Syncing local tree... - tar jxf $file - rm -f $file + tar jxf $FILE + rm -f $FILE # Make sure user and group file ownership is root - chown -R root:root portage + chown -R 0:0 portage cd portage rsync -av --progress --stats --delete --delete-after \ --exclude='distfiles/*' --exclude='packages/*' . ${PORTDIR%%/} @@ -45,22 +52,30 @@ while (( $attempts < 40 )) ; do - day=`date -d "-$attempts day" +"%d"` - month=`date -d "-$attempts day" +"%m"` - year=`date -d "-$attempts day" +"%Y"` + #this too, sucks. it works in the interim though. + if [ "$USERLAND" == "BSD" ] ; then + daysbefore=$(expr $(date +"%s") - 86400 \* $attempts) + day=$(date -r $daysbefore +"%d") + month=$(date -r $daysbefore +"%m") + year=$(date -r $daysbefore +"%Y") + else + day=$(date -d "-$attempts day" +"%d") + month=$(date -d "-$attempts day" +"%m") + year=$(date -d "-$attempts day" +"%Y") + fi - file="portage-${year}${month}${day}.tar.bz2" + FILE="portage-${year}${month}${day}.tar.bz2" - if [ -f $file ] && [ $download == 0 ] ; then + if [ -f $DISTDIR/$FILE ] && [ $download == 0 ] ; then sync_local exit 0 fi for i in $GENTOO_MIRRORS ; do - url="${i}/snapshots/$file" - rm -f $file + URI="${i}/snapshots/$FILE" + rm -f $DISTDIR/$FILE - if (wget $wgetops $url) && [ -s $file ] ; then + if (eval "$FETCHCOMMAND $wgetops") && [ -s $DISTDIR/$FILE ] ; then sync_local echo echo " *** Completed websync, please now perform a normal rsync if possible."