#!/bin/sh

set -u

[ -f /opt/osstech/etc/samba/rsync.conf ] || { echo "/opt/osstech/etc/samba/rsync.conf MUST exist" 1>&2 ; exit 1; }
[ -f /opt/osstech/etc/samba/rsync.secret ] || { echo "/opt/osstech/etc/samba/rsync.secret MUST exist" 1>&2 ; exit 1; }

. /opt/osstech/etc/samba/rsync.conf

rsync \
    --compress \
    --timeout=120 \
    --recursive \
    --links \
    --times \
    --chmod=D0775,F0664 \
    --omit-dir-times \
    --delete-after \
    --port=$RSYNC_PORT \
    --password-file=/opt/osstech/etc/samba/rsync.secret \
    "$@" \
    rsync://$RSYNC_USER@$RSYNC_SERVER/SYSVOL/ \
    /opt/osstech/var/lib/samba/sysvol/

/opt/osstech/bin/samba-tool ntacl sysvolreset
