-#!/bin/bash -l
+#!/bin/bash
[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
+if [[ -e /b/errhandle/err ]]; then
+ source /b/errhandle/err
+else
+ set -eE -o pipefail
+ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+fi
+source /a/bin/bash_unpublished/source-state
+source /a/bin/distro-functions/src/package-manager-abstractions
# davdroid setup instructions at the bottom
# main docs:
# http://radicale.org/user_documentation/
# https://davdroid.bitfire.at/configuration/
+# note on debugging: if radicale can't bind to the address,
+# in the log it just says "Starting Radicale". If you run
+# it in the foreground, it will give more info. Background
+# plus debug does not help.
+# sudo -u radicale radicale -D -f
# created password file with:
-# htpasswd -c /etc/nginx/caldav/htpasswd ian
+# htpasswd -c /etc/davpass dav
+
+vpn_ser=openvpn-client
+if [[ ! -e /lib/systemd/system/openvpn-client@.service ]]; then
+ vpn_ser=openvpn
+fi
+
+d=/etc/systemd/system/radicale.service.d
+mkdir -p $d
+cat >$d/override.conf <<EOF
+[Unit]
+# this unit is configured to start and stop whenever openvpn-client@mail.service
+# does
+After=network.target
+BindsTo=$vpn_ser@mail.service
+After=$vpn_ser@mail.service
+
+[Install]
+RequiredBy=$vpn_ser@mail.service
+EOF
+systemctl daemon-reload # not sure this is needed
+
+pi-nostart radicale
+
+# use persistent uid/gid
+IFS=:; read _ _ uid _ < <(getent passwd radicale ); unset IFS
+IFS=:; read _ _ gid _ < <(getent group radicale ); unset IFS
+if [[ $uid != 609 ]]; then
+ systemctl stop radicale ||:
+ usermod -u 609 radicale
+ groupmod -g 609 radicale
+ usermod -g 609 radicale
+fi
+find /o/radicale /var/log/radicale -xdev -exec chown -h 609 {} +
+find /o/radicale -xdev -exec chgrp -h 609 {} +
-# python-dulwich, to track changes with git, per
-# http://radicale.org/user_documentation/#idgit-support
-pi nginx python-dulwich radicale
-
# I moved /var/lib/radicale after it's initialization.
# I did a sudo -u radicale git init in the collections subfolder
# after it gets created, per the git docs.
-lnf -T /o/radicale /var/lib/radicale
+/a/exe/lnf -T /o/radicale /var/lib/radicale
# from https://www.williamjbowman.com/blog/2015/07/24/setting-up-webdav-caldav-and-carddav-servers/
# coment in this file says this is needed for it to run on startup
sed -ri 's/^\s*#+\s*(ENABLE_RADICALE\s*=\s*yes\s*)/\1/' /etc/default/radicale
-sgo radicale
setini() {
key="$1" value="$2" section="$3"
}
# comments say default is 0.0.0.0:5232
-setini hosts 10.8.0.1:5232 server
+setini hosts 10.8.0.4:5232 server
+
+if [[ $HOSTNAME == $MAIL_HOST ]]; then
+ systemctl start radicale
+ systemctl enable radicale
+fi
-# davdroid from f-droid. username ian,
-# url https://iank.pw/radicale/ian.
-# I disabled power management feature, it's got 240 min sync interval,
+# disable power management feature, set to 240 min sync interval,
# so it shouldn't be bad.
-#
-# when setting up davdroid, switch to groups are per-contact categories,
-# per https://davdroid.bitfire.at/configuration/radicale/
+# davdroid from f-druid.
+# login with url and user name
+# url https://cal.iankelling.org/ian
+# username ian
+# pass, see password manager for radicale
+#
+# add account dialog:
#
# set account name as ian@iankelling.org, per help text below the
# field.
#
+# switch to groups are per-contact categories,
+# per https://davdroid.bitfire.at/configuration/radicale/
+#
+#
# After setting up account, I added one address book, named
-# ian. calender was already created, named ian. checked boxes under
+# ianaddr. calender was already created, named ian. checked boxes under
# both. synced.
#
+# To restore from old phone to new phone, I wiped all data out, then copied over the newly created files. I think
+#
# ignorable background info:
#
-# When debugging, tailed /var/log/radicale/radicale.log and nginx log,
+# opentasks uses the calendar file.
+#
+# The address book I created got a uuid as a name for the file. Note
+# the .props file says if it's a calendar or addressbook.
+#
+# When debugging, tailed /var/log/radicale/radicale.log and apache log,
# both show the requests happening. Without creating the address book,
# after creating a contact, a sync would delete it.
#
# https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
#
# Note, url above says only cayanogenmod 13+ and omnirom can manage groups.
+
+# Note, radicale had built-in git support to track changes, but they
+# removed it in 2.0.