#!/bin/sh -efu

. girar-sh-functions

usage()
{
	echo >&2 "$PROG: $*"
	echo >&2 "usage: $PROG <source package name> <binary package repository name>"
	exit 1
}

[ "$#" -ge 2 ] ||
	usage 'Not enough arguments.'
[ "$#" -le 2 ] ||
	usage 'Too many arguments.'

package="$1"; shift
repository="$1"; shift

# Returns:
# 0 - $package exists in $repository;
# 1 - otherwise.

[ -n "${GIRAR_USER-}" ] ||
	fatal 'GIRAR_USER undefined'

repository="$(girar-normalize-repo-name "$repository")"

conf="$GIRAR_REPO_CONF_DIR/$repository"
if [ -s "$conf" ]; then
	. "$conf"
fi

[ -d "${GIRAR_REPO_DIR-}" ] ||
	fatal 'GIRAR_REPO_DIR is either undefined or invalid'

[ -n "$(printf %s "$package" |join -j1 -o1.1 - $GIRAR_REPO_DIR/files/list/src.list)" ]
