Skip to content

Instantly share code, notes, and snippets.

@thorsteneckel
Last active March 8, 2019 13:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thorsteneckel/c0610fb415c8d0486bce to your computer and use it in GitHub Desktop.
Save thorsteneckel/c0610fb415c8d0486bce to your computer and use it in GitHub Desktop.
ejurgensen/forked-daapd on FreeBSD 10.1
#!/bin/sh
# PROVIDE: forked-daapd
# REQUIRE: avahi_daemon dbus
# Add the following lines to /etc/rc.conf to enable `forked-daapd':
#
# forked_daapd_enable="YES"
# forked_daapd_flags="<set as needed>"
. /etc/rc.subr
name="forked_daapd"
rcvar=`set_rcvar`
command="/usr/local/sbin/forked-daapd"
command_args=""
pidfile="/var/run/forked-daapd.pid"
required_files="/usr/local/etc/forked-daapd.conf"
# read configuration and set defaults
load_rc_config "$name"
: ${forked_daapd_enable="NO"}
run_rc_command "$1"

forked-daapd on FreeBSD 10.1

These are my steps installing 'ejurgensen/forked-daapd' on my FreeBSD 10.1 amd64 using user root and editor joe. Feedback would be great!

create working folder

export WORKDIR=/usr/local/src/forked-daapd
mkdir -p $WORKDIR
cd $WORKDIR

install dependencies

from pkg repository

# maybe 'pkg install automake' ?
pkg install gmake libantlr3c autoconf libtool gettext gperf glib libconfuse libevent2 mxml libgcrypt taglib libunistring libplist openjdk8-jre libiconv avahi-app avahi sqlite3 yasm pkgconf

OpenJDK fdescfs and procfs

This OpenJDK implementation requires fdescfs(5) mounted on /dev/fd and procfs(5) mounted on /proc.

If you have not done it yet, please do the following:

mount -t fdescfs fdesc /dev/fd
mount -t procfs proc /proc

To make it permanent, you need the following lines in /etc/fstab:

fdesc   /dev/fd         fdescfs         rw      0       0
proc    /proc           procfs          rw      0       0

create soundcard link ( you might want to install 'oss'? )

mkdir -p /usr/local/lib/oss/include/sys/
ln -sf /usr/include/sys/soundcard.h /usr/local/lib/oss/include/sys/

libavl_0.3.5

download and extract

cd $WORKDIR
curl -O http://www.debian.co.il/debian/pool/main/liba/libavl/libavl_0.3.5.orig.tar.gz
tar xzvf libavl_0.3.5.orig.tar.gz
cd avl-0.3.5

maybe fix GNUmakefile?

There might be an error in the 'GNUmakefile' of AVL while installing with make. Here is the fix: Change all $(LIBRARIES) variables to $(LIBRARY) in 'GNUmakefile'.

joe GNUmakefile

compile and install

gmake CC=clang CFLAGS=-fPIC
gmake install


antlr3

cd $WORKDIR
mkdir antlr3
cd antlr3
curl -O https://raw.githubusercontent.com/antlr/website-antlr3/gh-pages/download/antlr-3.4-complete.jar
mv antlr-3.4-complete.jar /usr/local/share/java/antlr-3.4-complete.jar
cd $WORKDIR
cd antlr3
echo '#!/bin/sh' > antlr3
echo 'export CLASSPATH' >> antlr3
echo 'CLASSPATH=$CLASSPATH:/usr/local/share/java/antlr-3.4-complete.jar:/usr/share/java /usr/local/openjdk8/bin/java org.antlr.Tool $*' >> antlr3
#echo exec /usr/local/bin/java -cp /usr/local/share/java/antlr-3.3-complete.jar org.antlr.Tool \"\$@\" >> antlr3
chmod u+x antlr3
mv antlr3 /usr/local/bin/antlr3

libantlr3c

cd $WORKDIR
#curl -O http://www.antlr3.org/download/C/libantlr3c-3.2.tar.gz
curl -O https://raw.githubusercontent.com/antlr/website-antlr3/gh-pages/download/C/libantlr3c-3.4.tar.gz
tar xzvf libantlr3c-3.4.tar.gz
cd libantlr3c-3.4
./configure --enable-64bit
gmake
gmake install

ffmpeg or libav

ffmpeg 2.3.3 from ports

If you might want aac support. Grab a cup of coffee - this might take a while.

# maybe 'pkg remove automake' ?
cd /usr/ports/multimedia/ffmpeg
make config
make install clean

libav 11.2 from ports

cd /usr/ports/multimedia/libav
make config
make install clean

