Skip to content

Instantly share code, notes, and snippets.

@paceline
Last active December 21, 2015 00:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paceline/6218520 to your computer and use it in GitHub Desktop.
Save paceline/6218520 to your computer and use it in GitHub Desktop.
Run Shairport AirTunes / AirPlay server emulator on a QNAP NAS.

Prerequisites

  • QNAP NAS
  • Supported USB sound card

"Solution"

  • First of all install Optware via the QPKG menu
  • Connect to your NAS (e.g. ssh admin@192.168.1.1)
  • Install various software packages with ipkg install xxx (mainly avahi, openssl, and various build tools - refer to my package list shown below)
  • Check out Shairport from github: git clone https://github.com/abrasive/shairport.git
  • Unzip and cd into the directory
  • Edit the Makefile, inserting "CC:=gcc" at the top
  • Run ./configure
  • Run make clean all
  • Manually copy freshly compiled "shairport" binary to /opt/bin and make executable (chmod 0755 /opt/bin/shairport)
  • Create a startup file in /opt/etc/init.d, configure to taste and make executable (mine is shown below)
  • Run to see if everything works fine (e.g. /opt/etc/init.d/S30shairport start). You should see your newly configures speakers pop up in iTunes or Music on your iOS devices
  • Make your QNAP launch Shairport at start up by following this guide here or replace your /etc/init.d/Optware.sh file with my version below

I had to try various approaches before getting right. Finally, this one here worked for me (BTW: I use a QNAP TS-219P w/ 3.8.2 Build 2013030 firmware)

