Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Ubuntu-Phone] Owncloud Contact & Calendar Sync - Carddav & Caldav via syncevolution.
#!/bin/bash
# ---------------------------------------------------------------------------
# Ubuntu Phone - Sync Owncloud Contacts & Calendar Account
# Carddav & Caldav.
# Tested on : Ubuntu-touch vivid - ubuntu-touch/rc-proposed/bq-aquaris.en/vegetahd/
# Last edit : 2015/10/07.
# Author : Romain Fluttaz, boTux.fr, <romain@botux.fr>
# ============= [ Configuration ] ============= #
# --------------- [ OwnCloud ] ---------------- #
# Server and user informations
HTTP_PROTOCOL="https" # "http" or "https". It's recommended to use an $HTTP_PROTOCOL connection
OWNCLOUD_URL="cloud.domain.com" # Without the last /.
USERNAME="owncloud-user" # Your OwnCloud username
PASSWORD="owncloud-password" # Your OwnCloud password
# Contact addressbooks
CONTACT_ADDRESSBOOK_NAME="contacts" # Check in the contact setting page.
# Calendar
CALENDAR_NAME="personnel" # Check in the calendar setting page.
# Database
OC_DATABASE_NAME="owncloud"
# ----------------- [ Phone ] ----------------- #
# Database name :
CONTACT_DB_NAME="Contacts-name" # Contact addressbook name on the phone
CALENDAR_DB_NAME="Calendar-name" # Calendar name on the phone
# CRON job
CRON_FREQUENCY="hourly" # Cronjob frequency. "hourly", "dayly", "weekly", "monthly". See $HTTP_PROTOCOL://help.ubuntu.com/community/CronHowto#Advanced_Crontab
# ============= [ /Configuration ] ============ #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License at <http://www.gnu.org/licenses/> for
# more details.
# Thanks to :
# alexandre_payet @ https://askubuntu.com/questions/616081/ubuntu-touch-add-contact-list-and-calendars
# alexandre_payet @ https://askubuntu.com/questions/611761/syncevolution-in-cronjob-to-sync-the-ubuntu-phone-via-caldav-arddav
# alexandre_payet @ https://askubuntu.com/questions/629219/automatically-sync-calendar-on-ubuntu-phone/629728#629728
# Usage: Edit the config section and run the script.
# Revision history:
# 2015-08-22 Adding 1 Contact & 1 Calendar.
# 2015-08-22 Add cronjob support.
# ---------------------------------------------------------------------------
echo "\e[4mAdding OwnCloud account : **$OWNCLOUD_URL**\e[0m"
echo ""
# Contact
echo -e "[\e[0;34m Contacts \e[m] $CONTACT_ADDRESSBOOK_NAME @ $OC_DATABASE_NAME"
syncevolution --create-database backend=evolution-contacts database=$CONTACT_DB_NAME
syncevolution --configure --template webdav username=$USERNAME password="$PASSWORD" syncURL=$HTTP_PROTOCOL://$OWNCLOUD_URL/remote.php/ keyring=no target-config@$OC_DATABASE_NAME
syncevolution --configure backend=evolution-contacts database=$CONTACT_DB_NAME @default $CONTACT_DB_NAME
syncevolution --configure database=$HTTP_PROTOCOL://$OWNCLOUD_URL/remote.php/carddav/addressbooks/$USERNAME/$CONTACT_ADDRESSBOOK_NAME backend=carddav target-config@$OC_DATABASE_NAME $CONTACT_DB_NAME
syncevolution --configure --template SyncEvolution_Client Sync=None syncURL=local://@$OC_DATABASE_NAME username= password= $OC_DATABASE_NAME $CONTACT_DB_NAME
syncevolution --configure sync=two-way backend=evolution-contacts database=$CONTACT_DB_NAME $OC_DATABASE_NAME $CONTACT_DB_NAME
echo " +--> $CONTACT_DB_NAME @ local"
syncevolution --sync refresh-from-remote $OC_DATABASE_NAME $CONTACT_DB_NAME
syncevolution --sync slow $OC_DATABASE_NAME $CONTACT_DB_NAME
echo -e "[\e[0;34m Contacts \e[m] +--> Done."
echo ""
# Calendar
echo -e "[\e[33m Calendar \e[m] $CALENDAR_NAME @ $OC_DATABASE_NAME"
syncevolution --create-database backend=evolution-calendar database=$CALENDAR_NAME
syncevolution --configure --template webdav username=$USERNAME password="$PASSWORD" syncURL=$HTTP_PROTOCOL://$OWNCLOUD_URL/remote.php/ keyring=no target-config@$OC_DATABASE_NAME
syncevolution --configure backend=evolution-calendar database=$CALENDAR_NAME @default $CALENDAR_NAME
syncevolution --configure database=$HTTP_PROTOCOL://$OWNCLOUD_URL/remote.php/caldav/calendars/$USERNAME/$CALENDAR_NAME backend=caldav target-config@$OC_DATABASE_NAME $CALENDAR_DB_NAME
syncevolution --configure --template SyncEvolution_Client syncURL=local://@$OC_DATABASE_NAME username= password= $OC_DATABASE_NAME $CALENDAR_NAME
syncevolution --configure sync=two-way database=$CALENDAR_NAME $OC_DATABASE_NAME $CALENDAR_NAME
echo " +--> $CALENDAR_DB_NAME @ local"
syncevolution --sync refresh-from-remote $OC_DATABASE_NAME $CALENDAR_NAME
echo -e "[\e[33m Calendar \e[m] +--> Done."
echo ""
# Cron
echo -e "[\e[0;36m Cron \e[m]"
echo -e " +--> \e[0;31mGranting SuperUser Access\e[m"
sudo mount /dev/loop0 / -o remount,rw
CRON_LINE="@$CRON_FREQUENCY export DISPLAY=:0.0 && export DBUS_SESSION_BUS_ADDRESS=$(ps -u phablet e | grep -Eo 'dbus-daemon.*address=unix:abstract=/tmp/dbus-[A-Za-z0-9]{10}' | tail -c35) && /usr/bin/syncevolution $OC_DATABASE_NAME"
(crontab -u phablet -l; echo "$CRON_LINE" ) | crontab -u phablet -
sudo service cron restart
crontab -l | grep "$CRON_LINE"
echo -e "[\e[0;36m Cron \e[m] +--> Added."
echo ""
# First Normal Sync
echo -e "[\e[0;32m Syncronisation \e[m]"
syncevolution $OC_DATABASE_NAME
echo -e "[\e[0;32m Syncronisation \e[m] +--> Done."
# Print information
echo ""
echo ""
echo ""
echo "# To manually sync your accounts, use the command below :"
echo ""
echo -e " syncevolution $OC_DATABASE_NAME \e[m"
echo " or"
echo -e "\e[0;34msyncevolution $OC_DATABASE_NAME $CONTACT_DB_NAME\e[m | \e[33msyncevolution $OC_DATABASE_NAME $CALENDAR_NAME\e[m"
echo ""
echo "See 'syncevolution --help' to get more information."
@boTux

