#!/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

    for folder in ${folders[@]}; do
        echo $folder
        rsync -auszv --progress --bwlimit=$BWLIMIT --password-file=rsyncpw --exclude-from="exclude-file" Christopher@server-haus-12b.home::Christopher/$account/files/$folder /media/data/ncdata/data/$account/files/
    done
done

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