#/bin/bash
# sets proper permissions for all ModE-Sim subfolders
# Ralf, 08.08.23 

set -ex

data_dir_sim=/tank/exports/ERC_PALAEO/ModE-Sim
data_dir_ra=/tank/exports/ERC_PALAEO/ModE-RA

sim=true
ra=false

# set permissions for ModE-Sim

if ${sim}; then
   
   chown -R rhand@giub.local:palaeo-ra ${data_dir_sim}
   setfacl -b -R ${data_dir_sim} 
   setfacl -b -R -d ${data_dir_sim}
   
   chmod g+s ${data_dir_sim}
   
   chmod 750 ${data_dir_sim}/processing_scripts
   chmod -R u=rwX,go=rX ${data_dir_sim}/{docu,example_runscripts,forcings,inputfiles,outdata,processing_scripts,README.txt}

   find ${data_dir_sim} -type d -exec chmod u+w {} \;

   chmod -R a-w ${data_dir_sim}/outdata/set_????-?/abs/m0??/by_year

fi # sim

# set permissions for ModE-RA

if ${ra}; then
   
   chown -R joerg:palaeo-ra ${data_dir_ra}
   setfacl -b -R ${data_dir_ra}
   setfacl -b -R -d ${data_dir_ra}
   
   chmod g+s ${data_dir_ra}
   
   chmod 750 ${data_dir_ra}/processing_scripts
   chmod -R u=rwX,go=rX ${data_dir_ra}/{docu,outdata,processing_scripts,README.txt}

   find ${data_dir_ra} -type d -exec chmod u+w {} \;

   chmod -R u-w ${data_dir_ra}/outdata/set_/abs/m0??/by_year
   
fi # ra

exit 0