#!/bin/sh
RETVAL=0
QPKG_NAME="Optware"
_exit()
{
/bin/echo -e "Error: $*"
/bin/echo
exit 1
}
# Determine BASE installation location according to smb.conf
BASE=
publicdir=`/sbin/getcfg Public path -f /etc/config/smb.conf`
if [ ! -z $publicdir ] && [ -d $publicdir ];then
publicdirp1=`/bin/echo $publicdir | /bin/cut -d "/" -f 2`
publicdirp2=`/bin/echo $publicdir | /bin/cut -d "/" -f 3`
publicdirp3=`/bin/echo $publicdir | /bin/cut -d "/" -f 4`
if [ ! -z $publicdirp1 ] && [ ! -z $publicdirp2 ] && [ ! -z $publicdirp3 ]; then
[ -d "/${publicdirp1}/${publicdirp2}/Public" ] && BASE="/${publicdirp1}/${publicdirp2}"
fi
fi
# Determine BASE installation location by checking where the Public folder is.
if [ -z $BASE ]; then
for datadirtest in /share/HDA_DATA /share/HDB_DATA /share/HDC_DATA /share/HDD_DATA /share/MD0_DATA; do
[ -d $datadirtest/Public ] && BASE="$datadirtest"
done
fi
if [ -z $BASE ] ; then
echo "The Public share not found."
_exit 1
fi
QPKG_DIR=${BASE}/.qpkg/Optware
case "$1" in
start)
if [ `/sbin/getcfg ${QPKG_NAME} Enable -u -d FALSE -f /etc/config/qpkg.conf` = UNKNOWN ]; then
/sbin/setcfg ${QPKG_NAME} Enable TRUE -f /etc/config/qpkg.conf
elif [ `/sbin/getcfg ${QPKG_NAME} Enable -u -d FALSE -f /etc/config/qpkg.conf` != TRUE ]; then
_exit "${QPKG_NAME} is disabled."
fi
# Added by Lukas Oesterreicher to enable finding any /opt libraries
/bin/echo "/opt/lib" >> /etc/ld.so.conf
/sbin/ldconfig
/bin/echo "Enable Optware/ipkg"
# sym-link $QPKG_DIR to /opt
/bin/rm -rf /opt
/bin/ln -sf $QPKG_DIR /opt
# determine the architecture
arch=$(/bin/uname -m)
#if not x09 then
if [ "$arch" != "armv5tejl" ]; then
#sym-link the html dir
/bin/ln -sf $QPKG_DIR/html /home/httpd/
#sym-link the management website to /(Q)Web
[ -d /share/Web ] && WebDir="/share/Web"
[ -d /share/Qweb ] && WebDir="/share/Qweb"
[ -d $WebDir/Optware ] || /bin/ln -sf /home/httpd/html/Management $WebDir/Optware
fi
# adding Ipkg apps into system path ...
/bin/cat /etc/profile | /bin/grep "PATH" | /bin/grep "/opt/bin" 1>>/dev/null 2>>/dev/null
[ $? -ne 0 ] && /bin/echo "export PATH=\$PATH":/opt/bin:/opt/sbin >> /etc/profile
# determine the right feed based on cpu type
case "$(/bin/uname -m)" in
armv5tejl)
#X09 architecture
kmod_feed="http://ipkg.nslu2-linux.org/feeds/optware/tsx09/cross/unstable"
modelrange="tsx09"
;;
armv5tel)
#X19 architecture
kmod_feed="http://ipkg.nslu2-linux.org/feeds/optware/tsx19/cross/unstable"
modelrange="tsx19"
;;
armv5tel)
#X19 architecture
kmod_feed="http://ipkg.nslu2-linux.org/feeds/optware/tsx19/cross/unstable"
modelrange="tsx19"
;;
x86_64)
#x86 architecture
kmod_feed=""
modelrange="ts509"
;;
i686)
#x86 architecture
kmod_feed=""
modelrange="ts509"
;;
*)
#everyting else
_exit "Unknown CPU architecture, quitting Optware start"
;;
esac
[ -z $kmod_feed ] || /bin/echo "src $modelrange $kmod_feed" > /opt/etc/ipkg/$modelrange-kmod.conf
[ -z $kmod_feed ] || /usr/bin/wget -q $kmod_feed/Packages --spider || /bin/rm -rf /opt/etc/ipkg/$modelrange-kmod.conf
# Start all manually compiled daemons
/opt/etc/init.d/S30shairport start
;;
stop)
/bin/echo "Disable Optware/ipkg"
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
[ -d /share/Web ] && WebDir="/share/Web"
[ -d /share/Qweb ] && WebDir="/share/Qweb"
/bin/rm -f $WebDir/Optware
# Stop all manually compiled daemons
/opt/etc/init.d/S30shairport stop
/bin/sync
/bin/sleep 1
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $RETVAL
adduser - 1.10.3-1 - a multi-call binary for login and user account administration
alsa-lib - 1.0.23-1 - ALSA sound library
alsa-oss - 1.0.17-1 - ALSA sound OSS emulation library
alsa-utils - 1.0.23-1 - ALSA utils
audiofile - 0.2.6-6 - Misc Audio Libraries.
autoconf - 2.69-1 - Creating scripts to configure source code packages using templates
automake - 1.12-1 - Creates GNU standards-compliant Makefiles from template files
avahi - 0.6.30-1 - A system for multicast DNS service discovery, an implementation of Zeroconf.
bash - 3.2.49-1 - A bourne style shell
binutils - 2.19.1-1 - The GNU assembler and linker and related tools
bzip2 - 1.0.6-1 - Very high-quality data compression program
classpath - 0.98-1 - GNU Classpath for java
cyrus-sasl-libs - 2.1.23-2 - Provides client or server side authentication (see RFC 2222).
dbus - 1.2.16-1 - D-Bus is a message bus system, a simple way for applications to talk to one another.
diffutils - 3.1-1 - contains gnu diff, cmp, sdiff and diff3 to display differences between and among text files
expat - 2.0.1-1 - XML Parser library
faad2 - 2.6-3 - Freeware Advanced Audio Coder
ffmpeg - 0.svn20080409-3 - FFmpeg is an audio/video conversion tool.
file - 5.12-1 - Ubiquitous file identification utility.
flac - 1.2.1-1 - FLAC is a free lossless audio codec. This package contains the codec libraries and the command-line tools flac and metaflac.
freetype - 2.3.6-1 - Free truetype library
gawk - 4.0.1-1 - Gnu AWK interpreter
gcc - 4.2.3-1 - The GNU Compiler Collection.
gconv-modules - 2.5-1 - Provides gconv modules missing from the firmware. These are used by glibc iconv() implementation.
gdbm - 1.8.3-4 - GNU dbm is a set of database routines that use extensible hashing. It works similar to the standard UNIX dbm routines.
gettext - 0.14.5-2 - Set of tools for producing multi-lingual messages
git - 1.8.2.1-2 - GIT is a directory tree content manager that can be used for distributed revision control.
glib - 2.20.4-1 - The GLib library of C routines.
gnupg - 2.0.18-1 - GNU privacy guard - a free PGP replacement.
grep - 2.12-1 - Global regular expression parser
ipkg-web - 7-7 - A web frontend for ipkg
lame - 3.99.5-1 - LAME is an LGPL MP3 encoder.
libao - 0.8.8-1 - Cross Platform Audio Library.
libassuan - 2.0.1-1 - Libassuan is the IPC library used by some GnuPG related software.
libc-dev - 2.5-5 - libc development files.
libcurl - 7.24.0-1 - Curl is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FI
libdaemon - 0.14-1 - A lightweight C library that eases the writing of UNIX daemons.
libdb - 4.2.52-3 - Berkeley DB Libraries
libgcrypt - 1.5.0-1 - GNU cryptography libray, needed by gnutls
libgmp - 4.3.2-1 - GNU Multiple Precision Arithmetic Library.
libgpg-error - 1.10-1 - Error handling library for libgcrypt
libid3tag - 0.15.1b-1 - The library used for ID3 tag reading
libksba - 1.0.3-1 - Libksba is a CMS and X.509 access library.
libmad - 0.15.1b-4 - MPEG Audio Decoder library
libmms - 0.5-1 - A common library for parsing mms:// and mmsh:// type network streams
libmpcdec - 1.2.6-1 - Portable Musepack decoder library.
libnsl - 2.5-4 - Network Services Library
libogg - 1.2.1-1 - Ogg is a multimedia container format.
libpth - 2.0.7-2 - Pth is a very portable POSIX/ANSI-C based library for Unix platforms which provides non-preemptive priority-based scheduling fo
libshout - 2.2.2-2 - Library which can be used to write a source client like ices.
libstdc++ - 6.0.9-6 - Standard C++ library, needed for dynamically linked C++ programs
libtool - 1.5.26-1 - Library tools.
libusb - 0.1.12-2 - Library for interfacing to the USB subsystem.
libvorbis - 1.3.2-1 - Ogg Vorbis compressed audio format.
libvorbisidec - cvs-20050221-2 - libvorbisidec is the integer-only ogg decoder library, AKA Tremor
lynx - 2.8.6-1 - A text browser for the World Wide Web
m4 - 1.4.16-1 - gnu macro processor and compiler front end
make - 3.82-1 - examines files and runs commands necessary for compilation
mpg123 - 1.14.2-1 - Fast console MPEG Audio Player.
ncurses - 5.7-3 - NCurses libraries
ncursesw - 5.7-2 - NCurses libraries with wide char support
openldap-libs - 2.3.43-2 - Open Lightweight Directory Access Protocol
openssl - 0.9.8v-2 - Openssl provides the ssl implementation in libraries libcrypto and libssl, and is needed by many other applications and librari
openssl-dev - 0.9.8v-2 - openssl native development files
patch - 2.6.1-1 - applies a diff to produce a patched file
pcre - 8.31-1 - Perl-compatible regular expression library
perl - 5.10.0-6 - Practical Extraction and Report Language.
perl-compress-zlib - 1.42-3 - Compress-Zlib - Interface to zlib compression library.
perl-html-parser - 3.60-1 - A collection of modules that parse and extract information from HTML documents.
perl-html-tagset - 3.04-4 - This module contains data tables useful in dealing with HTML.
perl-libwww - 5.825-1 - libwww-perl - The World-Wide Web library for Perl
perl-uri - 1.35-3 - URI - <module_description>
pinentry - 0.8.0-1 - A collection of simple PIN or passphrase entry dialogs
pkgconfig - 0.15.0-2 - Package configuration tool
psmisc - 22.17-1 - A set of some small useful utilities that use the proc filesystem.
python27 - 2.7.3-1 - Python is an interpreted, interactive, object-oriented programming language.
rcs - 5.7-2 - The Revision Control System (RCS) manages multiple revisions of files.
readline - 6.1-2 - The GNU Readline library provides a set of functions for use by applications that allow users to edit command lines as they are
sed - 4.2.2-1 - Stream editor.
speex - 1.2rc1-2 - Speex is an Open Source/Free Software patent-free audio compression format designed for speech.
sqlite - 3.7.14.1-1 - SQLite is a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine.
sudo - 1.8.4.5-1 - System utility to execute commands as the superuser
tar - 1.26-1 - heavyweight version of the Tape ARchiver
unrar - 4.2.4-1 - unrar is an application that can decompress files and archives created using the RAR compression scheme
unzip - 6.0-2 - A (de)compression library for the ZIP format
wavpack - 4.50.1-1 - WavPack is a completely open audio compression format providing lossless, high-quality lossy, and a unique hybrid compression m
zlib - 1.2.5-1 - zlib is a library implementing the 'deflate' compression system.
#! /bin/sh
OPTWARE_TARGET=cs08q1armel
# -*- coding: utf-8 -*-
# init.d script for Shairport
# Copyright 2013 Ulf Moehring <ulf@moehring.me>
# Set LD_LIBRARY_PATH if not set already
if [ -z "$LD_LIBRARY_PATH" ]; then
export LD_LIBRARY_PATH=/usr/lib:/opt/lib
fi
DAEMON=/opt/bin/shairport
NAME=Santa-Barbara
PIDFILE=/opt/var/run/shairport.pid
DESC="AirPlay server"
test -x $DAEMON || exit 0
ENABLED=1
PARAMS="-d -a $NAME -o ao"
test "$ENABLED" != "0" || exit 0
start_it_up()
{
if [ -e $PIDFILE ]; then
echo "$DESC already started; not starting."
else
echo -n "Starting $DESC: "
PID=`$DAEMON $PARAMS > /dev/null 2>&1 & echo $!`
if [ -z $PID ]; then
printf "%s\n" "Fail"
else
echo $((PID+1)) > $PIDFILE
printf "%s\n" "Ok"
fi
fi
}
shut_it_down()
{
echo -n "Stopping $DESC: "
if [ -e $PIDFILE ]; then
PID=`cat $PIDFILE`
kill -9 $PID
rm -f $PIDFILE
fi
echo "Ok"
}
case "$1" in
start)
start_it_up
;;
stop)
shut_it_down
;;
restart|force-reload)
shut_it_down
sleep 1
start_it_up
;;
*)
echo "Usage: /opt/etc/init.d/S30shairport {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
@rubbertail
Copy link

Hello,

first, I want to thank you a thousandfold for the detailed description - which enabled even me, a complete novice, to actually set this up. Unfortunately, I was not yet successful completely, and I wondered, whether I might ask your help with the whole thing?
I have a QNAP TS-509 pro myself (Intel-based, with a celeron processor), with the 4.0.3 QNAP firmware. I managed to install all the prerequisites, I also managed to compile Shairport without any error (although I had to put in the CC:=gcc line to make it work), copied the resulting file, made it executable, and also managed to get the startup script up and running. I rejoiced at that time already - but unfortunately iTunes (on Windows) doesn't show the newly created Airplay target.
Could you possibly help me with troubleshooting? I know this is asking a great deal... but I would be ever so grateful... If you could, please let me know what you need to check it all - sorry if this sounds very helpless, but unfortunately I really am.

Thank you very much for considering that!

Martin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment