#!/bin/bash

#----------------------------------------------------------
# A script to set up the Bsoft environment
# Author: Bernard Heymann 
# 20170914 - 20200809

BSOFT=`dirname $0`
if [[ -z $BSOFT ]]; then BSOFT=`pwd`; fi
if [[ -n $1 ]]; then BSOFT="$( cd $1 && pwd )"; fi

echo "Bsoft directory: $BSOFT"

cd $BSOFT

./benv

if [[ -d /etc/profile.d ]]; then
	cp ${BSOFT}/bsoft.bashrc /etc/profile.d/bsoft.sh
elif [[ -e /etc/profile ]]; then
	if [[ `grep bsoft /etc/profile` ]]; then
		sed -i.orig '/.*bsoft.*/d' /etc/profile
	fi
	echo source ${BSOFT}/bsoft.bashrc >> /etc/profile
fi


if [[ -e /etc/csh.cshrc ]]; then
	if [[ `grep bsoft /etc/csh.cshrc` ]]; then
		sed -i.orig '/.*bsoft.*/d' /etc/csh.cshrc
	fi
	echo source ${BSOFT}/bsoft.cshrc >> /etc/csh.cshrc
fi

SYS=`uname -s | cut -f1 -d"-"`
if [[ $SYS = Darwin ]]; then
	./macinstall
fi

