<?sphp $this->text('pagetitle') ?>
 
Home of the Squeezebox™ & Transporter® network music players.

How to install SqueezeCenter on your Thecus N5200PRO

From SqueezeboxWiki

Revision as of 16:17, 1 July 2010 by Soulkeeper (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

All the info here will be for SqueezeCenter 7.3, but can be also used for 7.2. I'm preparing a new module based on 7.3, where users can directly replace the SC server by simply untaring a new version into the module directory. Below are the steps needed to make the full module.

Contents

Prerequisites

  • 32-bit Linux machine with basic development tools (ie. beeing able to compile perl from source)
  • perl 5.8.8 compiled without threads (when Configure asks "Build a threading Perl?", answer no)

Intro

I won't go into details on Thecus module structure, here are just a few notes on important things to understand:

  • our SC module will be using omega's Theces perl installation (available on onbeat.dk wiki)
  • additional perl modules are required by SC, and are normally built using the build-perl-modules.pl script in SC Bin directory
  • these perl modules will require some extra libraries, which are not present on Thecus (for example libexpat.so.1 is needed by XML::Parser::Expat)
  • we need to provide any extra binaries which SC might need (like lame, ffmpeg...), and these might need extra libraries as well
  • after we add the missing libraries, we must make sure Thecus knows about them (by setting proper LD_LIBRARY_PATH in SC module startup scripts)

Howto

Even though you can just untar new SC source into my module, I will describe everything here, which will be applicable to all future versions.

Everything is done on the Linux box described in the prerequisites. Make sure you are using the correct perl binary, compiled without threads.

  • Start by downloading my SC 7.3 module (link at the bottom of the page, will be at onbeat.dk when 7.3 is released), since all the files are already in place.

Thecus modules are just tar.gz files, so change .mod into .tgz and unpack it The directory structure is:

 SQUEEZECENTER
 |
 |-Configure/ 
 |-Shell/  <-- holds the install script and the module startup script   
 |-Thecus
 |-system/ <-- will hold the tar.gz of the SC and our extra stuff
 |-www/
  • Download the latest SC source and unpack it somewhere
  • build the perl modules needed by SC by using Bin/build-perl-modules.pl. If the building fails, check the errors, there are probably some perl modules missing in your non-threaded installation. Build and install the missing ones, making sure you are using the correct perl binary again.
  • move the complete CPAN directory from SC source into SQUEEZECENTER/system. We're doing this to be able to use future versions by simply untaring the new source on Thecus, without need for any compilation. However, if future versions of SC require some new perl modules, these will need to be compiled and added to the CPAN directory on Thecus. Make sure the dynamic perl module libraries are included in the CPAN directory. They will be in a directory arch/5.8.8/i686-linux-thread-multi/auto/ whereever you compiled them originally. Move the complete arch directory to SQUEEZEBOX/system/CPAN and just to make sure, make a symbolic link in CPAN to arch/5.8.8/i686-linux-thread-multi/auto/ (ie. "cd SQUEEZEBOX/system/CPAN; ln -s arch/5.8.8/i686-linux-thread-multi/auto/ auto").
  • create directories SQUEEZECENTER/system/addlib and SQUEEZECENTER/system/addbin. Put all the extra binaries into "addbin" (lame,ffmpeg and any other converters which you need). All the dynamic libraries required by the binaries AND by the perl modules go into "addlib". Chech which libraries are required by using the command "ldd". Don't forget to check the perl module libraries requirement (do ldd on all .so files in SQUEEZEBOX/system/CPAN/auto/).
  • create the Custom.pm file in SC source (Slim/Utils/OS/Custom.pm). You can use the version provided below, or write your own. The most important thing it defines is the new scanner. We have to write a wrapper script which will set up the environment and then call the original scanner.pl from SC directory. This script can also go into "addbin". Here is the script I used:
#!/bin/sh

MODDIR=/raid/data/module

PERLDIR=$MODDIR/PERL/perl
SLIMDIR=$MODDIR/SQUEEZECENTER/squeezecenter
CPAN=$MODDIR/SQUEEZECENTER/system/CPAN
ADDLIBS=$MODDIR/SQUEEZECENTER/system/addlib

PERL=$PERLDIR/bin/perl
SCANNER=$SLIMDIR/scanner.pl

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$ADDLIBS"
export PERL5LIB="$CPAN:$PERL5LIB"
exec "$PERL" "$SCANNER" "$@"

The important bits are the setting of proper LD_LIBRARY_PATH and PERL5LIB. Without them, scanner.pl won't work.

  • put all the files from SC source into SQUEEZECENTER/system/squeezecenter. Since we moved the CPAN directory elsewhere, you can remove it from the SC source during future updates.
  • edit the convert.conf in SC directory and set it up as you need (make sure you have the required binaries in "addbin")
  • create the 2 tar.gz archives in SQUEEZECENTER/system/. One will hold the SC source, which is now in the directory "squeezecenter" and the other will hold CPAN, addlib and addbin directories (call it add.tar.gz)
    • cd SQUEEZECENTER/system/; tar -zcf SQUEEZECENTER.tar.gz squeezecenter
    • tar -zcf add.tar.gz addlib addbin CPAN
  • Create/edit the module install script (SQUEEZEBOX/Shell/install.sh). Make sure it extracts both tar.gz files which are in the system directory (SQUEEZECENTER.tar.gz and add.tar.gz). Here is the relevant part from my installation (notice that add.tar.gz is extracted into $modDir/system):
echo "Unpacking $modName tar file..." >>$modLog
tar xzf $modDir/system/$modName.tar.gz -C $modDir >>$modLog 2>&1
rm $modDir/system/$modName.tar.gz >>$modLog 2>&1

echo "Unpacking $modName extras tar file..." >>$modLog
tar xzf $modDir/system/add.tar.gz -C $modDir/system >>$modLog 2>&1
rm $modDir/system/add.tar.gz >>$modLog 2>&1

chown -R nobody.nogroup $modDir/squeezecenter
chown -R nobody.nogroup $modDir/system/

After the archives are there, remove the directories (CPAN, addbin,addlib and squeezecenter)

  • Create/edit the module startup script (SQUEEZEBOX/Shell/module.rc). This script is ran with parameter "start" everytime the module is enabled (or Thecus is rebooted and the module was enabled). The most important parts are the setting of proper LD_LIBRARY_PATH (so it includes our addlib directory) and PERL5LIB (so it includes our CPAN directory). You can also copy Custom.pm into SC directory here, if you plan to simply update the SC source directly in the exiting Thecus installation (my script copies it from addlib). Also, file ownership needs to be set to nobody:nogroup or whichever user/group you want to use for running the server (check the SLIM_ARGS in omega's or my script). Once everything is setup, the actual server is started. In the current script it's done here:
"$PERL_EXE" "$SLIM_HOME/slimserver.pl" $SLIM_ARGS >>"$SLIM_OUT" 2>&1

The script then loops until it sees the 3 processes running (slimserver.pl, mysqld and mDNSResponderPosix) or reports an error if they're not there after $SLIM_MAX_START_TIME tries.

  • finally, create the actual mod file, which is just a regular tar.gz:
tar -zcf SQUEEZECENTER.tar.gz SQUEEZECENTER; mv SQUEEZECENTER.tar.gz SQUEEZECENTER.mod
  • upload the new module using Thecus web interface and hope it works :)
  • to upgrade to new SC release, you can simply replace the files in /raid/data/module/SQUEEZECENTER/squeezecenter/ with the current ones (and copy Custom.pm, if your module startup script doesn't do it)

Known problems

  • m4a files don't play, which is caused by 2 problems:

1. faad beeing stared without proper LD_LIBRARY_PATH. Solve by compiling a static faad binary. 2. bug? in SC where it doesn't pass the filename to faad. Can be solved by hacking Song.pm in Slim/Player and changing the function call tokenizeConvertCommand to

my $filepath = '-';
if ($command =~ /faad/) {
  $filepath = $track->path;
}
$command = Slim::Player::TranscodingHelper::tokenizeConvertCommand(
 $command, $type, $filepath, $url, 0 , $maxRate, 1, $quality );
  • scanner.pl is started with server's real UID (root in our case), so it creates Artwork directory owned by root, and it cannot write to it later. I fixed it by including a "sudo" binary (compiled to look for sudoers file in SQUEEZECENTER/system/etc) and running the scanner.pl with it. If you look in my installation, Custom.pm defines the scanner to be addbin/scanner.sh. That script is this:
#!/bin/sh

BINDIR=/raid/data/module/SQUEEZECENTER/system/addbin
$BINDIR/sudo -u nobody $BINDIR/scanner_sudo.sh "$@"

and the scanner.sh described above is renamed to scanner_sudo.sh. That seems to solve the Artwork problems, but scanner.pl then cannot find the cookies.dat. The problem is the following line in squeezecenter/Slim/Networking/Async/HTTP.pm:

my $cookieJar = HTTP::Cookies->new(    file => catdir($prefs->get('cachedir'), 'cookies.dat'), autosave => 1 );

Basically, $prefs->get('cachedir') doesn't return the proper value for some reason. You can fix it by hard-coding the proper path there:

my $cookieJar = HTTP::Cookies->new(     file => '/raid/data/module/SQUEEZECENTER/system/SlimCache/cookies.dat', autosave => 1 );
  • Album artwork shown in full size in playlist

This was caused by the missing jpeg support in the original gd library I used when compiling the perl GD module. Make sure bot gd and GD are compiled with jpeg support. (thanks flynn)

Debugging/troubleshooting

  • If things don't work after enabling the module, first check the log files in SQUEEZECENTER/system/etc/logs/
  • ssh to your Thecus first and try manually running the server. Don't forget to export LD_LIBRARY_PATH and PERL5LIB first.
  • if the server complains about missing perl modules, you probably forgot to include some libraries. Try running perl with -e "use missing_module" to see why it fails. For example if slimserver.pl complains that it's missing XML::Parser::Expat you would try:
export PERL5LIB=/raid/data/module/SQUEEZECENTER/system/CPAN
export LD_LIBRARY_PATH=/raid/data/module/SQUEEZECENTER/system/addlib
/raid/data/module/PERL/perl/bin/perl -e "use XML::Parser::Expat"

Perl will complain about the missing libraries, so add them to addlib (or CPAN/auto, if it's the module's own libs you forgot).

Files

package Slim::Utils::OS::Custom;

#Custom OS module for Thecus N5200/N5200PRO
#initial version: Ivica Letunic, 17.Sep 2009.


use strict;
use base qw(Slim::Utils::OS::Unix);



sub initDetails {
        my $class = shift;
        $class->{osDetails} = $class->SUPER::initDetails();
        $class->{osDetails}->{name} = "Thecus N5200/N5200PRO";
        return $class->{osDetails};
}

sub initSearchPath {
   my $class = shift;

   $class->SUPER::initSearchPath();
   Slim::Utils::Misc::addFindBinPaths('/raid/data/module/SQUEEZECENTER/system/addbin');
}

sub scanner {
        return '/raid/data/module/SQUEEZECENTER/system/addbin/scanner.sh';
}
sub dirsFor {
    my ($class, $dir) = @_;
    my @dirs = $class->SUPER::dirsFor($dir);
    if ($dir eq 'cache') {
       @dirs = ();
       push @dirs, '/raid/data/module/SQUEEZECENTER/system/SlimCache';
   } 
   return wantarray() ? @dirs : $dirs[0];
}
1;