#!/bin/bash

#  cd CDAQ/daq_dev_v0.31/daq/config/HOSS
#  stop HOSS; exit GUI
#  ./set_config.sh hoss_default_raid57_g50.config
#  ./set_config.sh hoss_default_raid57_moreskims.config
#  start GUI ;  restart HOSS ;
#
#  cd /hdops/CDAQ/daq_dev_v0.31/daq/config/hd_all/
#  cp hosts.g50 hosts
#  cp hosts.buff  hosts
#
#  /hdops/online_setup.cshrc.coda_3.10dev
#       setenv JAVA_HOME /gapps/Java/jdk/1.8/x64/jdk1.8.0_102/
#       #setenv JAVA_HOME /gapps/Java/jdk-11.0.2/
#


CONFIG=${1-none}

if [[ $CONFIG == none ]] ; then

    echo "---------------------------------------"
    echo "Uasage: $0 <config> "
    echo "Avalable config: "
    ls -1 hoss_default_raid*f_more*.config
    #ls -l hoss_default.config
    echo "==>  FILE: hoss_default.config  LINK = `readlink hoss_default.config` "
    exit 0
elif [[ $CONFIG == rst ]] ; then
    echo "Restore saved config: `readlink hoss_default.config.SAVE` "
    [[ ! -f hoss_default.config.SAVE ]]  && echo "Error: File: hoss_default.config.SAVE  does not exists"  && exit 1
    mv hoss_default.config hoss_default.config.OLD
    mv hoss_default.config.SAVE hoss_default.config    
    ls -l hoss_default.config*
    exit 0
fi


[[ ! -f $CONFIG ]]  && echo "Error: File:  $CONFIG  does not exists"  && exit 1

echo "----------------------------------------------"
ls -l hoss_default.config
echo " Set new link: hoss_default.config to $CONFIG "

mv hoss_default.config hoss_default.config.SAVE
ln -s $CONFIG hoss_default.config

ls -l hoss_default.config*
