Note: I originally posted this on Forrst.

I like to keep my music collection fairly centralized. Instead of having my music files spread out amongst various home and work computers, I have a machine at home host my iTunes/DAAP music library via forked-daapd (although one could just as easily leave a computer running iTunes open).

This shell script, tested on OS X 10.6, connects to my home machine via SSH and forwards the DAAP port to my remote machine. There are a few blog posts out there that describe how to do this, but this is the script I eventually landed on. If you have any suggestions for improvements, please let me know.

You’ll need to be able to log into your home machine via SSH. To connect outside your own LAN, you’ll also need to configure your router at home to forward the SSH port (default: 22) to whatever machine is hosting your iTunes library.

Here’s the shell script:

    share_name="ssh iTunes"

    kill `ps -U "$local_username" | grep ssh | grep ":36890: $ssh_username@$ssh_server" | awk '{ print $1 }'`
    kill `ps -U "$local_username" | grep dns-sd | grep "$share_name" | awk '{ print $1 }'`
    ssh -p 22 -fNL :36890: "$ssh_username@$ssh_server"
    dns-sd -R "$share_name" _daap._tcp local 36890 &