#!/bin/bash

BWLIMIT=2500

while [[ $# -gt 0 ]]; do
    case $1 in
        --bwlimit)
            BWLIMIT="$2"
            shift 2
            ;;
        *)
            shift
            ;;
    esac
done

./reresolve-dns.sh
systemctl stop wg-quick@wg0
systemctl start wg-quick@wg0

#WENN wg show einen lange zurückliegenden handshake zeigt, muss der keepalive auf Serverseite verlängert werden

cd /home/ck/

echo syncing `pwd` `date`

source sync-accounts

for account in ${accounts[@]}; do
    echo $account
    source $account

    echo $(date "+%FT%T") >> /media/data/ncdata/data/$account/files/syncdate.txt
    echo "$(tail -20 /media/data/ncdata/data/$account/files/syncdate.txt)" > /media/data/ncdata/data/$account/files/syncdate.txt

    for folder in ${folders[@]}; do
        echo $folder
#!! in rsync --delete deletes all fles that are available remotely but not locally
## -n für "trockenlauf"
        rsync -auszv --bwlimit=$BWLIMIT --password-file=rsyncpw --delete /media/data/ncdata/data/$account/files/$folder Christopher@server-haus-12b.home::Christopher/$account/files/
    done
done

#echo $(date "+%FT%T") >> $logfile
