tag:blogger.com,1999:blog-10049676384185587812024-03-13T03:57:37.864-07:00James Can SpelSharing useful bits of information about various things I've had to configure or build. Well hopefully, I'm just getting started...shamushttp://www.blogger.com/profile/05727327544786752831noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-1004967638418558781.post-43710276088483278632009-09-07T12:21:00.000-07:002019-01-17T22:58:35.662-08:00Accessing a Linux File Server from OS X using AFPI keep most of my data on a low-power Ubuntu server that sits underneath my TV. The data isn't much good to me if I can't access it, so I've mounted the server as a network drive on OS X. This post will show you how to do the same.<br />
<br />
<span style="font-size: x-small;"><i>I first discovered how to set up AFP from <a href="http://www.kremalicious.com/2008/06/ubuntu-as-mac-file-server-and-time-machine-volume/">this article</a> on kermalicious.com. It's slightly out-dated but feel free to go there if you want info direct from the source, especially if you run into issues with these instructions.</i></span><br />
<br />
<span style="font-size: large;">Step 1: Set up Netatalk on the Server</span><br />
<br />
I'm using a server running Ubuntu 9.04 for these instructions.<br />
<br />
Netatalk is the open source version of Apple's AFP (AppleTalk Filing Protocol), which provides remote filesystem access similar to NFS, Samba etc. I've found AFP to integrate a little better with OS X. <a href="http://code.google.com/p/macfuse/wiki/MACFUSE_FS_SSHFS">sshfs</a> is faster, and more secure, but I had trouble getting it to reliably automount.<br />
<br />
First install Netatalk. It comes out-of-the-box with encrypted authentication these days, so no need to compile your own.<br />
<div style="font-family: "Courier New",Courier,monospace;">sudo apt-get install netatalk</div><br />
Now configure AFP services by editing <span style="font-family: 'Courier New', Courier, monospace;">/etc/default/netatalk</span> to contain only the necessary daemons (<span style="font-family: 'Courier New', Courier, monospace;">CNID_METAD</span> and <span style="font-family: 'Courier New', Courier, monospace;">AFPD</span>):<br />
<span style="font-family: 'Courier New', Courier, monospace;">ATALKD_RUN=no</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">PAPD_RUN=no</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">CNID_METAD_RUN=yes</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">AFPD_RUN=yes</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">TIMELORD_RUN=no</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">A2BOOT_RUN=no</span><br />
the rest of the defaults should be fine.<br />
<br />
The last bit of Netatalk configuration is in <span style="font-family: 'Courier New', Courier, monospace;">/etc/netatalk/afpd.conf</span>. Set the last line of the file to the following:<br />
<div style="font-family: "Courier New",Courier,monospace;">- -transall -uamlist uams_dhx2.so -nosavepassword</div><br />
This ensures that we only use Diffie-Hellman key exchange (DHX) for authentication, rather than plaintext passwords or something silly like that. <br />
<br />
<span style="font-size: large;">Step 2: Set up Shared Volumes</span><br />
<br />
Did I say that was the last bit of configuration? I lied, kinda. We need to configure the volumes we wish to share via AFP - right now our server speaks AFP, but it doesn't have anything to share. This is done by editing the file <span style="font-family: 'Courier New', Courier, monospace;">/etc/netatalk/AppleVolumes.default</span>.<br />
<br />
Each volume you wish to share goes on a line at the bottom of this file. By default all users will be able to access their own home directories (<span style="font-family: 'Courier New', Courier, monospace;">~/ "Home Directory"</span>), but you can change that to the following:<br />
<span style="font-family: 'Courier New', Courier, monospace;">~/ "$u" options:usedots,upriv</span><br />
<br />
The <span style="font-family: 'Courier New', Courier, monospace;">"$u"</span> will call Bob's home directory "Bob" rather than "Home Directory". The <span style="font-family: 'Courier New', Courier, monospace;">usedots</span> option is necessary if you want to use "invisible" dot files (such as <span style="font-family: 'Courier New', Courier, monospace;">.profile</span>), and <span style="font-family: 'Courier New', Courier, monospace;">upriv</span> adds support for unix privileges (but apparently has problems with OS X Tiger or older).<br />
<br />
You can have other volumes shared - I have the following:<br />
<div style="font-family: "Courier New",Courier,monospace;">/home/cowling/TimeMachine TimeMachine allow:cowling options:usedots,upriv<br />
/home/media Media allow:cowling,media options:usedots,upriv</div><br />
Now restart netatalk and we should be set!<br />
<span style="font-family: 'Courier New', Courier, monospace;">sudo /etc/init.d/netatalk restart</span><br />
<br />
<span style="font-size: large;">Step 3: Connect to the Remote Volume on OS X</span><br />
<br />
This should be pretty straight-forward. In Finder go to Go -> Connect to Server..., enter <span style="font-family: 'Courier New', Courier, monospace;">afp://servername</span>, your username and password, and hopefully it all works!<br />
<br />
If you want to access a volume from behind a NAT/firewall, you'll need to forward/open port 548.<br />
<br />
If you don't want OS X putting <span style="font-family: 'Courier New', Courier, monospace;">.DS_Store</span> files in every folder you access (you probably don't), you can turn these off for remote volumes by running the following in the OS X terminal: <br />
<div style="font-family: "Courier New",Courier,monospace;">defaults write com.apple.desktopservices DSDontWriteNetworkStores true</div><br />
<span style="font-size: large;">Optional: Automatic Discovery using Bonjour/Avahi</span><br />
<br />
As in the last post on setting up <a href="http://jamescanspel.blogspot.com/2009/08/setting-up-music-streaming-server-using.html">music server</a>, you need to set up Avahi if you want OS X to automatically detect shared volumes on your local network, and pop them up in the Finder side panel.<br />
<br />
First install Zeroconf/Avahi if you haven't already:<br />
<span style="font-family: 'Courier New', Courier, monospace;">sudo apt-get install avahi-daemon </span><br />
<br />
Set up the AFP service by creating a file<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;"> </span>/etc/avahi/services/afpd.service </span>containing:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;"><?xml version="1.0" standalone='no'?><br />
<!DOCTYPE service-group SYSTEM "avahi-service.dtd"><br />
<service-group><br />
<name replace-wildcards="yes">%h</name><br />
<service><br />
<type>_afpovertcp._tcp</type><br />
<port>548</port><br />
</service><br />
<service><br />
<type>_device-info._tcp</type><br />
<port>0</port><br />
<txt-record>model=Xserve</txt-record><br />
</service><br />
</service-group></span><br />
<br />
and restart avahi:<br />
<div style="font-family: "Courier New",Courier,monospace;">sudo /etc/init.d/avahi-daemon restart</div><br />
If you have a firewall that's blocking Avahi, you'll want to open port 5353. There's not much point forwarding this port on a NAT, since Avahi only works within a local network.<br />
<br />
If all went well, your server will show up in the panel on the left of the Finder window. Yay, we're done! As always, let me know if you encounter any errors with these instructions.<br />
<br />
Have fun.<br />
<br />
Jamesshamushttp://www.blogger.com/profile/05727327544786752831noreply@blogger.com4tag:blogger.com,1999:blog-1004967638418558781.post-2378737605433167792009-08-31T19:32:00.000-07:002019-01-17T22:59:31.185-08:00Setting up an Ubuntu Music Streaming Server using FireflyIf you're like me, you probably:<br />
<ul><li>have too much music to fit on your laptop HD</li>
<li>end up storing your music on an external HD but hate carrying it around everywhere</li>
<li>want to listen to your music from your other computers</li>
<li>have access to a linux server somewhere</li>
</ul><br />
If you're lucky, those are the only things you have in common with me. If so, great, I'm going to show you how to serve music from a linux machine.<br />
<br />
Now there are a few caveats before I start:<br />
<ul><li>you'll want to have a decently fast network connection</li>
<li>it's nicer to look at your neatly-categorized music locally through iTunes cover browser interface than as a shared library</li>
<li>your library won't maintain play counts etc, and I haven't tried using ratings</li>
<li>I don't have a perfect solution for syncing an iPod/iPhone, but there are some half-baked solutions you can look into</li>
</ul><br />
I'm going to assume the laptop you're using is a Mac and the linux box is running Ubuntu 9.04 or greater, but most of these instructions should translate somewhat to other OS's/distros.<br />
<br />
Oh yeah, and before you do any of this stuff, <b>back up your music</b>. No one wants to make a mistake and lose years of collected tracks.<br />
<br />
<b><span style="font-size: large;">Step 0: Clean up your Library</span></b><br />
<br />
Now is a really good time to clean up your library: get rid of the old crap you don't listen to, fix your ID3 tags, add album art, replace missing songs in albums etc. I just deleted my iTunes library file and selectively added back music one album at a time when I wanted to listen to it, and have since become a bit obsessive about keeping my library organized. I lost my playlists etc, but they were all a mess anyway. You could back up this stuff if you want.<br />
<br />
iTunes doesn't have art for a bunch of my music, so I used <a href="http://www.widget-foundry.com/widgets/amazonart.htm">this widget</a> to pull art off Amazon.<a class="urlextern" href="http://www.widget-foundry.com/widgets/amazonart.htm" rel="nofollow" title="http://www.widget-foundry.com/widgets/amazonart.htm"></a><br />
<br />
<b><span style="font-size: large;">Step 1: Install Firefly</span></b><br />
<br />
I'm assuming you have a working Ubuntu installation and you know your way around the command line.<br />
<br />
Firefly (also known as mt-daapd) is the program that exports your library as a DAAP stream, which is Apple's protocol for iTunes media sharing. Apple have changed the protocol in recent versions of iTunes to make it incompatible with other programs, but Firefly uses a version of the protocol that works fine.<br />
<br />
Install Firefly (mt-daapd):<br />
<span style="font-family: 'Courier New',Courier,monospace;">sudo apt-get install mt-daapd</span><br />
<br />
Now edit <span style="font-family: 'Courier New',Courier,monospace;">/etc/mt-daapd.conf</span> to your liking. The defaults are a good start, but you'll want to change <span style="font-family: 'Courier New',Courier,monospace;">admin_pw</span>, <span style="font-family: 'Courier New',Courier,monospace;">mp3_dir</span>, <span style="font-family: 'Courier New',Courier,monospace;">servername</span> and <span style="font-family: 'Courier New',Courier,monospace;">password</span>. You can change many of these settings through the web interface once you get going. I created a new user account named "media" to store my media on the server, added myself to the "media" group, and pointed <span style="font-family: 'Courier New',Courier,monospace;">mp3_dir</span> to <span style="font-family: 'Courier New',Courier,monospace;">/home/media/music</span>, but do as you please. <span style="font-family: 'Courier New',Courier,monospace;">servername</span> is whatever you want your stream to be listed as in iTunes. <span style="font-family: 'Courier New',Courier,monospace;">admin_pw</span> is the password used to access the web configuration interface, while <span style="font-family: 'Courier New',Courier,monospace;">password</span> is just the password people need to enter to listen to your shared library.<br />
<br />
Now restart Firefly:<br />
<span style="font-family: 'Courier New',Courier,monospace;">sudo /etc/init.d/mt-daapd restart</span><br />
<br />
If this worked so far, you should be able to access the web configuration interface at <span style="font-family: 'Courier New',Courier,monospace;">http://servername:3689</span><span style="font-family: inherit;">. Make sure you forward port 3689 on your router (if you're behind a NAT), and open that port on your firewall (if you have one).</span><br />
<br />
<b><span style="font-size: large;">Step 2: Connect to your Shared Library</span></b><br />
<br />
Now the exciting part.<br />
<br />
We can't connect to the stream in iTunes yet, but we can with any other program that connects to DAAP streams. I use Songbird, which I'm hoping to fully transition over to from iTunes at some stage.<br />
<br />
Install <a href="http://www.getsongbird.com/">Songbird</a> and the <a href="http://addons.songbirdnest.com/addon/1355">Songbird Daap Client</a> add-on. Then go to File -> New DAAP library, type in <span style="font-family: 'Courier New',Courier,monospace;">daap://servername:3689</span>, and it should load your library in Songbird!<br />
<br />
Wait wait, that wasn't very exciting - we haven't added any music yet! We'll get to that now.<br />
<br />
<b><span style="font-size: large;">Step 3: Move Your Music to Your Server</span></b><br />
<br />
Your music might be neatly organized, but if you're using iTunes, all your album art is sitting in a separate database file. I used <a href="http://dougscripts.com/itunes/scripts/ss.php?sp=embedart">this Applescript</a> to embed all the art back into the ID3 tags.<br />
<br />
Now just copy your music folder across to your server, using rsync, scp, or from an external HD. (One day I'll post an article about mounting an HFS+ formatted HD in linux.)<br />
<br />
I came across one small complication here: mp3 files have two types of ID3 tags - v1 and v2. iTunes writes tag information to the ID3v2 tag, but ignores the ID3v1 tag, which can leave bad tag data lying around to confuse other programs. I fixed this problem in bulk by stripping away the ID3v1 tags using a program called id3v2.<br />
<br />
<span style="font-family: 'Courier New',Courier,monospace;">sudo apt-get install id3v2</span><br />
<span style="font-family: 'Courier New',Courier,monospace;">id3v2 -s *.mp3</span><br />
<span style="font-family: 'Courier New',Courier,monospace;">id3v2 -s *.m4a </span><br />
<br />
I didn't lose any useful tag data this way. If you want to be on the safe side, you can select your mp3s in iTunes, right-click, select Convert ID3 Tags, and convert the tags to v2.3.<br />
<br />
<b><span style="font-size: large;">Step 4: Enable iTunes Sharing</span></b><br />
<br />
Are you sure you still want to use iTunes? Okay, I still do, but bear in mind that you can only connect to your library if you're on the same subnet. There are ways around accessing libraries on different networks, but you're better off just using Songbird in this case.<br />
<br />
iTunes doesn't just let you type in the location of a DAAP share - that would be too easy. Instead it uses Zeroconf (Bonjour) to automatically discover shared libraries on your network. What we need to do is set up the Ubuntu server to advertise Zeroconf services using Avahi. This can also be used to advertise a network drive from the server,but that's the topic of another discussion.<br />
<br />
First install Avahi:<br />
<span style="font-family: 'Courier New',Courier,monospace;">sudo apt-get install avahi-daemon</span><br />
<br />
At the time of writing, there's a <a href="https://bugs.launchpad.net/ubuntu/+source/mt-daapd/+bug/343069">race condition</a> between Avahi and Firefly in the current Ubuntu packages. This sometimes prevents Firefly from loading. The bug can be fixed by applying the following patch<br />
<br />
for 32 bit:<br />
<span style="font-family: 'Courier New',Courier,monospace;">wget http://launchpadlibrarian.net/26549308/mt-daapd_0.9%7Er1696.dfsg-9_i386.deb</span><br />
<span style="font-family: 'Courier New',Courier,monospace;">sudo dpkg -i mt-daapd_0.9%7Er1696.dfsg-9_i386.deb</span><br />
<br />
or for 64 bit:<br />
<span style="font-family: 'Courier New',Courier,monospace;">wget http://launchpadlibrarian.net/26923010/mt-daapd_0.9%7Er1696.dfsg-9ubuntu1_amd64.deb</span><br />
<span style="font-family: 'Courier New',Courier,monospace;">sudo dpkg -i mt-daapd_0.9~r1696.dfsg-9ubuntu1_amd64.deb</span><br />
<br />
Hopefully this bug will be fixed in Ubuntu 9.10.<br />
<br />
Now create a file <span style="font-family: 'Courier New',Courier,monospace;">/etc/avahi/services/mt-daapd.service</span> containing:<br />
<br />
<span style="font-family: 'Courier New',Courier,monospace;"><?xml version="1.0" standalone='no'?><br />
<!DOCTYPE service-group SYSTEM "avahi-service.dtd"><br />
<service-group><br />
<name replace-wildcards="yes">%h</name><br />
<service><br />
<type>_daap._tcp</type><br />
<port>3689</port><br />
<txt-record>txtvers=1</txt-record><br />
<txt-record>iTSh Version=131073</txt-record><br />
<txt-record>Version=196610</txt-record><br />
</service><br />
</service-group></span><br />
<br />
Restart Avahi:<br />
<span style="font-family: 'Courier New',Courier,monospace;">sudo /etc/init.d/avahi-daemon restart</span><br />
<br />
and your DAAP share should pop up in the iTunes sidebar on any of the computers in your local network.<br />
<br />
<b><span style="font-size: large;">Step 5: Listen to Some Music</span></b><br />
<br />
Are we done? I hope so! If I've left something out, or made an error, please let me know in the comments. Bear in mind that I might not have time to help with specific problems.<br />
<br />
Jamesshamushttp://www.blogger.com/profile/05727327544786752831noreply@blogger.com5