This comment has been minimized.

Show comment
Hide comment
@boTux

boTux Aug 23, 2015

Ubuntu-Phone - Owncloud Contacts & Calendar Account Sync

Launch this script on your ubuntu-touch phone.

# Connect to your phone (dev mode activated)
phablet-shell
# Download the script
wget https://gist.github.com/boTux/069b53d8e06bdb9b9c97/raw/e7bcd362c6781d909f810522dc328fb64ca1f113/ubuntu-touch_owncloud-sync_contact-calendar.sh
chmod +x ubuntu-touch_owncloud-sync_contact-calendar.sh
# Edit the script to change your server informations before running it.
./ubuntu-touch_owncloud-sync_contact-calendar.sh
Owner

boTux commented Aug 23, 2015

Ubuntu-Phone - Owncloud Contacts & Calendar Account Sync

Launch this script on your ubuntu-touch phone.

# Connect to your phone (dev mode activated)
phablet-shell
# Download the script
wget https://gist.github.com/boTux/069b53d8e06bdb9b9c97/raw/e7bcd362c6781d909f810522dc328fb64ca1f113/ubuntu-touch_owncloud-sync_contact-calendar.sh
chmod +x ubuntu-touch_owncloud-sync_contact-calendar.sh
# Edit the script to change your server informations before running it.
./ubuntu-touch_owncloud-sync_contact-calendar.sh
@konnnGit

This comment has been minimized.

Show comment
Hide comment
@konnnGit

konnnGit Feb 9, 2016

Hello and nice for you to write that script. Thanks.
I though have a problem when I use the https protocol. I have problem in authentication with the v.m server. I use a self signed .pem file, I have stored it locally to the phone but the problem persist. Have any hint about it?

konnnGit commented Feb 9, 2016

Hello and nice for you to write that script. Thanks.
I though have a problem when I use the https protocol. I have problem in authentication with the v.m server. I use a self signed .pem file, I have stored it locally to the phone but the problem persist. Have any hint about it?

@stevenandree

This comment has been minimized.

Show comment
Hide comment
@stevenandree

stevenandree Feb 22, 2016

Hey, thanks for the excellent script. Works flawlessly.

konnnGit: Follow instructions here http://askubuntu.com/questions/591866/how-can-contacts-and-calendars-be-synchronised to add self signed SSL cert to ubuntu touch.

stevenandree commented Feb 22, 2016

Hey, thanks for the excellent script. Works flawlessly.

konnnGit: Follow instructions here http://askubuntu.com/questions/591866/how-can-contacts-and-calendars-be-synchronised to add self signed SSL cert to ubuntu touch.

@NodokaMurmevent

This comment has been minimized.

Show comment
Hide comment
@NodokaMurmevent

NodokaMurmevent Mar 12, 2016

are you sur it's dayly and not daily ? L36

NodokaMurmevent commented Mar 12, 2016

are you sur it's dayly and not daily ? L36

@waltSGDB

This comment has been minimized.

Show comment
Hide comment
@waltSGDB

waltSGDB Sep 13, 2016

Hi, the script does not work with my value CALENDAR_DB_NAME= "Calendar-Owncloud"
on line 82, it says syncevolution --create-database backend=evolution-calendar database=$CALENDAR_NAME of this should not be rather $CALENDAR_DB_NAME ?

waltSGDB commented Sep 13, 2016

Hi, the script does not work with my value CALENDAR_DB_NAME= "Calendar-Owncloud"
on line 82, it says syncevolution --create-database backend=evolution-calendar database=$CALENDAR_NAME of this should not be rather $CALENDAR_DB_NAME ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment