#!/bin/sh # # Roman Bogorodskiy version=0.1 config_file="/usr/local/etc/fetch_delta.conf" #test -f ${config_file} && source ${config_file} SYS_FETCH=${SYS_FETCH:=/usr/bin/fetch} FETCH=${FETCH:=/usr/local/bin/wget} DELTUP=${DELTUP:=/usr/local/bin/deltup} #MPDIR=${TMPDIR:=/tmp} #xport TMPDIR=${TMPDIR} try_to_fetch_delta() { prefix=`echo $1|sed -e 's/[[:digit:]][[:print:]]*$//'` suffix=".`echo $1|sed -e 's/.*[.]//g'`" # if there are more than 1 file we get last 'cause # it's most likely it'll be the newest version you have old_file=`ls ${prefix}*${suffix} 2>/dev/null|tail -1` new_file=$1 if test \"${old_file}\" = \"${new_file}\"; then echo "I see (probably) a corrupted file ${old_file}!" return 1; fi if test -z ${old_file}; then echo "---> It seems there are no previous versions of ${new_file} here, fetching tarball"; return 1 else URL="http://linux01.gwdg.de/~nlissne/deltup.php?have=${old_file}&want=${new_file}&version=0.7" echo "---> Delta URL: ${URL}" echo "---> Fetching delta" rm -f ${old_file}-${new_file}.dtu* 2>&1 > /dev/null ${FETCH} ${URL} # check return status if test $? -ne 0 && test -f ${old_file}-${new_file}.dtu; then echo "---> Failed to download delta" return 1; else echo "---> Succeed, patching" ${DELTUP} -p ${old_file}-${new_file}.dtu if test ! -f ${new_file}; then echo "Patching failed (probalby the delta you want has not been generated by server yet)" return 1; fi fi return 0; fi } # command executed by `make fetch' should look like that: # ${FETCH_CMD} -S size_of_distfile url #f test $# -eq 3; then # try_to_fetch_delta `basename $2`; #elif test $# -eq 1; then # looks like `make makesum` or something like that -> we're going to download original tarball # because we don't want to break distinfo # echo "---> Falling back to downloading orignal tarball" # ${SYS_FETCH} $*; #else # echo "Something goes wrong. Dance around me!" # exit 1; #fi if test $2; then try_to_fetch_delta `basename $2`; else ${SYS_FETCH} $*; fi if test $? -eq 1; then echo "---> Falling back to downloading orignal tarball" ${SYS_FETCH} $*; fi