#!/bin/sh
# Mirrorea debian
#
# Version 1.5 - 06.feb.2006
#       * Eliminado repositorio non-US
#       * Control de sincronizacion y reintentos
# Version  1.0 - 17.ene.2005
#       * Primer version

# 0 corre en modo consola con feedback a stdout
# 1 corre en modo batch con feedback a /var/log/syslog
SILENT=0

# Cantidad de reintentos en sincronizar antes de abortar
REINTENTOS=10

DEBMIRROR=/usr/bin/debmirror

function bajo_mirror {
        if [ $SILENT -eq 1 ]; then
                /usr/bin/logger "Inicio actualizacion mirror $DISTRO"
                PROGRESO=""
        else
                echo Distro:     $DISTRO
                echo Section:    $SECTION
                echo Server:     $HOST
                echo Mirror en:  $LOCATION
                PROGRESO="-p -v"
        fi
        BUCLES=1
        run_debmirror
        if [ $SILENT -eq 1 ]; then
                /usr/bin/logger "Final actualizacion mirror $DISTRO"
        else
                echo "========================================================================================"
        fi
}

function run_debmirror {
        if [ $BUCLES -gt $REINTENTOS ]; then return; fi
        # TEST="--dry-run" --md5sums
#        $DEBMIRROR $TEST $PROGRESO -h $HOST -d $DISTRO $REPOSIT --nosource --progress -s $SECTION $LOCATION -a i386,amd64 --ignore-release-gpg --method http --pdiff=none
#        $DEBMIRROR $TEST $PROGRESO -h $HOST -d $DISTRO $REPOSIT --nosource -s $SECTION $LOCATION -a i386,amd64 --ignore-release-gpg --method http --pdiff=none --rsync-options="-tlO" --ignore-small-errors
        $DEBMIRROR $TEST $PROGRESO -h $HOST -d $DISTRO $REPOSIT --nosource -s $SECTION $LOCATION -a i386,amd64 --ignore-release-gpg --method http --pdiff=none
        if [ $? -ne 0 ]; then
                if [ $SILENT -eq 1 ]; then
                        /usr/bin/logger "Error al sincronizar repositorio, intento $BUCLES"
                else
                        echo "Error al sincronizar repositorio, intento $BUCLES"
                fi
                BUCLES=$(($BUCLES+1))
                run_debmirror
        fi
}


DISTRO=etch,etch-proposed-updates,\
lenny,lenny-proposed-updates,\
squeeze,squeeze-proposed-updates
SECTION=main,contrib,non-free,main/debian-installer,main/installer-i386,main/installer-amd64
LOCATION=/home/ftp/debian/
HOST=ftp.debian.org
REPOSIT="-r debian"
bajo_mirror


DISTRO=etch/volatile,etch-proposed-updates/volatile,\
lenny/volatile,lenny-proposed-updates/volatile,\
squeeze/volatile,squeeze-proposed-updates/volatile,
SECTION=main,contrib,non-free
LOCATION=/home/ftp/debian-volatile/
HOST=volatile.debian.org
REPOSIT="-r debian-volatile"
bajo_mirror

DISTRO=etch/updates,lenny/updates,squeeze/updates
SECTION=main,contrib,non-free
LOCATION=/home/ftp/debian-security
HOST=security.debian.org
REPOSIT="-r debian-security"
bajo_mirror

# Para hacer una replica de otro repositorio, agregar bloques como el siguiente
#
#DISTRO=etch
#SECTION=main,contrib,non-free
#LOCATION=/data/debmirror
#HOST=ftp.br.debian.org
#REPOSIT="-r /debian-non-US"
#bajo_mirror

exit 0

