#!/bin/bash -e
# $Id: sisyphus_add_new,v 1.5 2004/06/24 15:25:34 ldv Exp $

. /etc/sisyphus/functions
. /etc/sisyphus/config

lock_incoming()
{
	cd "$START_DIR"
	chmod g-rw RPMS SRPMS
}

unlock_incoming()
{
	cd "$START_DIR"
	chmod g+rw RPMS SRPMS
}

exit_handler()
{
	local rc=$?
	trap - EXIT
	unlock_incoming
	exit $rc
}

lock_incoming
trap exit_handler EXIT HUP INT PIPE TERM QUIT

if ! cleanup_incoming RPMS/*.rpm SRPMS/*.rpm; then
	echo "ERROR: you have problems with your incoming files" >&2
	exit 1
fi

check_incoming()
{
	echo -n "Verifying repositories: "
	if ! check_missing_srpms "$@"; then
		echo "ERROR: you have orphaned RPMS" >&2
		return 1
	fi

	if ! check_obsolete_srpms "$@"; then
		echo "ERROR: you have orphaned SRPMS" >&2
		exit 1
	fi

	sisyphus_check -q "$@"
	echo "done."
}

check_incoming RPMS SRPMS
upload_bin_new RPMS
upload_src_new SRPMS

if ! cleanup_incoming RPMS/*.rpm SRPMS/*.rpm; then
	echo "ERROR: you have problems with your incoming files" >&2
	exit 1
fi

check_incoming RPMS SRPMS
sisyphus_prepare
