#! /bin/sh

# Thomas Lange, lange@informatik.uni-koeln.de, (c) 2001-2018

# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
update_from() {

    # update local mirror from a host
    host=$1
    shift
    defopt="--keyring /usr/share/keyrings/debian-archive-keyring.gpg --method=http --rsync-extra=none --diff=none $allopt --host=$host --dist=$dist $sect"

    echo "------------------ create mirror for debian ------------------"
    debmirror $excl $destdir/debian $defopt $*
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# main program
#
# here you have to adjust the hostnames of the mirror and the names of the distributions

# excluding dbg_ packages saves a lot of disk space. About 33G for squeeze,wheezy in amd64,i386
excl="--exclude=-dbg_ --exclude=debian-installer-netboot-images --include=libc6-dbg"

debug="$@"
arch=amd64
dist=bullseye,bullseye-backports

destdir=/files/scratch/debmirror
sect="--section main,contrib,non-free"
allopt="$debug --state-cache-days=100 --ignore-missing-release --ignore-release-gpg --passive --nosource --arch=$arch"

# first sync from a mirror near to you
#update_from ftp.uni-koeln.de $*
# If this mirror isn't always up to date, sync again from an official mirror

# sync from an official mirror
update_from deb.debian.org --getcontents $*

# even one should not mirror the security site, but I will do it.
echo "------------------ create mirror for debian-security ------------------"
debmirror --keyring /usr/share/keyrings/debian-archive-keyring.gpg --method=http $excl $destdir/debian-security $allopt --host=deb.debian.org -r debian-security $sect -d bullseye-security $*
