After suffering through yet another morning of ‘find’ pegging my CPU and grinding my sad little laptop hard drive for a couple of hours, I finally decided to rectify the situation. Most Linux distributions these days ship mlocate by default, and so I decided to give it a go on OS X. Unfortunately, it doesn’t quite support OS X out of the box yet. I’ll spare you all the miserable details (it was an epic struggle getting this compiled), but I finally managed to get it working.
# first we get the source and patch it $ hg clone http://hg.fedorahosted.org/hg/mlocate $ cd mlocate $ wget 'https://fedorahosted.org/mlocate/attachment/ticket/15/mlocate-mountlist-hg.2.diff?format=raw' -O mlocate-mountlist-hg.2.diff $ hg import mlocate-mountlist-hg.2.diff # prep $ cd .. $ git clone git://git.savannah.gnu.org/gnulib.git $ cd mlocate $ ../gnulib/gnulib-tool --import $ mv gnulib/lib/stat-time.h~ gnulib/lib/stat-time.h $ cp ../gnulib/lib/canonicalize.h gnulib/lib/ $ autoreconf --install --force # install $ ./configure $ make $ sudo make install
Ok, now we have the binaries in place; we’re almost there! One last thing to do, and that’s create a new user account and group for mlocate. After running updatedb it will try to chown the locate db as the user ‘mlocate’, so we need to make sure this users exists. Unfortunately, there’s no adduser command in OS X and it’s a little bit of a pain, so I wrote this little script to take care of it for you. Grab it here.
Simply run it like so:
$ adduser adduser! username: mlocate home dir [default=/var/empty]: group id (default=700): user id (default=700): real name (default=daemon): shell: (default=/usr/bin/false):
All done! Now let’s try updating the db –
$ sudo /usr/local/bin/updatedb
And that should be it. I still ran into a couple of problems with permissions so your best bet is to fix them every time you run updatedb (just stick it in cron):
$ chmod 664 /usr/local/var/mlocate/mlocate.db
Now wasn’t that easy?
Updated (July 23, 2010): You may need newer versions of automake and autoconf as well. I had problems with 1.5 and 2.63 respectively but upgrading to 1.11 and 2.65 (with fink) worked fine.