#!/bin/bash

### Debug
## date | mailx -s "$0 is running" tillea@rki.de

# Andreas Tille, tille@debian.org, (c) 2001

# create partitial debian mirror using debmirror from Joey and rsync
# http://cvs.kitenet.net/joey-cvs/bin/debmirror
# DIST=testing
# see #281844
# DIST=sarge
DIST=testing

CONF=$(dirname $0)/mirror.conf
# echo $CONF
export http_proxy="$proxy"

if [ -f $CONF ] ; then
  source $CONF
fi

EXCLUDESTRING=""
INCLUDESTRING=""

for i in $EXCLUDE ; do
  EXCLUDESTRING="$EXCLUDESTRING|$i"
done

for i in $INCLUDE ; do
  INCLUDESTRING="$INCLUDESTRING|$i"
done

arch=amd64
debug="--debug"
debug="$*"
## defopt="$debug --arch=$arch --getcontents --host=$host --nosource"
## Schalte mal getcontents ab, weil's sowieso nicht immer funktioniert
## und hole dann per Hand an andere Stelle zum Platz sparen
# defopt="$debug --arch=$arch --host=$host --nosource"
defopt="$debug  --arch=$arch --host=$host --nosource"
## Bei http worde manchmal nichts geholt

# echo "--getcontents wieder mit reinnehmen, sobald verfuegbar."
set -x
defopt="-v --debug --method=http --proxy=$proxy $defopt --getcontents --allow-dist-rename"
# defopt="--method=http --proxy=$proxy $defopt"

## --passive ... siehe #281844
# defopt="--passive $defopt"

$debmirrorprog $destdir/debian $defopt --dist=$DIST --exclude="non-US/|disks-$arch/|security/|/project/$EXCLUDESTRING"
## echo $debmirrorprog $destdir/debian $defopt --dist=$DIST --exclude="non-US/|disks-$arch/|security/|/project/$EXCLUDESTRING" > /usr/local/sbin/zw

## In non-US/contrib ist gar nichts mehr ...
## $debmirrorprog $destdir/non-US $defopt --dist=$DIST -r $nonusdir -s non-US/main,non-US/contrib,non-US/non-free  --exclude="project/$EXCLUDESTRING"
## Und auch sonst non-US Schwachsinn - es kann per conf-File ausgeschaltet werden
if [ _"$nonusdir" != _"" ] ; then
   $debmirrorprog $destdir/non-US $defopt --dist=$DIST -r $nonusdir -s non-US/main,non-US/non-free  --exclude="project/$EXCLUDESTRING"
fi

## MPlayer

EXCLUDESTRING=""
for i in $MPLAYEREXCLUDE ; do
  EXCLUDESTRING="$EXCLUDESTRING|$i"
done

#debug="--debug --verbose"
defopt="$debug --arch=$arch --host=$mplayerhost --nosource"
defopt="--method=http --proxy=$proxy $defopt --getcontents"
# Die leere Zeichenkette als dir (-r) scheint ganz wichtig, sonst erzeugt debmirror eine
# Adresse der Art http://www.debian-multimedia.org//debian/dists/sid/Release.gpg
# was durch die zwei '//' zu Problemen fuehrt
$debmirrorprog $destdir/mplayer --ignore-missing-release $defopt -r '' $mplayerdir --dist=$mplayerdist -s main --exclude="/project/$EXCLUDESTRING" 2> /dev/null > /dev/null



exit 0

