My Raspberry Pi setup

16 Jun 2014

A quickstart for headless Raspbian setup with shairport and WiFi.

Many tutorials for the RPi have a lot of text. I am more of a command line guy which just wants to know the commands. So here is my quickstart for a headless Raspbian setup (version 2014-01-07) with shairport. NB: I use a macbook pro and I don't have any external monitors, so I have to do it headless.

I will follow this tutorial. It uses sudo on places where it shouldn't to and some steps are not needed. Hence my own version of that tutorial. This is completely self contained: we will setup the SD card, then configure the RPi, then install shairport with its dependencies and finally setup a wifi dongle.

Prepping the SD

I first formatted my SD card to give it a name. It then shows up with the command df, as you can see:

~$ df -h
Filesystem                          Size   Used  Avail Capacity  iused    ifree %iused  Mounted on
[...]
/dev/disk1s1                       7.4Gi  2.4Mi  7.4Gi     1%        0        0  100%   /Volumes/RASPBERRY

Now we know it is disk1s1 internally. We want to write to the raw buffer which is called rdisk1 (this is mac specific, I believe). Next we will unmount it, write the image (this will take a while) and eject it.

~$ diskutil unmountDisk /dev/disk1s1
Volume RASPBERRY on disk1s1 unmounted
~$ sudo dd bs=1m if=~/Downloads/2014-01-07-wheezy-raspbian.img of=/dev/rdisk1
2825+0 records in
2825+0 records out
2962227200 bytes transferred in 242.670684 secs (12206778 bytes/sec)
~$ diskutil eject /dev/rdisk1
Disk /dev/rdisk1 ejected

Config

We are now ready to put this in our RPi. Put it in, plug the ethernet cable in and fire it up. It will be ready for usage shortly after. Now we need to know its IP address. I just guessed it (my mac was on 192.168.1.106, so I tried 107) by pinging: ping 192.168.1.107. One of the LEDs will react to the pings, so you're sure it is the right device. Log in (and accept the keys, yadayada):

~$ ssh pi@192.168.1.107
[...]
NOTICE: the software on this Raspberry Pi has not been fully configured. Please run 'sudo raspi-config'

pi@raspberrypi ~ $

Succes!!! We now can continue with the config.

pi@raspberrypi ~ $ sudo raspi-config

First thing you want to do is expanding the filesystem. Then I enabled modest overclocking. I changed the hostname in the advanced settings. Finally I force audio from the 3.5 jack, as that will be my intended use. Hit finish and reboot.

I was a bit surprised to not find any timezone settings in this menu. You can do this yourself:

pi@rabarber ~ $ sudo dpkg-reconfigure tzdata

Look here if you have locale problems.

Shairplay

At this point we are going to install some software. We will follow this tutorial. We are at the point where we update our package list and upgrade the packages (will take several minutes, have you cleaned up your desk already?):

sudo apt-get update
sudo apt-get upgrade

We will use shairport, which depends on perl-net-sdp. Looking at the depencies we reckon we need to install the following Debian packages (we already have build-essential and pkg-config installed). Again this might take a while (now it's time to clean up the other half of your desk).

sudo apt-get install git libao-dev libssl-dev libcrypt-openssl-rsa-perl libio-socket-inet6-perl libwww-perl avahi-utils libmodule-build-perl

Followed by installing the two github projects (you can look for other versions or forks if you like):

git clone https://github.com/njh/perl-net-sdp.git
cd perl-net-sdp
perl Build.PL
./Build
./Build test
sudo ./Build install
cd ..
git clone https://github.com/hendrikw82/shairport.git
cd shairport
make
sudo make install
cd ..

Now we can run it as follows with the name "Rabarber". Open iTunes and select your new airplay device :D! This should just work fine.

shairport.pl -a Rabarber

We want shairport as an service, which starts up at reboot and will also stay active after crashes (it will crash sometimes). We need to daemonize it.

cd shairport
sudo cp shairport.init.sample /etc/init.d/shairport
sudo chmod a+x /etc/init.d/shairport
sudo update-rc.d shairport defaults
sudo vi +22 /etc/init.d/shairport

On line 22 we can specify a name (with the -a flag) as shown above. Once saved, reboot, and check if it's working.

There seems to be a lot of forks of shairplay. The most up to date one seems to be shairport-sync. While the official version seems to be here. I was stupid enough to blindly follow the original tutorial, hence we ended up with an old version.

Wifi

I got my wifi adapter from DealExtreme. It was the cheapest I could find (only 4.30 euro). After plugging in the adapter, the RPi seems to reboot, so wait for a moment and log back in. Install the following and run:

sudo apt-get install wicd-curses
wicd-curses

It should display a list of available networks. Highlight yours and configure it (right arrow). Here you should enter the password and enable autoconnect, hit F10. Now connect with enter. Wait. Since it now uses a different network, the RPi's IP address will probably change, and you'll have to reconnect. Once on wifi, unplug the cable, reboot and see if everything works!

That was all! I or my friends can now stream music from any device to our audio system without any hassle (modulo occasional crashes). I am happy with this setup (and the free RPi from transip).

comments powered by Disqus