#!/bin/bash -e

if [ $# -lt 2 ]; then
  echo 'Usage: sync local_dir endpoint'
  exit 1
fi

umask 002

TO=/mirror/root/$1
export RCLONE_CONFIG_S3_ENDPOINT=$2 RCLONE_CONFIG_S3_TYPE=s3 RCLONE_CONFIG_S3_PROVIDER=Other RCLONE_CONFIG_S3_ENV_AUTH=false
ADDRESS=$(cat ~/config/ADDRESS)

mkdir -p $TO
cd $TO
exec nice rclone sync --fast-list --use-server-modtime --bind $ADDRESS s3:s3/ $TO
