#!/usr/bin/env bash
# This file is part of Megatest.
#
# Megatest is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Megatest is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Megatest. If not, see <http://www.gnu.org/licenses/>.
# Get the list of fossils from the cache
FILES=$(ls $FSLSAREA/$AREANAME|grep fossil)
# Do the remote sync from CACHE to FOSSILS
ssh $SITENAME /bin/bash <<EOF
for f in $FILES;do
FOSSLF=$FSLSAREA/$AREANAME/\$f
CACHEF=$WORKAREA/$SITENAME/
if [ ! -e \$FOSSLF ];then
cp \$CACHEF \$FOSSLF
chmod ug+rw \$FOSSLF
elif [ \$CACHEF -nt \$FOSSLF ];then
fossil pull -R \$FOSSLF \$CACHEF
fi
done
EOF
# Do the local sync
for f in $FILES;do
FOSSLF=$FSLSAREA/$AREANAME/\$f
CACHEF=$WORKAREA/$SITENAME/
if [ ! -e \$FOSSLF ];then
cp \$CACHEF \$FOSSLF
chmod ug+rw \$FOSSLF
elif [ \$CACHEF -nt \$FOSSLF ];then
fossil pull -R \$FOSSLF \$CACHEF
fi
done
echo done