various fixes
[distro-setup] / radicale-setup
1 #!/bin/bash -l
2
3 [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
4
5
6 # davdroid setup instructions at the bottom
7
8 # main docs:
9 # http://radicale.org/user_documentation/
10 # https://davdroid.bitfire.at/configuration/
11
12 # note on debugging: if radicale can't bind to the address,
13 # in the log it just says "Starting Radicale". If you run
14 # it in the foreground, it will give more info. Background
15 # plus debug does not help.
16 # sudo -u radicale radicale -D -f
17
18 # created password file with:
19 # htpasswd -c /etc/davpass dav
20
21 d=/etc/systemd/system/radicale.service.d
22 mkdir -p $d
23 sudo dd of=$d/override.conf <<'EOF'
24 [Unit]
25 # this unit is configured to start and stop whenever openvpn-client@mail.service
26 # does
27 After=network.target
28 BindsTo=openvpn-client@mail.service
29 After=openvpn-client@mail.service
30
31 [Install]
32 RequiredBy=openvpn-client@mail.service
33 EOF
34
35 pi radicale
36
37 # I moved /var/lib/radicale after it's initialization.
38 # I did a sudo -u radicale git init in the collections subfolder
39 # after it gets created, per the git docs.
40 lnf -T /o/radicale /var/lib/radicale
41
42 # from https://www.williamjbowman.com/blog/2015/07/24/setting-up-webdav-caldav-and-carddav-servers/
43
44 # more config is for li in distro-end
45
46 # coment in this file says this is needed for it to run on startup
47 sed -ri 's/^\s*#+\s*(ENABLE_RADICALE\s*=\s*yes\s*)/\1/' /etc/default/radicale
48
49 setini() {
50 key="$1" value="$2" section="$3"
51 file="/etc/radicale/config"
52 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*$key[[:space:]=]/d};/ *\[$section\]/a $key = $value" "$file"
53 }
54
55 # comments say default is 0.0.0.0:5232
56 setini hosts 10.8.0.4:5232 server
57
58 if [[ $HOSTNAME == $MAIL_HOST ]]; then
59 sgo radicale
60 fi
61
62 # disable power management feature, set to 240 min sync interval,
63 # so it shouldn't be bad.
64
65 # davdroid from f-druid.
66 # login with url and user name
67 # username ian,
68 # url https://cal.iankelling.org
69 # username ian
70 # pass, see password manager
71 #
72 # add account dialog:
73 #
74 # set account name as ian@iankelling.org, per help text below the
75 # field.
76 #
77 # switch to groups are per-contact categories,
78 # per https://davdroid.bitfire.at/configuration/radicale/
79 #
80 #
81 # After setting up account, I added one address book, named
82 # ianaddr. calender was already created, named ian. checked boxes under
83 # both. synced.
84 #
85 # To restore from old phone to new phone, I wiped all data out, then copied over the newly created files. I think
86 #
87 # ignorable background info:
88 #
89 # opentasks uses the calendar file.
90 #
91 # The address book I created got a uuid as a name for the file. Note
92 # the .props file says if it's a calendar or addressbook.
93 #
94 # When debugging, tailed /var/log/radicale/radicale.log and apache log,
95 # both show the requests happening. Without creating the address book,
96 # after creating a contact, a sync would delete it.
97 #
98 # Address books correspond to .props files in the radicale dir.
99 #
100 # Some background is here,
101 # https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
102 # which shows separate vcard option is from rfc 6350, the other is 2426,
103 # radicale page says it implements the former not the latter,
104 # which conflicts with the documentation of which to select, but whatever.
105 # http://radicale.org/technical_choices/
106 # https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
107 #
108 # Note, url above says only cayanogenmod 13+ and omnirom can manage groups.
109
110 # Note, radicale had built-in git support to track changes, but they
111 # removed it in 2.0.