ejurgensen/forked-daapd

compile and install

cd $WORKDIR
git clone https://github.com/ejurgensen/forked-daapd.git
cd forked-daapd
autoreconf -iv -Wno-portability
CFLAGS="-march=native -O2 -pipe" LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include ./configure --localstatedir=/var --with-oss4=/usr/local/lib/oss/include/sys --enable-itunes --enable-lastfm
gmake
gmake install

configure environment

backup and customize config

cp /usr/local/etc/forked-daapd.conf /usr/local/etc/forked-daapd.conf.sample
joe /usr/local/etc/forked-daapd.conf

add user and set permissions

useradd daapd
chown daapd:daapd /var/cache/forked-daapd

enable startup

joe /etc/rc.conf
dbus_enable="YES"
avahi_daemon_enable="YES"
forked_daapd_enable="YES"

rc.d script

open/create file
joe /usr/local/etc/rc.d/forked-daapd
insert attached file 'forked-daapd'
set permissions
chmod u+x /usr/local/etc/rc.d/forked-daapd
@transistorgrab
Copy link

thanks for the manual. however I'm stuck at installing/compiling ejurgensen/forked-daapd.
I get an error:

checking for ZLIB... no
configure: error: Package requirements ( zlib ) were not met:

Package zlib was not found in the pkg-config search path.
Perhaps you should add the directory containing 'zlib.pc'
to the PKG_CONFIG_PATH environment variable
Package 'zlib', required by 'world', not found
zlib.pc is clearly not installed on FreeBSD 9.3 (locate cannot find it) and I find no package/port that provides it. Any hint on this? Is this provided as standard on FreeBSD 10?

OK, after some searching I found this solution:
changing the line for configure to this resulted in a successful configure run:
CFLAGS="-march=native -O2 -pipe" ZLIB_CFLAGS="-I/usr/include" ZLIB_LIBS="-L/usr/lib -lz" LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include ./configure --localstatedir=/var --with-oss4=/usr/local/lib/oss/include/sys --enable-itunes --enable-lastfm

Relevant part is: ZLIB_CFLAGS="-I/usr/include" ZLIB_LIBS="-L/usr/lib -lz"

after that gmake crashed with this message:

Making all in src
gmake[2]: Entering directory '/root/forked-daapd/src'
antlr3 -depend SMARTPL2SQL.g > SMARTPL2SQL.u
/usr/local/bin/antlr3: /usr/local/openjdk8/bin/java: not found
antlr3 -depend SMARTPL.g > SMARTPL.u
/usr/local/bin/antlr3: /usr/local/openjdk8/bin/java: not found
antlr3 -depend DAAP2SQL.g > DAAP2SQL.u
/usr/local/bin/antlr3: /usr/local/openjdk8/bin/java: not found
antlr3 -depend DAAP.g > DAAP.u
/usr/local/bin/antlr3: /usr/local/openjdk8/bin/java: not found
antlr3 -depend RSP2SQL.g > RSP2SQL.u
/usr/local/bin/antlr3: /usr/local/openjdk8/bin/java: not found
antlr3 -depend RSP.g > RSP.u
/usr/local/bin/antlr3: /usr/local/openjdk8/bin/java: not found

obviosly openjdk8 was installed in openjdk8-jre
ln -s openjdk8-jre/ openjdk8 in /usr/local/ resolved that problem…

But after receiving:

