#!/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

systemctl enable boapns
if [ $install != "1" ]; then
	systemctl restart boapns
fi

# Add Autodrm user
useradd bdsautodrm

systemctl enable mariadb
systemctl enable bdsServer
systemctl enable bdsAutodrm

systemctl start mariadb

bdsRestart

exit 0
