#!/bin/sh -xe

# snapshot
cd /home/sdk/.reminders
git add *
git commit -m "Update $(date +"%Y-%m-%d %H:%M:%S")" || true

# copy uugrn calendard to dalek
scp -q vorstand@vorstand.uugrn.org:private/Kalender/uugrn.rem \
       sdk@home.codevoid.de:.reminders/uugrn.rem

# copy all calendars from dalek to local
scp -q sdk@home.codevoid.de:.reminders/\*.rem \
       /home/sdk/.reminders/

# download vcal/vcard from icloud / radical
vdirsyncer sync

# create import.rem from ical events (XXX fix this mess)
find ~/.isync -name "*.ics" -exec cat {} + \
        | ical2rem --no-todos \
        | fgrep -v "REM  MSG" \
        | sed 's,\\n, ,g' \
        | tr -d '\' \
        | sed 's/  / /g'  \
        > /home/sdk/.reminders/import.rem
