2022-05-19 15:03:00 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-05-30 20:36:25 +00:00
|
|
|
### 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.
|
2022-05-19 15:03:00 +00:00
|
|
|
|
|
|
|
|
2022-05-30 20:36:25 +00:00
|
|
|
# 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."
|
2022-05-19 15:03:00 +00:00
|
|
|
|
2022-05-30 20:36:25 +00:00
|
|
|
# print usage string if improper options, or if requested.
|
|
|
|
if [ "$#" -lt 3 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
|
|
|
|
echo "$usage"
|
2022-05-19 15:03:00 +00:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
|
2022-05-30 20:36:25 +00:00
|
|
|
# read login credentials and config
|
|
|
|
BASEPATH=$(dirname $(realpath $0))
|
|
|
|
. $BASEPATH/.env
|
|
|
|
|
|
|
|
# generate random UID starting here
|
2022-05-19 15:03:00 +00:00
|
|
|
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 ""`
|
|
|
|
|
2022-05-30 20:36:25 +00:00
|
|
|
# UID=`</dev/urandom tr -dc '1-9a-z' | head -c10; echo ""`
|
2022-05-19 15:03:00 +00:00
|
|
|
|
|
|
|
# ics example 8cbf7d9e-6g68-43b9-zb3c-073a8e6b8f46.ics
|
2022-05-30 20:36:25 +00:00
|
|
|
UUID=$random1-$random2-$random3-$random4-$random5
|
|
|
|
ics=$UUID.ics
|
|
|
|
# done here generating an UID, and defining a filename using that UID
|
2022-05-19 15:03:00 +00:00
|
|
|
|
|
|
|
NOW=`date +%Y%m%dT%H%M%S`
|
2022-05-30 20:36:25 +00:00
|
|
|
|
|
|
|
# find main category and decide for a template
|
|
|
|
main_cat=$(echo $1 | cut -d, -f1 | tr 'A-Z' 'a-z')
|
2022-05-19 15:03:00 +00:00
|
|
|
|
2022-05-30 20:36:25 +00:00
|
|
|
template=$BASEPATH/templates/template_$main_cat.ics
|
2022-05-19 15:03:00 +00:00
|
|
|
|
2022-05-30 20:36:25 +00:00
|
|
|
# initiate iCal file with template
|
|
|
|
cp $template $ics
|
2022-05-19 15:03:00 +00:00
|
|
|
|
2022-05-30 20:36:25 +00:00
|
|
|
# and change some stuff with cli options.
|
|
|
|
# what we need to change:
|
|
|
|
# dtstamp, lastmodified, created:
|
2022-05-19 15:03:00 +00:00
|
|
|
sed -i "s|20160224T172807|$NOW|g" $ics
|
2022-05-30 20:36:25 +00:00
|
|
|
# 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
|
2022-05-19 15:03:00 +00:00
|
|
|
|
2022-05-30 20:36:25 +00:00
|
|
|
user=$username:$secret
|
|
|
|
url=$domain/$username/$calendar
|
2022-05-19 15:03:00 +00:00
|
|
|
|
2022-05-30 20:36:25 +00:00
|
|
|
# curl -k --user $user -X PUT -H "Content-Type: text/calendar; charset=utf-8" --data-binary @./$ics --url $url/$ics
|
|
|
|
cat $ics
|
2022-05-19 15:03:00 +00:00
|
|
|
fi
|