Sunday, January 12, 2014

Raspberry Pi and ownCloud: Calendar and contact synchronization without Apple or Google

The probably badest news about Mac OS X Maverick is that the synchronization services were removed, thus disabling tools like Missing Sync to work. I used Missing Sync to synchronize calendar and contacts between my MacBook and Android phone. Since I do not want to use Google, I had to find another solution.
My new solution is a combination of the following things:
  • Raspberry Pi
  • ownCloud
  • CalDav- and CardDav-Sync for Android
I have a Raspberry Pi running ownCloud connected to my Airport Extreme via Ethernet cable (as it is directly placed near to the Airport). It has a static IP, so that it is easy to find in my local network. For security reasons it is only available in my local network: I don't need global access to my few contact and calendar data, as it is sufficient to sync the data when I (and my Android and MacBook) are at home. ownCloud is a little cloud solution, providing WebDav, CalDav and CardDav services. These services are used to sync the data similar to Google or Apple.
Why a Raspberry Pi?
For security reasons, I didn't want to use a (virtual) server publicly available on the internet. I simply do not have the time to constantly update a server for fixing security issues. Also, setting up a server in the cloud is not that much different from using Google, is it? Since the server needs to be accessible to the Android device, a static IP address is very convenient. I could have installed ownCloud on my MacBook directly, and assigning the book a static IP address (or reserve a specific DSCP IP address to the MacBook), however with the Pi I can use the server not only for me but also for roommates ;-) And then, for a geek a real local server is simply a must, isn't it?

Setup Raspberry Pi and ownCloud

Installation if this set up was pretty easy:
  1. Buy a Raspberry Pi along with an USB power supply, an SDHC card, and a little case and maybe little cooling elements
  2. Format SDHC card (luckily my MacBook has an SD card slot) via SD Formatter for Mac (https://www.sdcard.org)
  3. Install Rasbian via Noobs (http://www.raspberrypi.org)
    1. follow readme instruction foud in Noobs zip
    2. install Rasbian via Noobs, enable SSH via menu
    3. set up static IP address (e.g., see https://thepihut.com/blogs/raspberry-pi-tutorials/)
    4. while 3.1-3.3 needed the Pi to be connected to a monitor, once the static IP address is configured, the following steps can be applied via ssh.
  4. Install ownCloud (https://owncloud.com), following the tutorial at http://www.connect.de (german only).
    Minor adjustment: The SSL configuration file has to have newlines, that is, use this template:
    <virtualhost>
    SSLEngine On
    SSLCertificateFile /etc/apache2/ssl/apache.pem
    DocumentRoot /var/www
    </virtualhost>

Set up clients

Now, configure ownCloud, that is, set up initial admin user and create a new user via the web interface.
There is not much magic to configuring CalDav and CardDav to the OS X apps (in the apps, select preferences and add your own server using the static IP address and the configured user).
There may be some trouble setting up CardDav. For El Capitan, add a new CardDav account, manual setup, and use the following server address:
https://SERVER/owncloud/remote.php/dav/principles/users/USERNAME



For initial import of the calendar entries, export your calendar to a file. This file is then uploaded via drag'n drop to ownCloud and imported there via click (only click once, this might take a while).
The last point has been a little bit tricky, as I had to create a temporary folder manually in order make it work. This is how I did it:
cd /var/www/apps/calendar/
sudo mkdir import_tmp
sudo chown www-data:www-data import_tmp
Android Apps
I'm using the following Android apps now (instead of the Missing Sync software with Fliq Calendar, which I never really liked):
(Thank you Marcus for pointing me to these apps!)