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