#!/bin/bash
echo  "Enter no. of synchronization files"
read n
cp profiles_tdi.properties profiles_tdi_ORIGINAL.properties
for (( c=1; c<=n; c++ ))
do
filename="profiles_tdi_$c.properties"
cp $filename profiles_tdi.properties
cd `dirname $0`

LOCK_FILE=./sync_all_dns.lck

# test lock
if [ -e ${LOCK_FILE} ]; then
	echo "Synchronization Lock file already exist. Please turn off other running sync process before performing this one."
	exit
else
	echo "create synchronization lock"
	touch ${LOCK_FILE}
fi

#clear rc file
./clearRC.sh

#get TDI variables
. ./tdienv.sh

./netstore ping >/dev/null 2>/dev/null
if [[ $? -ne 0 ]]; then
	./netstore start
fi

#set initial failure return code in case called task does not complete
echo "1" >/tmp/_tdi.rc
${TDIPATH}/ibmdisrv -s . -c profiles_tdi.xml -r sync_all_dns
rc=`cat /tmp/_tdi.rc`
if [[ ! "${rc}" == "0" ]]; then
	echo "Synchronize of Database Repository failed"
	echo ""
fi
./clearRC.sh
./clearLock.sh



cp profiles_tdi_ORIGINAL.properties profiles_tdi.properties
done
exit ${rc}
