#!/bin/bash

# Load configuration file
if [ ! -f kp.cfg ]; then
    . /etc/kp.cfg
else
    . kp.cfg
fi

MB_SQL="SELECT hash.size, to_timestamp(hash.mtime)::date, filearr.path
        FROM hash, filearr
        WHERE filearr.id=hash.file_id
           AND (filearr.path LIKE '%rpm' OR filearr.path LIKE '%.iso' OR filearr.path LIKE '%.xml%')
           AND filearr.path NOT LIKE 'ensuse/%'
           AND array_length(mirrors,1) > 0;"

### AND filearr.path NOT LIKE 'repositories/home:%';\""

echo 'Getting the package list ...'
PGPASSWORD=$MB_PASSWD psql -U $MB_USER -h $MB_HOST -t -A -F ' ' mb_opensuse -c "$MB_SQL" > $DATA/mirror_brain.txt

# Wake up the rest of the process
if [ "$LOCK" = true ]; then
    :> lock-dir/kp.lock
fi
