Get Unison working on MBWE

This will enable you to sync files with unison on the MBWE. There was much discussion and hints about how to get unison working on the MBWE. So I make this page as a as-short-as-possible cheat sheet to get your MBWE to use unison, like mine. Most of this should be cut/pastable, please report if that is not the case.

This is working on all my MBWE 2TB with white lights. Please report if you have success on any other models, for completeness.

Updated after I found this post that mentioned that version 2.40+ of unison have vastly improved syncing of filenames containing UTF-8 characters (syncing from Mac OSX often scrambles the filenames).

Prerequisites

First, you need to have root access to your MBWE (instructions) and need to have ipkg working (instructions). You need to login as root now into your MBWE.

Getting gcc to work

This used to be the stopping point for many. Thankfully, now there is a new armel feed that contains gcc. You need to verify that you are using the new feed, as hinted at here. You should replace cs05q1 with cs08q1 to get a file like this (note I have commented the original line):

$ cat /opt/etc/ipkg/armel-feed.conf
src armel http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable
#src armel http://ipkg.nslu2-linux.org/feeds/optware/cs05q1armel/cross/unstable

After this, you need to update the feed information, and install all the necessary tools to build unison, like this:

$ ipkg update
$ ipkg install bash coreutils make ocaml gcc

This will download a few files, and install these tools. Note that it may take a couple of minutes to get there.

Downloading and preparing Unison

Now we are ready to build unison. Prepare a sandbox for this:

$ mkdir /root/unison
$ cd /root/unison

The latest stable unison is 2.48.4 (download from here). Note that if you use Ubuntu LTS (Long Term Service), it ships with 2.48.3, others with 2.32.52, and different versions can not always talk to each other. So you should install the same version on all machines that will need to sync through unison. You can find out which version is installed on a machine by issuing:

$ unison -version

Download the appropriate version of unison then, noting the single quotes around the URL in the following example to deal correctly with the ~ in the path name.

$ export VERSION=2.48.4
$ wget "http://www.seas.upenn.edu/~bcpierce/unison//download/releases/unison-${VERSION}/unison-${VERSION}.tar.gz"
$ tar xvfz unison-${VERSION}.tar.gz
$ mv src unison-${VERSION}  # Because 2.48.4 expands into 'src'
$ cd unison-${VERSION}

For some reason, with our combination of Ocaml and build tools, the code will sometimes not completely compile as-is. Here are the few hints depending on the version of unison you are trying to compile.

Building and installing unison

You should now be able to build unison. Build instructions were mostly taken from Grzegorz's page. Just issue this command:

$ make NATIVE=false UISTYLE=text CFLAGS="-cclib -L/lib" unison

This will compile all the Ocaml files and link the result into a binary. Note that currently you will get a few errors, that you can ignore. Also, for 2.48.x this will compile only the {unison} binary, not the {fsmonitor} tools because I could not get {inotify} to link.

Just to check that unison is at least working locally, unison comes with a suite of self tests:

$ ./unison -selftest

2.46.x - 2.48.x This is currently failing on Linux machines (as of Aug 2016, see this post).

Now all you need is to install unison in the right place (note the slash at the end of the INSTALLDIR):

make install NATIVE=false INSTALLDIR=/opt/bin/
chmod ga+rx /opt/bin/unison*

For 2.48.x, as the {inotify} stuff does not build, the installation can be done by

cp unison /opt/bin/unison-2.48.4 && chmod ga+rx /opt/bin/unison-2.48.4

Default access rights are limited to the user root and group root, so you may want to change them as indicated above. It will install both a plain unison binary as well as one with the version in the binary name (e.g. /opt/bin/unison-2.32.52), which lets you install multiple version on your MBWE. See the next section to use the correct one should you have multiple version.

Using unison

From another machine, setup a unison profile (.prf) to sync some files as usual. The only addition you will need for it to work is that unison is not at the standard location on the MBWE, which you should configure with the servercmd parameter so it looks for it in /opt/bin. Here is what one of my profiles looks like:

# cat ~/.unison/sample.prf
root = /shares/data
root = ssh://syncuser@myserver.local//DataVolume/Data
servercmd = /opt/bin/unison-2.48.4

As noted before, you would need to add the version number to the path in the servercmd to make sure you use the same version. Unison will tell you if versions mismatch and fail.
For setting up unison over ssh so that you don't need to enter your password each time, have a look at this article.

Thanks

Most of this information is available somewhere on the net, but you have to grab it from different places. I have linked these pages where appropriate. Thanks to all the guys having put it up, so I can make a nice single cheat sheet for this!

Further improvements

Now that we have a running unison binary, it would probably make sense to add it to the armel feed, so that this page could be summarized as

ipkg install unison

:-)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License