#!/bin/bash
[ -e /etc/autodist/config ] || {
   echo "ERROR: missing configuration file /etc/autodist/config."
   exit 1
}

. /etc/autodist/config

shopt -s nocaseglob
checkpkg=$1

if [ ! "$checkpkg" ]; then
   echo "Usage:
$0 query"
   exit 1
fi

[ "$LOCAL_REPS_BASE_DIR" -a -e "$LOCAL_REPS_BASE_DIR" ] || {
   echo "ERROR: LOCAL_REPS_BASE_DIR needs to be defined and local repositories to exists."
   exit 1
}

echo "=== distromatic sources: ==="
head -n2 ${LOCAL_REPS_BASE_DIR}/distromatic/base/sources
grep -i $checkpkg ${LOCAL_REPS_BASE_DIR}/distromatic/base/sources
#tail -n+2 ${PREFIX}/distromatic/base/deps-* | grep -i $checkpkg 
echo -e "\n=== distdb: ==="
grep -i $checkpkg ${LOCAL_REPS_BASE_DIR}/base/distdb
echo -e "\n=== legacy: ==="
grep -i $checkpkg ${LOCAL_REPS_BASE_DIR}/base/legacy
for repo in base devel-makedist devel-autodist devel-misc devel-contrib devel-future; do
   echo -e "\n=== ${repo}: ==="
   ls ${LOCAL_REPS_BASE_DIR}/${repo}/SRPMS.base/*$checkpkg* 2>/dev/null
   ls ${LOCAL_REPS_BASE_DIR}/${repo}/RPMS.*/*$checkpkg* 2>/dev/null
done
