-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaldavexplore.sh
55 lines (49 loc) · 2.78 KB
/
caldavexplore.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Helper Script to Display User's Calendar URLs on a CalDav Server
# derived from:
# https://blog.sleeplessbeastie.eu/2018/06/18/how-to-display-upcoming-events-in-nextcloud-calendar-using-shell-script/
# needs curl and xmlstarlet to be installed
# CalDav server and path
dav_server="https://your.caldavserver.net"
dav_path="/nextcloud/remote.php/dav/"
# Basic auth credentials
username="youruser"
password="yourpass"
# Get URL for the user's principal resource on the server
dav_user_path=$(curl --silent \
--request PROPFIND \
--header 'Content-Type: text/xml' \
--header 'Depth: 0' \
--data '<d:propfind xmlns:d="DAV:">
<d:prop>
<d:current-user-principal />
</d:prop>
</d:propfind>' \
--user ${username}:${password} \
${dav_server}${dav_path} | \
xmlstarlet sel -t -v 'd:multistatus/d:response/d:propstat/d:prop/d:current-user-principal/d:href' -n)
# Get URL that contains calendar collections owned by the user
dav_user_calendar_home_path=$(curl --silent \
--request PROPFIND \
--header 'Content-Type: text/xml' \
--header 'Depth: 0' \
--data '<d:propfind xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
<d:prop>
<c:calendar-home-set />
</d:prop>
</d:propfind>' \
--user ${username}:${password} \
${dav_server}${dav_user_path} | \
xmlstarlet sel -t -v 'd:multistatus/d:response/d:propstat/d:prop/cal:calendar-home-set/d:href' -n)
# Get calendar paths
dav_user_calendar_paths=$(curl --silent \
--request PROPFIND \
--header 'Content-Type: text/xml' \
--header 'Depth: 1' \
--data '<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/"><d:prop><d:displayname/></d:prop></d:propfind>' \
--user ${username}:${password} \
${dav_server}${dav_user_calendar_home_path} | \
xmlstarlet sel -t -m 'd:multistatus/d:response' -i "string-length(d:propstat/d:prop/d:displayname)" -i "d:propstat/d:status='HTTP/1.1 200 OK'" -v "d:href" -n)
echo "dav_user_path: $dav_user_path"
echo "dav_user_calendar_home_path: $dav_user_calendar_home_path"
echo "dav_user_calendar_paths: $dav_user_calendar_paths"