#!/bin/bash
#
# Deliver RPMs packages and tgz files to ftp.mondorescue.org
#
# $Id: mkdeliv 561 2006-05-20 15:51:21Z bcornec $
#

# BerliOS FTP/SSH setup
ACCOUNT=bruno@ftp.mondorescue.org
DSTDIR=/mondo/ftp
FTPSERV="ftp.berlios.de"
FTPDIR="/incoming"

dname=`dirname $0`
prem=`echo $dname |cut -c1`
if [ ${prem} == "/" ]; then
        export TOOLHOME=$dname
else
	export TOOLHOME=${PWD}/$dname
fi

. $TOOLHOME/common-env
. $TOOLHOME/svn-env
. $TOOLHOME/rpm-env

tgz=""
srpms=""
rpms=""
rev=`$TOOLHOME/mksvnversion`

if [ "$1" = "" ]; then
		c="mondo-doc mindi mondo"
else
	c=$1
fi
if [ "`echo $c | grep mindi`" != "" ]; then
	cp -a ${TOPDIR}/SOURCES/mindi-${MINDI_VER}.tgz ${TOPDIR}/SOURCES/mindi-${MINDI_VER}-r${rev}.tgz
	cp -a ${TOPDIR}/SOURCES/mindi-${MINDI_VER}.tar.bz2 ${TOPDIR}/SOURCES/mindi-${MINDI_VER}-r${rev}.tar.bz2
	tgz="$tgz ${TOPDIR}/SOURCES/mindi-${MINDI_VER}-r${rev}.tgz ${TOPDIR}/SOURCES/mindi-${MINDI_VER}-r${rev}.tar.bz2"
	rpms="$rpms ${TOPDIR}/RPMS/${ARCH}/mindi-${MINDI_VER}-${rev}${suf}.${ARCH}.rpm"
	srpms="$srpms ${TOPDIR}/SRPMS/mindi-${MINDI_VER}-${rev}${suf}.src.rpm"
fi
if [ "`echo $c | grep mondo-doc`" != "" ]; then
	cp -a ${TOPDIR}/SOURCES/mondo-doc-${MONDO_VER}.tgz ${TOPDIR}/SOURCES/mondo-doc-${MONDO_VER}-r${rev}.tgz
	cp -a ${TOPDIR}/SOURCES/mondo-doc-${MONDO_VER}.tar.bz2 ${TOPDIR}/SOURCES/mondo-doc-${MONDO_VER}-r${rev}.tar.bz2
	tgz="$tgz ${TOPDIR}/SOURCES/mondo-doc-${MONDO_VER}-r${rev}.tgz ${TOPDIR}/SOURCES/mondo-doc-${MONDO_VER}-r${rev}.tar.bz2"
	rpms="$rpms ${TOPDIR}/RPMS/${ARCH}/mondo-doc-${MONDO_VER}-${rev}${suf}.${ARCH}.rpm"
	srpms="$srpms ${TOPDIR}/SRPMS/mondo-${MONDO_VER}-${rev}${suf}.src.rpm"
fi
if [ "`echo $c | grep -v doc | grep mondo`" != "" ]; then
	cp -a ${TOPDIR}/SOURCES/mondo-${MONDO_VER}.tgz ${TOPDIR}/SOURCES/mondo-${MONDO_VER}-r${rev}.tgz
	cp -a ${TOPDIR}/SOURCES/mondo-${MONDO_VER}.tar.bz2 ${TOPDIR}/SOURCES/mondo-${MONDO_VER}-r${rev}.tar.bz2
	tgz="$tgz ${TOPDIR}/SOURCES/mondo-${MONDO_VER}-r${rev}.tgz ${TOPDIR}/SOURCES/mondo-${MONDO_VER}-r${rev}.tar.bz2"
	rpms="$rpms ${TOPDIR}/RPMS/${ARCH}/mondo-${MONDO_VER}-${rev}${suf}.${ARCH}.rpm"
	srpms="$srpms ${TOPDIR}/SRPMS/mondo-${MONDO_VER}-${rev}${suf}.src.rpm"
fi
echo "Sources delivery to ${ACCOUNT}:${DSTDIR}/src"
scp ${tgz} ${ACCOUNT}:${DSTDIR}/src

echo "Packages delivery to ${ACCOUNT}:${DSTDIR}/${ddir}/${dver}"
ssh ${ACCOUNT} "mkdir -p ${DSTDIR}/${ddir}/${dver}"
scp ${rpms} ${srpms} ${ACCOUNT}:${DSTDIR}/${ddir}/${dver}

echo "Sources delivery to ${FTPSERV} ${FTPDIR}"
if [ "`which ncftpput`" != "" ]; then
	ncftpput ${FTPSERV} ${FTPDIR} ${tgz}
elif [ "`which lftp`" != "" ]; then
	lftp -e "cd ${FTPDIR} ; put ${tgz} ; quit" ${FTPSERV}
fi
