#!/bin/sh

#
# Start rancid and display result on stdout instead of sending it by mail
#
# Syntax:
#	start-rancid [eq ... eq]
#
# History
#   2007/07/03 : pda/jean : design
#   2010/10/20 : pda/jean : topo integration
#   2010/12/18 : pda      : rework installation
#

eval `/usr/local/bin/netmagis-config \
		rancidcmd \
		topobindir \
		`

# In the topodir directory, the fake sendmail program sends result
# on file descripor number 3 (instead of sending mail).
# We have to collect these mails (got on descriptor 3) and redirect
# them to stdout.

SENDMAILDIR="$topobindir"
PATH=$SENDMAILDIR:$PATH
export PATH

if [ $# = 0 ]
then
    exec $rancidcmd 3>&1
else
    error=0
    for eq in $*
    do
	$rancidcmd -r $eq 3>&1
	if [ $? != 0 ]
	then error=1
	fi
    done
    exit $error
fi
