#!/usr/bin/env	bash
export dbpath=/home/local/ehr
export path=/home/local/ehr
sed_mongodbpath() {
	sed -i 's#/usr/local/ehr#'$path'#' $dbpath/mongodb6/startmongodb.sh

	sed -i 's#/usr/local/ehr#'$path'#' $dbpath/mongodb6/startmongodb2.sh

	sed -i 's#/usr/local/ehr#'$path'#' $dbpath/mongodb6/stopmongodb.sh

	sed -i 's#/usr/local/ehr#'$path'#' $dbpath/mongodb6/mongodb_data_bak.sh

	sed -i 's#/usr/local/ehr#'$path'#' $dbpath/mongodb6/bin/mongod.cfg

	sed -i 's#/usr/local/ehr#'$path'#' $dbpath/mongodb6/bin/mongod2.cfg
}

sed_pgdbpath() {

	sed -i 's#/usr/local/ehr#'$path'#' $dbpath/postgresql15/startpostgresql.sh

	sed -i 's#/usr/local/ehr#'$path'#' $dbpath/postgresql15/stoppostgresql.sh

	sed -i 's#/usr/local/ehr#'$path'#' $dbpath/postgresql15/postgresql_data_bak.sh
}
sed_mongodbpath
sed_pgdbpath

detect_os() {
	if [ -f /etc/os-release ]; then
		. /etc/os-release
		OS=$NAME
	else
		OS=$(uname -s)
	fi

	if [ "$OS" = "Ubuntu" ]; then
		echo "This is Ubuntu"
		ln -s $dbpath/postgresql15/lib/libpq.so.5 /usr/lib/libpq.so.5
	elif [ "$OS" = "CentOS Linux" ]; then
		echo "This is CentOS"
		ln -s $dbpath/postgresql15/lib/libpq.so.5 /usr/lib64/libpq.so.5
	else
		echo "This is not Ubuntu or CentOS"
	fi
}
detect_os

