#! /bin/sh

obmconf=/etc/obm/obm-rpm.conf
NEWFILE=/etc/obm/obm_conf.ini

# check if the file exist
echo -e "================= OBM Satellite configuration ==================\n"
echo -e "o Please enter external url : \c"
read value
echo "EXTERNALURL=$value" >> $obmconf
echo -e "o Plese enter LDAP server name : \c"
read value
echo "OBM_LDAPSERVER=$value" >> $obmconf

echo -e "o Configure for postfix installation, (y)es, (n)o: \c"
read value
if [ $value = "y" -o $value = "yes" ] ; then
	echo "$SATELLITE_POSTFIX_INSTALL=true" >> $obmconf
else
	echo "$SATELLITE_POSTFIX_INSTALL=false" >> $obmconf	
fi

echo -e "o Enter ip adress of obm-services, default 127.0.0.1: \c"
read value
if [ -z ${value} ] ; then
	echo "${SATELLITE_OBM_SERVICES}=127.0.0.1" >> $obmconf
else
	echo "${SATELLITE_OBM_SERVICES}=${value}" >> $obmconf
fi
	

. $obmconf

sed -i -e "s#^ldap_server.*#ldap_server		${OBM_LDAPSERVER}#" /etc/obm-satellite/obmSatellite.cf

sed -i -e "s#^cidr_allow#cidr_allow		${SATELLITE_OBM_SERVICES}/32#" /etc/obm-satellite/obmSatellite.cf



if [ ${SATELLITE_POSTFIX_INSTALL} = "true" ] ; then
	touch /etc/postfix/virtual_mailbox && chown root:root /etc/postfix/virtual_mailbox && chmod 664 /etc/postfix/virtual_mailbox
	touch /etc/postfix/virtual_alias && chown root:root /etc/postfix/virtual_alias && chmod 664 /etc/postfix/virtual_alias
	touch /etc/postfix/transport && chown root:root /etc/postfix/transport && chmod 664 /etc/postfix/transport
	touch /etc/postfix/virtual_domains && chown root:root /etc/postfix/virtual_domains && chmod 664 /etc/postfix/virtual_domains	
fi


echo -e "======================= End Config obm-satellite =======================\n"
