Using a WebDAV server to share stuff (settings, preferences) between multiple environments

I use a Mac at home and Ubuntu at work, but in both cases I use Firefox to browse the web. I've a nice set of Adblock filters and I started thinking how to share the same filter set between my home Firefox profile and my profile at work. Here's the story.

As the title already says: I choose to use a WebDAV server to share the Adblock filters (in your Firefox profile it's the adblockplus/patterns.ini file). I already had WebDAV set up to share my Lightning calendar, so I was already half way there. I won't go into details on setting up a WebDAV server. Read the mod_dav guide for either Apache 1.3.x or Apache 2.2.x. It's pretty easy and straightforward. You can use DAV Explorer to check whether everything works.

If you've got DAV working, you just have to set up in both work environments an automount of the DAV directory. In case of Ubuntu (or Debian) you can install fusedav. It's a user-space (FUSE) implementation of a DAV client. I've written a small script to allow easy mounting of predefined DAV resources. Copy it into a file (eg. mount.fusedav and grant execute permissions on it):
#!/bin/sh

param=$1

# mount DAV shares
if [ -n "${param}" -a -r "${HOME}/.fusedav/fusedavtab" ]; then
  cat "${HOME}/.fusedav/fusedavtab" | while read LINE; do
    set -- $(echo ${LINE})
    davuri=$1
    mountpoint=$2
    username=$3
    password=$4
    if [ -n "${davuri}" -a \( "${davuri}" = "${param}" -o "${param}" = "-a" \) -a -n "${mountpoint}" -a -d "${mountpoint}" -a -n "${username}" -a -n "${password}" ]; then
      if ! mount | fgrep -qis "${mountpoint}" > /dev/null 2>&1; then
        (echo "${username}"; echo "${password}") | nohup fusedav -o nonempty "${davuri}" "${mountpoint}" > /dev/null 2>&1 &
      fi
    fi
  done
fi

The script tries to find DAV mount points and credentials in a file at $HOME/.fusedav/fusedavtab. It should have a format like this:
https://dav.example.com/some/directory  /home/youruser/Network/dav.example.com  davuser davpassword

The script takes only one parameter: a DAV URL. It looks up the mountpoint and credentials based on the URL. You can call the script with the -a parameter too and in that case it'll mount all DAV resources it finds in your fusedavtab file.

Now how to make this run automatically upon login? On Ubuntu you've to create a *.desktop file in your $HOME/.config/autostart directory. Something like this will do:
[Desktop Entry]
Name=Fusedav mounts
Comment=Mount WebDAV shares from $HOME/.fusedav/fusedavtab
Exec=mount.fusedav -a
Icon=terminal
StartupNotify=false
Terminal=false
Type=Application
Categories=Network;
X-GNOME-Autostart-enabled=true

Name[C]=Fusedav mounts
Comment[C]=Mount WebDAV shares from $HOME/.fusedav/fusedavtab

The above file assumes that mount.fusedav is somewhere on your $PATH.
You can create this desktop file also in the GUI (in the menu see System/Preferences/Sessions/Startup Programs).

Now we should do the same on our Mac. A little googling reveals the following one liner to mount DAV shares:
perl -e 'foreach ("davuser", "davpassword") {print pack("CCCC",0,0,0,length($_)).$_}' | mount_webdav -a0 https://dav.example.com/some/directory /Users/youruser/Network/dav.example.com

Update (10th Oct 2010): the above code works for Leopard nicely, but not for Snow Leopard (mount_webdav was changed Sad ). For 10.6 you've to use a shell script like this:
#!/usr/bin/expect
set timeout 15
log_user 0
spawn mount_webdav -i https://dav.example.com/some/directory /Users/youruser/Network/dav.example.com
expect "Username: " {
  send "davuser\n"
}
expect "Password: " {
  send "davpassword\n"
  exp_continue
}

You can use it as it is (in a shell script of course) or wrap it up in a script similiar to what I supplied for linux (Mac has /bin/sh too so probably you won't need too much work there to get it going) to make it more generic. The tricky part will be the automatic execution upon login.

There're a number of methods for that as well. You can create a launchd daemon, write a login hook or use an application/script as a login item. Needless to say: the latter is the easiest, but not the fastest/best solution.

My goal was to share my Adblock filters between my various Firefox profiles. Adblock Plus makes this easy since it uses a config variable to locate the patterns.ini file. Type about:config in Firefox and look for the extensions.adblockplus.patternsfile variable. Change its value in both of your environments to point to some file in a subdirectory of your DAV mount.

And finally: you're all done. Smile

PS: thanks to airwin for the idea of using a DAV server and the tip on using set -- $(echo ${variable}) to split a string into pieces.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Awsome, since fusedav is the

Awsome, since fusedav is the only possibility to access Novel Netstorage (davfs2 oder similiar won't work) i was looking for a script that would allow me to mount my shares without exposing my user data in the process table.

To bad this article wasn't linked anywhere.

Re: Awsome, since fusedav is the

Thanks for the comment. It made me revisit this post and realize that I haven't updated it for Snow Leopard (when I've upgraded my Mac and figured out how mount_webdav worked in the new OS).

As for not being linked anywhere ... running a Google search for fusedav webdav showed this page among the first 20 hits (first two pages of hits) for me.