Syncing your ical calendar to the iPhone from Linux

Many Linux users are advanced and experienced users. Those of them that also own an iPhone have probably jailbroken it to run custom third party applications as the first thing they do when they get home from their Apple pusher. Such users would like to control the content of the phone themselves, no matter what Apple wants them to do. For example, syncing mp3 and video to and from the iPhone is possible from Linux using Amarok and sshfs. I am such a user.

Now, I thought, could it be that hard to sync the calendar too? That would be extremely useful. It seems it was. I googled a bit for a solution, but found only iTunes, non-working syncml apps, and third party converting services. Do I want to send my https encrypted syncml url, username and password to some third party service provider in another part of the world over unencrypted http? I think not. Also, our groupware server runs OpenXchange, and its ical support is better than its syncml support, which is syncml v1 only. There exists starting points for syncing contacts via Evolution and an iPhone version of Funambol, but it doesn’t support the calendar.

Then I stumbled over ical2sqlite by Lucas Waye at his blog. His program seemed to be able to do what I wanted, so I tried to download it to give it a try. The source was not available from his blog anymore, but it has been accepted into Ubuntu Hardy, and can be downloaded from any mirror.

After some hours of trying and failing, I got it to work acceptable with ical data from OpenXchange, thus creating a proof-of-concept one-way sync.

Now, ical2sqlite is quite rough and unfinished work. It has some cool features, like it segfaults no matter what on x86_64, it crashes if it gets some special characters like ticks (‘), it crashes with a segfault if a description field is larger than about 1088 bytes, it crashes if it gets date fields in zulu time format, and it probably has a ton of other bugs. But if you can avoid those bugs, for example by piping the ical data through a perl script, you’re done.

Could one not write a less buggy program, or use perl only? There exists ical modules for perl, doesn’t it? Yes it does. Feel free to contribute :-)

Meanwhile, here’s what you need:

  • A jailbroken iPhone with OpenSSH available over Wifi. (iPod Touch will probably work too.)
  • A modern Linux distribution with the standard tool chain (gcc, make). Fedora and Ubuntu is nice. I have only got the program to work on i386.
  • ical (libical-dev) and sqlite (libsqlite3-dev) libraries and header files.
  • curl (wget or any perl module to download stuff would probably do too).
  • Perl. But you already have that.

Now, download ical2sqlite from an Ubuntu mirror and install it the normal way.

$ wget ftp://ftp.uninett.no/linux/ubuntu/pool/universe/i/ical2sqlite/ical2sqlite_0.1.orig.tar.gz
$ tar xvzf ical2sqlite_0.1.orig.tar.gz
$ cd ical2sqlite/
$ ./configure
$ make
$ sudo make install

(If you run Ubuntu and have the know-how, you might want to build and install the package instead).

The next thing you need some script to download and massage the data to get around the menioned bugs. You can use mine: http://users.linpro.no/ingvar/updateiphonecalendar. Just download it, edit it, and run it. (You can put it somewhere in your path and do chmod +x if you like).

This script is quite rough. A polished version should probably take options, use perl modules for converting time zone data, use more secure password and tempfile handling and so on. Feel free to contribute changes.

At least, change values for the variables icalurl, user, password, your phone’s ip-address, timezone and zuluoffset.

Note: This is one-way sync only. The existing iphone calendar will be overwritten, and all its contents lost. Proceed with care..

Then just run the script. Nice, eh?

By the way, I asked Lucas if he would fix the bugs mentioned above. Eventually, he probably will, but be patient.

4 Responses to “Syncing your ical calendar to the iPhone from Linux”

  1. Hei.

    Dette høres bra ut!
    Hvilket program buker du selv for å generere den ical-fila du så sender opp til iPhonen? Evolution eller Korganizer?

    Mvh,
    Kolbjørn

  2. Jeg henter iCal-fila fra kalenderen jeg bruker på jobben, Open-Xchange. Jeg har ikke testet andre kilder. ymmv :-)

  3. thomas says:

    it’s nice to see that it’s at least possible to sync the iphone ical with ubuntu. what i most like about the iphone is the excellent calendar, and i would like to be able to automatically sync it with a calendar on ubuntu. at the moment i’m using the symbian built-in calendar (N80IE), but i’m hoping to switch to iphone at some point. no hurry though, since i won’t buy the iphone 2.0 as long as one is required to sign a contract…

  4. [...] months ago, I used the quite crude tool called ical2sqlite and some simple perl scripting, and built a proof-of-concept one-way sync from an ical source (OpenXchange) to the iPhone calendar via a Linux box. Now, recently I tested [...]

Leave a Reply