#!/bin/bash -l

##############################################
#
# This script define color, PCID, and dataPath
#
##############################################

if [ ! -z $RED  ]; then
  echo "Process_BasicConfig already loaded."
  return
fi

RED='\033[1;31m'
YELLOW='\033[1;33m'
ORANGE='\033[0;33m'
GREEN='\033[1;32m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'  #no color
LRED='\033[1;91m'

##############   need to distingish mac and daq
Arch="$(uname -s)"
PCName="$(hostname)"
PCID=-1      #if PCID == 1 (DAQ), 2 (MAC), -1(OTHER)

#------ Set up data folder, check disk space
echo -e "${YELLOW} ##################### Check computer name and arch. ${NC}"
echo "PC name  : ${PCName}"
echo "Archetech: ${Arch}"

if [ ${Arch} == "Linux" ] && [ ${PCName} == "solaris-daq" ]; then 

  PCID=1

  pathsSetting=${HOME}/SOLARIS_QT6_DAQ/programSettings.txt
  if [ -e ${pathsSetting} ]; then
    #echo "Found DAQ programSettings.txt for paths settings"

    analysisPath=$(cat ${pathsSetting} | head -n 2 | tail -n 1)

    if [ ! "${analysisPath}" = "$SOLARISANADIR" ]; then
      echo "The analysisPath from ${analysisPath} is different from present folder $SOLARISANADIR. Abort."
      exit
    fi

    rawDataPathParent=$(cat ${pathsSetting} | head -n 3 | tail -n 1)
    rootDataPathParent=$(cat ${pathsSetting} | head -n 4 | tail -n 1)

    databaseIP=$(cat ${pathsSetting} | head -n 6 | tail -n 1)
    databaseName=$(cat ${pathsSetting} | head -n 7 | tail -n 1)

    #echo ${rawDataPathParent}
    #echo ${rootDataPathParent}
    #echo ${databaseIP}
    #echo ${databaseName}

  else 

    echo "${RED} Cannot found DAQ programSettings.txt for path settings ${NC}"
    echo "Seek Ryan for help"
    exit

  fi

fi

if [ ${Arch} == "Darwin" ] && [ ${PCName} == "SOLARISs-Mac-Studio.local" ]; then 
  PCID=2
  rawDataPathParent=${HOME}/experimentalData/
  rootDataPathParent=${HOME}/experimentalData/
fi