#!/bin/bash -e

if [ $# -lt 3 ]; then
  echo 'Usage: sync local_dir path cut'
  exit 1
fi

umask 002

TO=/mirror/root/$1
SOURCE_PATH=$2
CUT=$3
ADDRESS=$(cat ~/config/ADDRESS)

mkdir -p $TO
cd $TO
exec nice wget -q --bind-address=$ADDRESS --mirror --no-parent --no-host-directories --cut-dirs=$CUT --content-disposition --execute robots=off --recursive --reject "*\?*" $SOURCE_PATH
