#!/bin/bash
#
# Script that reads packages from buildcross output directories and 
# include debian packages into reprepro repository
#
# Emdebian 2000-2007 Copyright

source conf_vars.sh

usage(){
	echo "Usage: ${0##*/} [ARCH]"
	echo "Add deb files under toolchain build directories."
	echo 
	cat << EOF
	[ARCH] can be i386, amd64 or powerpc.
	Execute it from OUTSIDE the CHROOTs.

EOF
}

incluir_deb(){
	for j in $ARCHLIST; do
		DIRX="$ABSX/$j/"
		for i in $( ls -1 $DIRX/*.deb ); do
		   reprepro -Vb $REPRO_CONF -C main includedeb $SUITE $i
		done
	done
}

if [ $# != 0 ]; then
	while true; do
		case $1 in
			i386)
				ABSX=/jails/i386-$SUITE/home/toolchain/trunk/
				DIRX="$ABSX/$ARCH/"

				incluir_deb
				echo "em_repro.sh ....... finished."
				exit 0
				;;
			amd64)
				ABSX=/jails/amd64-$SUITE/home/toolchain/trunk/
				DIRX="$ABSX/$ARCH/"
				incluir_deb
				echo "em_repro.sh ....... finished."
				exit 0
				;;
			powerpc)
				ABSX=/jails/powerpc-$SUITE/home/toolchain/trunk/
				DIRX="$ABSX/$ARCH/"
				incluir_deb
				echo "em_repro.sh ....... finished."
				exit 0
				;;
			-h)
				usage
				exit 0
				;;
			*)
				usage
				break
				;;
		esac
	done
fi

