Already almost done with the caldav-project.

Some template-adjustment has to be done still, but it'll do.
master
gandalf 2022-05-30 22:36:25 +02:00
parent 78cf0f032e
commit 59c92430cc
15 changed files with 453 additions and 26 deletions

1
.env
View File

@ -1 +0,0 @@
FINDPATH=$HOME/Dokumente

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
# Custom entries
.erinnermich.csv
.erinneralle.csv
.env
*-*.ics
# ---> Linux

42
add_alarm.sh Executable file
View File

@ -0,0 +1,42 @@
#!/bin/bash
### This shell script is used to subscribe alarms to events/todos that are to be uploaded into caldav on the owncloud server by add_date.sh
# Usage output string. $0 is filename.
usage="$0 (t|e) categories date"
# print usage string if improper options, or if requested.
if [ "$#" -ne 3 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "$usage"
exit 1
else
# read login credentials and config
BASEPATH=$(dirname $(realpath $0))
. $BASEPATH/.env
# find relevant categories and decide for a template
main_cat=$(echo $2 | cut -d, -f1 | tr 'A-Z' 'a-z')
sec_cat=$(echo $2 | cut -d, -f2 | tr 'A-Z' 'a-z')
if [ $main_cat != wv ]; then
main_cat=${main_cat}_${sec_cat}
fi
# invoke template or exit, if template does not exist. add_date will then expect no output of this script.
template=$BASEPATH/templates/alarm_${main_cat}_$1.ics
aux=alarm.aux
if [ -e $template ]; then
cp $template $aux
else
exit 1;
fi
# adjust the template
sed -i "s|20160225|$3|g" $aux
sed -i "s|20160224|$(($3-1))|g" $aux
sed -i "s|20160223|$(($3-2))|g" $aux
sed -i "s|replacememail|${mails[$sec_cat]}|g" $aux
# output the stuff for add_date to read
cat $aux
fi

71
add_date.sh Normal file → Executable file
View File

@ -1,43 +1,78 @@
#!/bin/bash
### This shell script is used to create new events in caldav on our owncloud server after a machine booking on our grr server
### This shell script is used to create new events in caldav on the owncloud server
### Copied from https://gist.github.com/remyd1/a353b07219884c5878cc27d04aab9d96 and modified to fit my needs.
# Usage output string. $0 is filename.
usage="$0 categories date description [dtstart] [dtend]
where categories is a comma separated list that MUST start with FRIST, WF or TERMIN
and the second item in this list denotes the required alarm set."
usage="$0 machineNumber user starttime endtime"
if [ "$#" -ne 4 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ];then
echo $usage
# print usage string if improper options, or if requested.
if [ "$#" -lt 3 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "$usage"
exit 1
else
# read login credentials and config
BASEPATH=$(dirname $(realpath $0))
. $BASEPATH/.env
# generate random UID starting here
random1=`</dev/urandom tr -dc '1-9a-z' | head -c8; echo ""`
random2=`</dev/urandom tr -dc '1-9a-z' | head -c4; echo ""`
random3=`</dev/urandom tr -dc '1-9a-z' | head -c4; echo ""`
random4=`</dev/urandom tr -dc '1-9a-z' | head -c4; echo ""`
random5=`</dev/urandom tr -dc '1-9a-z' | head -c12; echo ""`
#UID=`</dev/urandom tr -dc '1-9a-z' | head -c10; echo ""`
# UID=`</dev/urandom tr -dc '1-9a-z' | head -c10; echo ""`
# ics example 8cbf7d9e-6g68-43b9-zb3c-073a8e6b8f46.ics
UID=$random1-$random2-$random3-$random4-$random5
ics=$UID.ics
UUID=$random1-$random2-$random3-$random4-$random5
ics=$UUID.ics
# done here generating an UID, and defining a filename using that UID
NOW=`date +%Y%m%dT%H%M%S`
# find main category and decide for a template
main_cat=$(echo $1 | cut -d, -f1 | tr 'A-Z' 'a-z')
template=template.ics
template=$BASEPATH/templates/template_$main_cat.ics
cp template.ics $ics
# initiate iCal file with template
cp $template $ics
sed -i "s|reservation machine|reservation machine $1 par $2|g" $ics
sed -i "s|20160225T083000|$3|g" $ics
sed -i "s|20160225T090000|$4|g" $ics
sed -i "s|99g999gggg|$UID|g" $ics
sed -i "s|20160224T172807|$NOW|g" $ics
# and change some stuff with cli options.
# what we need to change:
# dtstamp, lastmodified, created:
sed -i "s|20160224T172807|$NOW|g" $ics
# date (this script will only add single day events. Use other calDAV front-ends for more sophisticated usage)
sed -i "s|20160225|$2|g" $ics
# categories
sed -i "s|replacemecategory|$1|g" $ics
# replacemealarm[et]
# We have to do quite a lot of shitty magic here to get the right representations for the different kinds of newlines.
alarmt=$($BASEPATH/add_alarm.sh t $1 $2)
alarmt=${alarmt//$'\n'/\\$'\n'}
alarme=$($BASEPATH/add_alarm.sh e $1 $2)
alarme=${alarme//$'\n'/\\$'\n'}
sed -i "s|replacemealarmt|${alarmt//\\n/\\\\n}|g" $ics
sed -i "s|replacemealarmt|${alarme//\\n/\\\\n}|g" $ics
# AktenzeichenXYZ
# description:
sed -i "s|replacemedescription|${3//$'\n'/\\\\n}|g" $ics
# what we might need to replace, but not even that often:
# dtstart, time component optional:
[ -n $4 ] && sed -i "s|230000|$4|g" $ics
# dtend, time component optional:
[ -n $5 ] && sed -i "s|235959|$5|g" $ics
# UUID:
sed -i "s|99g999gggg|$UUID|g" $ics
user=username:secret
url=http://owncloud.domain.tld/owncloud/remote.php/caldav/calendars/foo
user=$username:$secret
url=$domain/$username/$calendar
curl -k --user $user -X PUT -H "Content-Type: text/calendar; charset=utf-8" --data-binary @./$ics --url $url/$ics
# curl -k --user $user -X PUT -H "Content-Type: text/calendar; charset=utf-8" --data-binary @./$ics --url $url/$ics
cat $ics
fi

View File

@ -0,0 +1,5 @@
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Fristablauf\nAktenzeichenXYZ\nreplacemedate
TRIGGER,VALUE=DATE-TIME:20160224T180000
END:VALARM

View File

@ -0,0 +1,27 @@
BEGIN:VALARM
ACTION:MAIL
SUMMARY:Fristablauf AktenzeichenXYZ
DESCRIPTION:Es läuft demnächst eine Frist ab:\nreplacemedescription\n\nreplacemedate
ATTENDEE:replacememail
TRIGGER,VALUE=DATE-TIME:20160223T100000
END:VALARM
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Fristablauf\nAktenzeichenXYZ\nreplacemedate
TRIGGER,VALUE=DATE-TIME:20160223T100000
END:VALARM
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Fristablauf\nAktenzeichenXYZ\nreplacemedate
TRIGGER,RELATED=END:-PT5M
END:VALARM
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Fristablauf\nAktenzeichenXYZ\nreplacemedate
TRIGGER,RELATED=END:-PT6H
END:VALARM
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Fristablauf\nAktenzeichenXYZ\nreplacemedate
TRIGGER,VALUE=DATE-TIME:20160224T180000
END:VALARM

View File

@ -0,0 +1,5 @@
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Deadline\nreplacemedate\nreplacemedescription
TRIGGER,VALUE=DATE-TIME:20160224T180000
END:VALARM

View File

@ -0,0 +1,12 @@
BEGIN:VALARM
ACTION:MAIL
SUMMARY:Termin AktenzeichenXYZ
DESCRIPTION:Du hast einen Termin:\nreplacemedescription\n\nreplacemedate
ATTENDEE:replacememail
TRIGGER:-P1W
END:VALARM
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Termin\nAktenzeichenXYZ\nreplacemedate
TRIGGER,VALUE=DATE-TIME:20160224T100000
END:VALARM

View File

@ -0,0 +1,5 @@
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Termin\nreplacemedate\nreplacemedescription
TRIGGER,VALUE=DATE-TIME:20160224T180000
END:VALARM

21
templates/alarm_wv_t.ics Normal file
View File

@ -0,0 +1,21 @@
BEGIN:VALARM
ACTION:MAIL
SUMMARY:Wiedervorlage AktenzeichenXYZ
DESCRIPTION:Hiermit wird ein Vorgang wieder vorgelegt:\nreplacemedescription\n\nreplacemedate
ATTENDEE:replacememail
TRIGGER:PT5M
DURATION:+P4W
REPEAT:6
END:VALARM
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Wiedervorlage\nAktenzeichenXYZ\nreplacemedescription
TRIGGER:PT5M
END:VALARM
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Wiedervorlage\nAktenzeichenXYZ\nreplacemedescription
TRIGGER:+P1W
DURATION:+P1W
REPEAT:10
END:VALARM

View File

@ -0,0 +1,144 @@
# Frist, Jura, event
# Display -1d 1800
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Fristablauf\nAktenzeichenXYZ\nreplacemedate
TRIGGER,VALUE=DATE-TIME:20160224T180000
END:VALARM
# Frist, Jura, todo
# Mail -2d 1000
BEGIN:VALARM
ACTION:MAIL
SUMMARY:Fristablauf AktenzeichenXYZ
DESCRIPTION:Es läuft demnächst eine Frist ab:\nreplacemedescription\n\nreplacemedate
ATTENDEE:replacememail
TRIGGER,VALUE=DATE-TIME:20160223T100000
END:VALARM
#Display -2d 1000
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Fristablauf\nAktenzeichenXYZ\nreplacemedate
TRIGGER,VALUE=DATE-TIME:20160223T100000
END:VALARM
#display -5m
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Fristablauf\nAktenzeichenXYZ\nreplacemedate
TRIGGER,RELATED=END:-PT5M
END:VALARM
#display -6h
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Fristablauf\nAktenzeichenXYZ\nreplacemedate
TRIGGER,RELATED=END:-PT6H
END:VALARM
# Display -1d 1800
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Fristablauf\nAktenzeichenXYZ\nreplacemedate
TRIGGER,VALUE=DATE-TIME:20160224T180000
END:VALARM
# Termin, Jura, event
# Mail -1w
BEGIN:VALARM
ACTION:MAIL
SUMMARY:Termin AktenzeichenXYZ
DESCRIPTION:Du hast einen Termin:\nreplacemedescription\n\nreplacemedate
ATTENDEE:replacememail
TRIGGER:-P1W
END:VALARM
#Display -1d 1000
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Termin\nAktenzeichenXYZ\nreplacemedate
TRIGGER,VALUE=DATE-TIME:20160224T100000
END:VALARM
# wv, todo
# Mail 0
BEGIN:VALARM
ACTION:MAIL
SUMMARY:Wiedervorlage AktenzeichenXYZ
DESCRIPTION:Hiermit wird eine Akte wieder vorgelegt:\nreplacemedescription\n\nreplacemedate
ATTENDEE:replacememail
TRIGGER:PT5M
DURATION:+P4W
REPEAT:6
END:VALARM
# Display 0
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Wiedervorlage\nAktenzeichenXYZ\nreplacemedescription
TRIGGER:PT5M
END:VALARM
#Display +7w
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Wiedervorlage\nAktenzeichenXYZ\nreplacemedescription
TRIGGER:+P1W
DURATION:+P1W
REPEAT:10
END:VALARM
# Frist, Uni, todo
#Display -1d 1000
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Deadline\nreplacemedate\nreplacemedescription
TRIGGER,VALUE=DATE-TIME:20160224T100000
END:VALARM
#display -1h
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Deadline\nreplacemedate\nreplacemedescription
TRIGGER,RELATED=END:-PT1H
END:VALARM
# Frist, pEp, todo
#Display -1d 1000
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Deadline\nreplacemedate\nreplacemedescription
TRIGGER,VALUE=DATE-TIME:20160224T100000
END:VALARM
#display -1w
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Deadline\nreplacemedate\nreplacemedescription
TRIGGER,RELATED=END:-P1W
END:VALARM
# Termin, pEp, event
#Display -1d 1000
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Deadline\nreplacemedate\nreplacemedescription
TRIGGER,VALUE=DATE-TIME:20160224T100000
END:VALARM
#display -15m
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Termin\nreplacemedate\nreplacemedescription
TRIGGER,RELATED=END:-PT15M
END:VALARM
# Frist, personal, todo
#Display -1d 1800
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Deadline\nreplacemedate\nreplacemedescription
TRIGGER,VALUE=DATE-TIME:20160224T180000
END:VALARM
# Termin, personal, event
#Display -1d 1800
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Termin\nreplacemedate\nreplacemedescription
TRIGGER,VALUE=DATE-TIME:20160224T180000
END:VALARM

View File

@ -0,0 +1,55 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
BEGIN:VTIMEZONE
TZID:Europe/Paris
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20160224T172807Z
LAST-MODIFIED:20160224T172807Z
DTSTAMP:20160224T172807Z
UID:99g999gggg-event
SUMMARY:Frist AktenzeichenXYZ
DESCRIPTION:replacemedescription
DTSTART;TZID=Europe/Paris:20160225T230000
DTEND;TZID=Europe/Paris:20160225T235959
TRANS:TRANSPARENT
CLASS:PUBLIC
CATEGORIES:replacemecategory
X-MOZ-GENERATION:1
BEGIN:VALARM
replacemealarme
END:VALARM
END:VEVENT
BEGIN:VTODO
CREATED:20160224T172807Z
LAST-MODIFIED:20160224T172807Z
DTSTAMP:20160224T172807Z
UID:99g999gggg-todo
RELATED-TO:99g999gggg-event
SUMMARY:Frist AktenzeichenXYZ
DESCRIPTION:replacemedescription
DUE;TZID=Europe/Paris:20160225T235959
STATUS:NEEDS-ACTION
CLASS:PUBLIC
CATEGORIES:replacemecategory
X-MOZ-GENERATION:1
BEGIN:VALARM
replacemealarmt
END:VALARM
END:VTODO
END:VCALENDAR

View File

@ -0,0 +1,35 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
BEGIN:VTIMEZONE
TZID:Europe/Paris
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20160224T172807Z
LAST-MODIFIED:20160224T172807Z
DTSTAMP:20160224T172807Z
UID:99g999gggg
SUMMARY:reservation machine
DESCRIPTION:to_replace
DTSTART;TZID=Europe/Paris:20160225T083000
DTEND;TZID=Europe/Paris:20160225T090000
X-LIC-ERROR;X-LIC-ERRORTYPE=VALUE-PARSE-ERROR:No value for CATEGORIES prope
rty. Removing entire property:
CLASS:PUBLIC
X-MOZ-GENERATION:1
END:VEVENT
END:VCALENDAR

View File

@ -22,14 +22,17 @@ BEGIN:VEVENT
CREATED:20160224T172807Z
LAST-MODIFIED:20160224T172807Z
DTSTAMP:20160224T172807Z
UID:99g999gggg
SUMMARY:reservation machine
DESCRIPTION:to_replace
DTSTART;TZID=Europe/Paris:20160225T083000
DTEND;TZID=Europe/Paris:20160225T090000
X-LIC-ERROR;X-LIC-ERRORTYPE=VALUE-PARSE-ERROR:No value for CATEGORIES prope
rty. Removing entire property:
UID:99g999gggg-event
SUMMARY:Frist AktenzeichenXYZ
DESCRIPTION:replacemedescription
DTSTART;TZID=Europe/Paris:20160225T230000
DTEND;TZID=Europe/Paris:20160225T235959
TRANS:TRANSPARENT
CLASS:PUBLIC
CATEGORIES:replacemecategory
X-MOZ-GENERATION:1
BEGIN:VALARM
replacemealarme
END:VALARM
END:VEVENT
END:VCALENDAR

37
templates/template_wv.ics Normal file
View File

@ -0,0 +1,37 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
BEGIN:VTIMEZONE
TZID:Europe/Paris
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
END:STANDARD
END:VTIMEZONE
BEGIN:VTODO
CREATED:20160224T172807Z
LAST-MODIFIED:20160224T172807Z
DTSTAMP:20160224T172807Z
UID:99g999gggg-todo
SUMMARY:Wiedervorlage AktenzeichenXYZ
DESCRIPTION:replacemedescription
DTSTART;TZID=Europe/Paris:20160225T230000
STATUS:NEEDS-ACTION
CLASS:PUBLIC
CATEGORIES:replacemecategory
X-MOZ-GENERATION:1
BEGIN:VALARM
replacemealarmt
END:VALARM
END:VTODO
END:VCALENDAR