#!/bin/bash
#-------------------------------------------------------------------------------
# Copyright (C) 2012-2019 British Crown (Met Office) & Contributors.
#
# This file is part of Rose, a framework for meteorological suites.
#
# Rose 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.
#
# Rose 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 Rose. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
set -eu
FOO=$(basename $0)
FOO_SESSION=${FOO_SESSION:-0}
FOO_RC=${FOO_RC:-0}
echo "$FOO $@ # rc=$FOO_RC" 1>>$FOO.log.$FOO_SESSION
ACTION=$1
shift 1
if [[ $ACTION != 'put' ]]; then
    echo "foo: $ACTION: unknown action" >&2
    exit 1
fi
TARGET=${1#foo://}
mkdir -p $(dirname foo/$TARGET)
shift 1
rsync -a "$@" foo/$TARGET
exit $FOO_RC
