#!/bin/bash

# script changes permissions for all results files and directories for domains
# it's necessary to be able delete results by script create_domains.pl if domains are redefined

ARG=$1
TARGET=${ARG:0:5}

FOUNDDIRS=`find /data/CASPCOMMONS/RESULTS/ -name "$TARGET*" -type d `

echo $FOUNDDIRS | xargs --no-run-if-empty chgrp casp
echo $FOUNDDIRS | xargs --no-run-if-empty chmod 775



FOUNDFILES=`find /data/CASPCOMMONS/RESULTS \( -name OBSOLETE_DOMAINS \) -prune -o -name "$TARGET*" -type f `

echo $FOUNDFILES | xargs --no-run-if-empty chgrp casp
echo $FOUNDFILES | xargs --no-run-if-empty chmod 664

FOUNDFILES=`find /data/CASPCOMMONS/RESULTS/LVR/$ARG -name "Data*" -type f `

echo $FOUNDFILES | xargs --no-run-if-empty chgrp casp
echo $FOUNDFILES | xargs --no-run-if-empty chmod 664

FOUNDFILES=`find /data/CASPCOMMONS/RESULTS/DaliLite/ -name "index.html" -type f `

echo $FOUNDFILES | xargs --no-run-if-empty chgrp casp
echo $FOUNDFILES | xargs --no-run-if-empty chmod 664

exit
