#!/bin/sh
##
##  spegla-mirror -- Spegla Mirror Manager
##  Copyright (c) 2000-2003 Ralf S. Engelschall <rse@engelschall.com>
##

BINDIR="@l_prefix@/bin"
ETCDIR="@l_prefix@/etc/spegla"
VARDIR="@l_prefix@/var/spegla"
PKGDIR="@l_prefix@/var/spegla/pkg"

mirror () {
    ( pkg=$1
      echo "spegla-mirror: spawning mirror for <$pkg>" >>$VARDIR/spegla-mirror.log
      $BINDIR/spegla \
          --section=common --configfile=$ETCDIR/spegla.conf \
          --section=$pkg   --configfile=$ETCDIR/spegla.conf \
          --lockfile=$PKGDIR/$pkg.lck \
          --logfile=$PKGDIR/$pkg.log \
          >>$VARDIR/spegla-mirror.log 2>&1 
      echo "spegla-mirror: terminated mirror for <$pkg>" >>$VARDIR/spegla-mirror.log
    ) >/dev/null 2>&1 &
}

if [ $# -gt 0 ]; then
    for pkg in $*; do
        mirror $pkg
    done
else
    for pkg in `egrep '^\[[a-zA-Z].*\]' $ETCDIR/spegla.conf |\
                grep -v common | sed -e 's/\[\(.*\)\]/\1/'`; do
        mirror $pkg
    done
fi  

