#!/bin/sh
#author: igi
#date: 2012-03-28
NAME="debian"
SYNC_FILES="$NAME"_files
#TO="/tmp/$NAME"
TO="./$NAME"
FROM="archive.debian.org::debian-archive/debian"
#FROM="debian.ethz.ch::debian-archive/debian"
#FROM="mirror.1und1.de::debian-archive/debian"
#FROM="debian.koyanet.lv::debian-archive/debian"
#RUNDIR="/tmp/"
RUNDIR="./"
ARCH_EXCLUDE="alpha hppa hurd-i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390 s390x sparc ppc64el"
for ARCH in $ARCH_EXCLUDE; do
EXCLUDE=$EXCLUDE"\
--exclude binary-$ARCH/ \
--exclude *_$ARCH.deb \
--exclude *_$ARCH.udeb \
--exclude installer-$ARCH/ \
--exclude Contents-$ARCH* "
done
#dists='lenny etch'
dists='wheezy jessie'
for dist in $dists; do
DIST_INCLUDE=${DIST_INCLUDE}"\
--include /dists/$dist/ \
--include /dists/$dist/contrib/ \
--include /dists/$dist/main/ \
--include /dists/$dist/non-free/ "
DIST_EXCLUDE="${DIST_EXCLUDE}\
--exclude /dists/$dist/* "
done
#sync index files
rsync --progress -av \
--include 'Packages.gz' \
--include 'Sources.gz' \
$DIST_INCLUDE \
--include '/dists/' \
--exclude '/*' \
--exclude '/dists/*' \
$DIST_EXCLUDE \
--exclude 'i18n' \
--exclude 'installer-amd64' \
--exclude 'installer-i386' \
--exclude 'installer-armel' \
--exclude 'installer-arm64' \
--exclude 'installer-armhf' \
--exclude 'installer-ppc64el' \
--exclude 'Release' \
--exclude '*.bz2' \
$EXCLUDE \
"$FROM/" "$TO/"
rm -rf "$RUNDIR"/"$SYNC_FILES"
find "$TO/dists/" -name 'Packages.gz' -exec zgrep 'Filename: ' {} + | awk '{print $2}' >"$RUNDIR"/"$SYNC_FILES"
find "$TO/dists/" -name 'Sources.gz' -exec zcat {} + | awk '/Package:/{dir="";delete files;next};/Directory:/{dir=$2;next};/Files:/{pass=1;next}; pass && /^ / {files[NR]=$NF}; length(files) && dir && / /{for(i in files) print dir"/"files[i];delete files}; /^[^ ]/{pass=0;next};' >>"$RUNDIR"/"$SYNC_FILES"
#first stage
rsync --progress -v --recursive --times --links --hard-links \
--files-from="$RUNDIR"/"$SYNC_FILES" \
"$FROM/" "$TO/"
#second stage
rsync --progress -v --recursive --times --links --hard-links \
$DIST_INCLUDE \
--exclude '/dists/*' \
$EXCLUDE \
--exclude '/pool/' \
"$FROM/" "$TO/"