#!/bin/sh
################################################################################
#	BdsSetup	Sets up a Bds Server
#			T.Barnaby,	BEAM Ltd,	2008-05-06
################################################################################
#
#
# This scripts sets up a BDS Server for operation after a bare metal install.

# fileReplace <filename> <searchParameter> <replaceParamter>
fileReplace()
{
	if grep "$2" $1 > /dev/null 2>&1
	then
		res=`sed -e "s'$2'$3'" $1`
		echo "$res" > $1
	else
		echo "$3" >> $1
	fi
}

fileReplaceIfNotSet()
{
	if ! grep "$3" $1 > /dev/null 2>&1
	then
		res=`sed -e "s'$2'$3'" $1`
		echo "$res" > $1
	fi
}

install=0
if [ "$1" == "-install" ]; then
	install=1
fi

# Setup freedesktop menu item
cp bds.menu /etc/xdg/menus/applications-merged/bds.menu

# Setup boapns
if ! grep "^boapns" /etc/services > /dev/null 2>&1
then
	echo "boapns        12000/tcp                # BEAM BOAP Name Server" >> /etc/services
	echo "boapns        12000/udp                # BEAM BOAP Name Server" >> /etc/services
fi

chkconfig boapns on
if [ $install != "1" ]; then
	service boapns restart
fi

# Add Autodrm user
useradd bdsautodrm

chkconfig mysqld on
chkconfig dovecot on
chkconfig bdsServer on
chkconfig bdsAutodrm on

service mysqld start
service dovcat start

bdsRestart

exit 0
