#!/bin/bash
#
# tarballer.sh - script to build tarballs of the rocking curve image and log
#                files copied from CHESS into the named scan directories, and
#                archive to srm any that are not already stored there.
#
# author: richard.t.jones at uconn.edu
# version: may 28, 2014

scandir_list="\
JD70-1-study1 \
JD70-2-study1 \
JD70-3-study1 \
JD70-4-study1 \
JD70-5-study1 \
JD70-6-study1 \
JD70-7-study1 \
JD70-8-study1 \
JD70-9-study1 \
JD70-10-study1 \
UC30-9-C300_25-study001 \
UC30-10-C300_25-study1 \
UC45-1-C500-study1 \
UC45-2-UC500_300-study1 \
UC45-3-study1 \
UC45-4-study1 \
UC45-5-study1 \
UC45-6-S200_50-study1 \
UC45-7-S200_50-study1 \
UC45-11-study1 \
UC45-12-study1 \
UC45-13-study1 \
UC45-14-study1 \
UC45-15-study1 \
UC30-15-study1 \
UC30-17-study1 \
UC30-18-study1 \
UC30-19-study1 \
UC30-20-study1 \
"

pnfsbase=/pnfs/phys.uconn.edu/data/Gluex/beamline/diamonds/chess-5-2014
srmbase=srm://grinch.phys.uconn.edu/Gluex/beamline/diamonds/chess-5-2014

for scandir in $scandir_list; do
    if [[ -r $pnfsbase/$scandir.tgz ]]; then
        echo "$scandir.tgz already saved, skipping..."
        continue
    elif [[ ! -r $scandir.tgz ]]; then
        echo "$scandir.tgz not found, creating..."
        tar zcf $scandir.tgz $scandir || exit $?
    fi
    echo "pushing $scandir.tgz to srm..."
    srmcp file:///`pwd`/$scandir.tgz $srmbase/$scandir.tgz || exit $?
done