forked_daapd-cache.o: In function `cache_init':
cache.c:(.text+0x2d9): undefined reference to `pipe2'
cache.c:(.text+0x2f2): undefined reference to `pipe2'
forked_daapd-filescanner.o: In function `filescanner_init':
filescanner.c:(.text+0x25a): undefined reference to `pipe2'
filescanner.c:(.text+0x2c3): undefined reference to `pipe2'
forked_daapd-remote_pairing.o: In function `remote_pairing_init':
remote_pairing.c:(.text+0x17c): undefined reference to `pipe2'
forked_daapd-httpd.o:httpd.c:(.text+0x142): more undefined references to `pipe2' follow
Makefile:596: recipe for target 'forked-daapd' failed
gmake[3]: *** [forked-daapd] Error 1

I'm out of my league. Giving up for now… :-/

@markbrookes
Copy link

Hi,
Did you manage to resolve your last issue. Ie pipe2 undefined.

I have just gone thru the same on a FreeNAS FreeBSD 9.3 jail.

Due to pipe2 not being available unless you are on FreeBSD 10+ I managed to resolve this by using gnulib and importing pipe2 into the build tree.

Let me know if you need the steps that I followed.

Regards

@laiclair
Copy link

Yes, i'm doing same as you, building a jail on freenas.
And i'm currently running the same issue. Can you please provide the steps you've followed.
Thanks,

@markbrookes
Copy link

Hi laiclair,

I have done a new install of a freenas jail and captured the steps I used below.

1. Create a new standard jail and edit the network to ensure the jail has internet access.

2. ssh into your FreeNAS server and connect to the new jail. Use the jls command to find the JID of the jail that you just created.

3. jexec "JID" tcsh. "JID" is from the above command.

jexec 13 tcsh

4. edit /etc/rc.conf and enable SSH by changing.

sshd_enable="NO" to sshd_enable="YES"

5. Update the jail and install sudo.

pkg update
pkg upgrade
pkg install sudo

6. Add a new user to the system, use the "adduser" command. Note the user "daapd" is used for these instructions.

adduser

*7. Add the new user to the sudo system by using the "visudo" command and append the following line and exit from the editor. (Using the user you created above)
*

daapd ALL=(ALL) ALL

8. Exit from the jail and restart.

9. ssh directly into your jail. (Example user: daapd).

ssh daapd@"ip address of jail"

10. Grab "forked-daapd" from git.

$ git clone https://github.com/ejurgensen/forked-daapd.git

11. Change to the scripts folder and setup the enviroment for the 1st pass.

$ cd forked-daapd/scripts
$ pwd
/home/daapd/forked-daapd/scripts

$ export ZLIB_CFLAGS=-I/usr/include
$ export ZLIB_LIBS=-L/usr/lib

12. Edit the installer script by changing "--mode=755" to "-m 755".

"freebsd_install_10.1.sh"

From "sudo install --mode=755 antlr3 /usr/local/bin"

To "sudo install -m 755 antlr3 /usr/local/bin"

From "sudo install --mode=755 scripts/freebsd_start_10.1.sh /usr/local/etc/rc.d/forked-daapd"

To "sudo install -m 755 scripts/freebsd_start_10.1.sh /usr/local/etc/rc.d/forked-daapd"

13. Run the installer.

$ pwd
/home/daapd/forked-daapd/scripts

$ ./freebsd_install_10_1.sh

Continue? [y/N] y

A list of packages are shown that are required.
Should the script install these packages? [y/N] y

Java is required.
Should the script install openjdk8-jre for you? [y/N] y

As we are running in a jail I said 'n' to the following question.

Should the script add the mount points to /etc/fstab that openjdk8-jre requests ? [y/N] n

Should the script create /root/forked-daapd_build and use it for building? [Y/n] y

Should the script install antlr and libantlr3c? [y/N] y

My system is 64 bit so I said 'y'
Should the script build libantlr3c for 64 bit? [Y/n] y

Should the script build forked-daapd? [y/N] y

This build should fail with undefined reference to 'pipe2', we will fix this up later.

Should the script install forked-daapd and add service startup scripts? [y/N] n

Should the script enable and start dbus and avahi-daemon? [y/N] y

Should the script (re)start forked-daapd and display the log output? [y/N] n

14. We need to fixup the build environment to add the 'pipe2' syscall that is missing from FreeBSD 9.x

$ cd ~/forked-daapd_build/forked-daapd/
$ pwd
/home/daapd/forked-daapd_build/forked-daapd
$ sudo pkg install gnulib
$ gnulib-tool --import pipe2

15. As per the message that gnulib-tool printed we need to make some changes to a few files. Below is the diff of the changes.

Makefile.am

*** Makefile.am Fri Feb 5 20:32:27 2016
--- /home/daapd/changes/Makefile.am Fri Feb 5 20:27:53 2016

*** 1,11 ****
ACLOCAL_AMFLAGS = -I m4

sysconf_DATA = forked-daapd.conf

! EXTRA_DIST = configure
! SUBDIRS = sqlext src

man_MANS = forked-daapd.8

install-data-hook:
$(MKDIR_P) $(DESTDIR)$(localstatedir)/cache/forked-daapd/libspotify
--- 1,16 ----
ACLOCAL_AMFLAGS = -I m4

sysconf_DATA = forked-daapd.conf

! EXTRA_DIST = m4/gnulib-cache.m4 configure
! SUBDIRS = lib sqlext src
!
! AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
! AM_LDFLAGS = -Ilib
!
! LDADD = $(top_srcdir)/lib/libgnu.a

man_MANS = forked-daapd.8

install-data-hook:
$(MKDIR_P) $(DESTDIR)$(localstatedir)/cache/forked-daapd/libspotify
$

configure.ac

*** configure.ac Fri Feb 5 20:32:27 2016
--- /home/daapd/changes/configure.ac Fri Feb 5 20:28:16 2016

*** 2,17 ****
--- 2,19 ----

AC_INIT([forked-daapd], [23.4])
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
! AC_CONFIG_FILES([lib/Makefile])
AM_INIT_AUTOMAKE([foreign -Wno-portability subdir-objects])

AC_USE_SYSTEM_EXTENSIONS

dnl Checks for programs.
AC_PROG_CC
! gl_EARLY
AM_PROG_CC_C_O
LT_INIT([disable-static])

AC_CHECK_PROG(GPERF, [gperf], [gperf])
if test "x$GPERF" = x; then

*** 34,43 ****
--- 36,48 ----
AC_SUBST(ANTLR)
AM_CONDITIONAL(COND_ANTLR, test "x$ANTLR" != x)

CFLAGS="$CFLAGS -Wall -D_LARGEFILE_SOURCE"

! dnl # For gnulib
! gl_INIT
!
AC_CHECK_HEADERS([sys/wait.h])
AC_CHECK_HEADERS([sys/param.h])
AC_CHECK_HEADERS([sys/select.h])
AC_CHECK_HEADERS([dirent.h])
AC_CHECK_HEADERS([regex.h])
$

src/Makefile.am

*** src/Makefile.am Fri Feb 5 20:32:27 2016
--- /home/daapd/changes/src/Makefile.am Fri Feb 5 20:28:39 2016

*** 61,70 ****
--- 61,71 ----
@CONFUSE_CFLAGS@ @MINIXML_CFLAGS@ @LIBPLIST_CFLAGS@
@LIBGCRYPT_CFLAGS@ @GPG_ERROR_CFLAGS@ @ALSA_CFLAGS@ @SPOTIFY_CFLAGS@
@LIBCURL_CFLAGS@

forked_daapd_LDADD = -lrt
! $(top_srcdir)/lib/libgnu.a
@ZLIB_LIBS@ @AVAHI_LIBS@ @SQLITE3_LIBS@ @LIBAV_LIBS@
@CONFUSE_LIBS@ @LIBEVENT_LIBS@
@MINIXML_LIBS@ @ANTLR3C_LIBS@ @LIBPLIST_LIBS@
@LIBGCRYPT_LIBS@ @GPG_ERROR_LIBS@ @ALSA_LIBS@ @LIBUNISTRING@ @SPOTIFY_LIBS@
@LIBCURL_LIBS@
$

$ pwd
/home/daapd/forked-daapd_build/forked-daapd

$ gmake clean
$ autoreconf -vi -Wno-portability

16. Setup the build environment.
$ export CC=cc
$ export LIBUNISTRING_CFLAGS=-I/usr/include
$ export LIBUNISTRING_LIBS=-L/usr/lib
$ export ZLIB_CFLAGS=-I/usr/include
$ export ZLIB_LIBS=-L/usr/lib

$ export CFLAGS="-march=native -O2 -pipe -I/usr/local/include -I/usr/include"
$ export LDFLAGS="-L/usr/local/lib -L/usr/lib"

17. Configure the build environment.
$ pwd
/home/daapd/forked-daapd_build/forked-daapd
$ ./configure

18. Build "forked-daapd".
$ gmake

$ sudo gmake install

$ sudo sed -i -- 's//var/cache//usr/local/var/cache/g' /usr/local/etc/forked-daapd.conf

$ sudo chown -R daapd:daapd /usr/local/var/cache/forked-daapd

$ sudo install -m 755 scripts/freebsd_start_10.1.sh /usr/local/etc/rc.d/forked-daapd

$ sudo sh -c 'echo "forked_daapd_enable="YES"" >> /etc/rc.conf'

$ sudo service forked-daapd start
Starting forked_daapd.
[ LOG] main: Forked Media Server Version 23.4 taking off

$ sudo service forked-daapd status
forked_daapd is running as pid 79448.

19. Change the settings of forked-daapd to match your needs.

20. Restart your jail and check if all is well :)

@sticilface
Copy link

is there any hope you can provide the changed make files... i can't make heads no tails of diff output!

@markbrookes
Copy link

Hi please see below the necessary changes, this is on the assumption that you followed the section above, please note that there are 1 "Makefile.am" the 1 that is located in the main build folder and the 1 that is located in the "src" folder off the main build folder.

Regards

Mark

Makefile.am

Find and edit the "Makefile.am" with the following changes :-

You will have the below in your current file (Starting at LINE 5) :-
EXTRA_DIST = configure
SUBDIRS = sqlext src

**Change the current entries to the below and add the extra lines :-**s :-
EXTRA_DIST = m4/gnulib-cache.m4 configure
SUBDIRS = lib sqlext src

AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
AM_LDFLAGS = -Ilib

LDADD = $(top_srcdir)/lib/libgnu.a

configure.ac

Find and edit the "configure.ac" with the following changes :-

You will have the below in your current file (Starting at LINE 3):-
AC_INIT([forked-daapd], [23.4])
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign -Wno-portability subdir-objects])

Add the changes so that it matches below (1 extra line) :-
AC_INIT([forked-daapd], [23.4])
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([lib/Makefile])
AM_INIT_AUTOMAKE([foreign -Wno-portability subdir-objects])

You will have the below in your current file (Starting at LINE 11):-
dnl Checks for programs.
AC_PROG_CC
AM_PROG_CC_C_O
LT_INIT([disable-static])

Add the changes so that it matches below (1 extra line) :-
dnl Checks for programs.
AC_PROG_CC
gl_EARLY
AM_PROG_CC_C_O
LT_INIT([disable-static])

You will have the below in your current file (Starting at LINE 37):-
CFLAGS="$CFLAGS -Wall -D_LARGEFILE_SOURCE"

AC_CHECK_HEADERS([sys/wait.h])
AC_CHECK_HEADERS([sys/param.h])
AC_CHECK_HEADERS([sys/select.h])
AC_CHECK_HEADERS([dirent.h])
AC_CHECK_HEADERS([regex.h])

Add the changes so that it matches below (3 extra lines, including the blank line) :-
CFLAGS="$CFLAGS -Wall -D_LARGEFILE_SOURCE"

dnl # For gnulib
gl_INIT

AC_CHECK_HEADERS([sys/wait.h])
AC_CHECK_HEADERS([sys/param.h])
AC_CHECK_HEADERS([sys/select.h])
AC_CHECK_HEADERS([dirent.h])
AC_CHECK_HEADERS([regex.h])

src/Makefile.am

You will have the below in your current file (Starting at LINE 66):-
@ZLIB_LIBS@ @AVAHI_LIBS@ @SQLITE3_LIBS@ @LIBAV_LIBS@
@CONFUSE_LIBS@ @LIBEVENT_LIBS@
@MINIXML_LIBS@ @ANTLR3C_LIBS@ @LIBPLIST_LIBS@
@LIBGCRYPT_LIBS@ @GPG_ERROR_LIBS@ @ALSA_LIBS@ @LIBUNISTRING@ @SPOTIFY_LIBS@
@LIBCURL_LIBS@

Add the changes so that it matches below (1 extra line) :-
*$(top_srcdir)/lib/libgnu.a *
@ZLIB_LIBS@ @AVAHI_LIBS@ @SQLITE3_LIBS@ @LIBAV_LIBS@
@CONFUSE_LIBS@ @LIBEVENT_LIBS@
@MINIXML_LIBS@ @ANTLR3C_LIBS@ @LIBPLIST_LIBS@
@LIBGCRYPT_LIBS@ @GPG_ERROR_LIBS@ @ALSA_LIBS@ @LIBUNISTRING@ @SPOTIFY_LIBS@
@LIBCURL_LIBS@

@sticilface
Copy link

ur a genis. That looks like it has worked. thank you.
How easy would it be to turn all this into a package for freenas or pkg?

@markbrookes
Copy link

Glad it worked for you. With regards to turning this into a package, it is something I may look at when I have some spare time.

Regards

Mark

@sticilface
Copy link

That would be ace:)

Seems to all work. The only issue I have is when streaming music via airplay, if i got back to the album view and scroll the music just stops streaming. It is still playing in the remote, i have to pause and then play again and it is fine. And there is nothing in the log, even set to [DEBUG]. does this happen to you?

@sticilface
Copy link

OK, so chickens counted before eggs.

I can't get the remote to pair. This worked fine for version 23.3 which still supported freebsd 9 see owntone/owntone-server#239. but the airplay drops out whenever i browse the lib.

Forked-daapd compile, builds, and seems to run just fine.
I can only pair my iOS remote if i restart forked-daapd, and then i get remote cannot connect to iTunes. check your network settings.
so forked-daapd seems to 1) not pick up the .remote file, unless i restart. 2) then the pairing works. but it doesn't load.

have you had any of these troubles?

@ejurgensen
Copy link

I've added back pipe support and fixed a FreeBSD issue, so some of the above is no longer relevant.

See owntone/owntone-server#239

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