# Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ inherit eutils DESCRIPTION="Music streaming server for SLIMP3/Squeezebox devices or software players." HOMEPAGE="http://www.slimdevices.com" MY_P="SlimServer_v${PV}" SRC_URI="http://www.slimdevices.com/downloads/${MY_P}/${MY_P}.no-cpan-arch.tar.gz" LICENSE="GPL-2" SLOT="0" KEYWORDS="~x86 ~amd64" IUSE="encode ffmpeg aac flac mp3 musepack shorten vorbis wma" # # NOTE: I changed this: shorten is now a global USE flag, and there's # another package that uses "musepack" instead of "mpc". Going for # some consistency that is the insanity of USE flags. # # For profiles/use.local.desc: # media-sound/slimserver:musepack - Adds support for Musepack files # media-sound/slimserver:wma - Configures support for WMA files # # NOTE: Flags "musepack" and "shorten" should be use.masked on archs which # don't have media-sound/musepack-tools and media-sound/shorten # packages yet. # Currently no depends for aac? or shorten? when using FFmpeg DEPEND=">=dev-lang/perl-5.8.1 >=sys-apps/sed-4 encode? ( >=media-sound/lame-3.96 ) ffmpeg? ( media-video/ffmpeg aac? ( dev-perl/MP4-Info ) flac? ( >=media-libs/flac-1.1 dev-perl/Audio-FLAC-Header ) mp3? ( dev-perl/MP3-Info ) musepack? ( media-sound/musepack-tools dev-perl/Audio-Musepack ) vorbis? ( dev-perl/Ogg-Vorbis-Header-PurePerl ) wma? ( dev-perl/Audio-WMA ) ) !ffmpeg? ( aac? ( media-libs/faad2 dev-perl/MP4-Info) flac? ( >=media-libs/flac-1.1 dev-perl/Audio-FLAC-Header ) mp3? ( >=media-sound/lame-3.96 dev-perl/MP3-Info ) musepack? ( media-sound/musepack-tools dev-perl/Audio-Musepack ) shorten? ( media-sound/shorten ) vorbis? ( media-sound/vorbis-tools dev-perl/Ogg-Vorbis-Header-PurePerl ) wma? ( dev-perl/Audio-WMA ) ) dev-perl/Audio-Wav dev-perl/B-LexInfo dev-perl/B-Size dev-perl/Class-DBI dev-perl/Compress-Zlib dev-perl/DBD-SQLite dev-perl/DBI dev-perl/Devel-Size dev-perl/Devel-Size-Report dev-perl/Devel-Symdump dev-perl/File-BOM dev-perl/File-Which dev-perl/HTML-Parser dev-perl/libwww-perl dev-perl/SQL-Abstract dev-perl/SQL-Abstract-Limit dev-perl/Template-Toolkit dev-perl/Tie-Cache-LRU dev-perl/Tie-Cache-LRU-Expires dev-perl/Tie-RegexpHash dev-perl/TimeDate dev-perl/URI dev-perl/XML-Parser dev-perl/XML-Simple perl-core/Digest-MD5 perl-core/Getopt-Long perl-core/MIME-Base64 perl-core/Time-HiRes" S="${WORKDIR}/${MY_P}" # # Remember our old configuration values, or new user-defined ones, much # like apache does for modules in its ebuild. # [ -f "/etc/conf.d/slimserver" ] && source "/etc/conf.d/slimserver" # # User-configurable variables # # NOTE: According to FHS, I think it may be appropriate to locate music # files in /srv/music/[somewhere], since /usr/share is for "static" # data, and a user will likely be adding/removing music all the # time. For the multitude of music folders here, /srv/music seems # better, even though /usr/share/music seems right for music only. # However, that leaves playlists and iTunes out in the cold, so # I'm venturing into /srv. This is very open for debate, but my # needs and FHS seem to be on my side for now. Comments are # appreciated. =) # # NOTE: Added a SLIM_ITUNES_DIR for those of us brave enough to use Samba # to do strange voodoo with iTunes and SlimServer. Voodoo aside, # it seems reasonable enough to add this here, since it's one of # the only other directories that you can configure for the # SlimServer. # SLIM_USER="${SLIM_USER:-slimserver}" SLIM_GROUP="${SLIM_GROUP:-slimserver}" SLIM_MUSIC_DIR="${SLIM_MUSIC_DIR:-/srv/music/library}" SLIM_PLAYLISTS_DIR="${SLIM_PLAYLISTS_DIR:-/srv/music/playlists}" SLIM_ITUNES_DIR="${SLIM_ITUNES_DIR:-/srv/music/itunes/iTunes Music}" SLIM_ITUNES_XML="${SLIM_ITUNES_XML:-/srv/music/itunes/iTunes Music Library.xml}" SLIM_ART_DIR="${SLIM_ART_DIR:-/srv/music/artwork}" SLIM_INPUT_FORMATS="${SLIM_INPUT_FORMATS:-NONE}" SLIM_OUTPUT_FORMATS="${SLIM_OUTPUT_FORMATS:-NONE}" SLIM_DISABLE_SETUP="${SLIM_DISABLE_SETUP:-no}" SLIM_DISABLE_SERVER_SETUP="${SLIM_DISABLE_SERVER_SETUP:-no}" SLIM_HTTP_PORT="${SLIM_HTTP_PORT:-9000}" SLIM_HTTP_ADDR="${SLIM_HTTP_ADDR:-}" SLIM_CLI_PORT="${SLIM_CLI_PORT:-9090}" SLIM_CLI_ADDR="${SLIM_CLI_ADDR:-}" SLIM_PLAYER_ADDR="${SLIM_PLAYER_ADDR:-}" SLIM_STREAM_ADDR="${SLIM_STREAM_ADDR:-}" SLIM_DEBUG="${SLIM_DEBUG:-no}" SLIM_QUIET="${SLIM_QUIET:-yes}" SLIM_PRIORITY="${SLIM_PRIORITY:-0}" SLIM_OPTIONS="${SLIM_OPTIONS:-}" # # List of variables to export to /etc/conf.d/slimserver later # # NOTE: This is mostly for letting the user customize slimserver # the first time they install it. I'm adding a file to # read these options in automagically from a file in /etc, # much like the apache ebuilds do for modules that ship # with apache. This is my main reason for moving the config # to /etc/slimserver/slimserver.conf # SLIM_CONFIG_VARS="SLIM_USER SLIM_GROUP SLIM_MUSIC_DIR SLIM_PLAYLISTS_DIR SLIM_ITUNES_DIR SLIM_ITUNES_XML SLIM_ART_DIR SLIM_INPUT_FORMATS SLIM_OUTPUT_FORMATS SLIM_DISABLE_SETUP SLIM_DISABLE_SERVER_SETUP SLIM_HTTP_PORT SLIM_HTTP_ADDR SLIM_CLI_PORT SLIM_CLI_ADDR SLIM_PLAYER_ADDR SLIM_STREAM_ADDR SLIM_DEBUG SLIM_QUIET SLIM_PRIORITY SLIM_OPTIONS" function configure_default_formats() { if [ "${SLIM_INPUT_FORMATS}" = "NONE" ] then SLIM_INPUT_FORMATS="wav" use ffmpeg && SLIM_INPUT_FORMATS="${SLIM_INPUT_FORMATS} aif" use mp3 && SLIM_INPUT_FORMATS="${SLIM_INPUT_FORMATS} mp3" use vorbis && SLIM_INPUT_FORMATS="${SLIM_INPUT_FORMATS} ogg" use flac && SLIM_INPUT_FORMATS="${SLIM_INPUT_FORMATS} flc" use shorten && SLIM_INPUT_FORMATS="${SLIM_INPUT_FORMATS} shn" use musepack && SLIM_INPUT_FORMATS="${SLIM_INPUT_FORMATS} mpc" use aac && SLIM_INPUT_FORMATS="${SLIM_INPUT_FORMATS} mov" use ffmpeg && \ use wma && SLIM_INPUT_FORMATS="${SLIM_INPUT_FORMATS} wma" fi if [ "${SLIM_OUTPUT_FORMATS}" = "NONE" ] then SLIM_OUTPUT_FORMATS="wav" use ffmpeg && SLIM_OUTPUT_FORMATS="${SLIM_OUTPUT_FORMATS} aif" use encode && SLIM_OUTPUT_FORMATS="${SLIM_OUTPUT_FORMATS} mp3" use flac && SLIM_OUTPUT_FORMATS="${SLIM_OUTPUT_FORMATS} flc" fi } # # This function set default settings values in init.d and conf.d files. # # USAGE: replace_env_vars [src_file] [dest_file] # # For each var_name in SLIM_CONFIG_VARS, this function # replaces instances of <> in [src_file] # with the actual value of the environment variable, # and writes the results to [dest_file]. # function replace_env_vars() { local sed_cmd="sed" local var_name var_value # # We require that SLIM_CONFIG_VARS be set, and that we are passed # a valid filename. # if [ ! -f "$1" -o -z "$2" -o -z "${SLIM_CONFIG_VARS}" ] then return 2 fi # Build a sed command to do something like this: # sed -e s:<>:slimserver: ... for var_name in ${SLIM_CONFIG_VARS} do eval var_value="\${${var_name}}" sed_cmd="${sed_cmd} -e 's:<<${var_name}>>:${var_value}:g'" done # Apply the sed command. Output to stdout. cat "$1" | eval ${sed_cmd} > "$2" } pkg_setup() { if use !encode || use !flac then ewarn "WARNING! You are about to build media-sound/slimserver without" ewarn "either MP3 or FLAC support. Most commonly a Squeezebox or" ewarn "SliMP3 streams in MP3, and newer Squeezebox models are capable" ewarn "of streaming FLAC files directly. You probably do not want to" ewarn "disable these. Here is what you have disabled, and how to" ewarn "fix it:" ewarn "" use !encode && ewarn " MP3 encoding support (USE='encode')" use !flac && ewarn " FLAC encoding support (USE='flac')" ewarn "" sleep 5 fi if use wma && use !ffmpeg then ewarn "WARNING! You are trying to enable WMA support without FFmpeg!" ewarn "SlimServer cannot handle WMA files unless you enable FFmpeg as" ewarn "a decoder to do this, you neeed to use the following USE flag:" ewarn "" ewarn " FFMpeg support (USE='ffmpeg')" ewarn "" sleep 5 fi enewgroup slimserver enewuser slimserver -1 /bin/false /usr/lib/slimserver slimserver } src_unpack() { unpack ${A} cd ${S} rm -rf Bin # Shouldn't need the included static binary decoders rm -rf CPAN # Shouldn't need included modules as we depend on the # ebuilds instead mkdir Bin epatch "${FILESDIR}/${P}.patch" } src_compile() { einfo "Configuring default input and output formats" configure_default_formats einfo "Configuring boot scripts" replace_env_vars "${FILESDIR}/slimserver.confd" \ "${WORKDIR}/slimserver.confd" replace_env_vars "${FILESDIR}/slimserver.initd" \ "${WORKDIR}/slimserver.initd" einfo "Copying format conversion files" if use ffmpeg then cp "${FILESDIR}/formats.conf-ffmpeg" "${WORKDIR}/formats.conf" else cp "${FILESDIR}/formats.conf-other" "${WORKDIR}/formats.conf" fi cp "${FILESDIR}/convert.conf" "${WORKDIR}/convert.conf" einfo "Copying server configuration files" if [ ! -f /var/cache/slimserver/slimserver.conf ] then # Unfortunately, since the SlimServer writes back to this file, # this ugly, un-ebuild-like hack has to remain in place, since # most users won't be able to make any sense out of the extra # lines that SlimServer has added once it starts serving up # music to clients, etc, and I'd rather copy the old config # than have a user accidentally annihilate all of the settings # that they worked so hard to configure. replace_env_vars "${FILESDIR}/slimserver.conf" \ "${WORKDIR}/slimserver.conf" else cp /var/cache/slimserver/slimserver.conf \ "${WORKDIR}/slimserver.conf" fi } src_install() { dodir /usr/lib/slimserver cp -R "${S}"/* "${D}/usr/lib/slimserver" rm -f \ "${D}/usr/lib/slimserver/convert.conf" \ "${D}/usr/lib/slimserver/slimserver.pl" \ "${D}/usr/lib/slimserver/Installation.txt" \ "${D}/usr/lib/slimserver/License.txt" \ "${D}/usr/lib/slimserver/Changelog.html" # Note: the server script really must stay in /usr/lib/slimserver # (code is full of "use FindBin") exeinto /usr/lib/slimserver newexe "${S}/slimserver.pl" slimserver.pl # Documentation: dodoc Installation.txt License.txt dohtml Changelog.html # Service script and its config dodir /etc/init.d newinitd "${WORKDIR}/slimserver.initd" slimserver dodir /etc/conf.d newconfd "${WORKDIR}/slimserver.confd" slimserver # # Setup the slimserver config files # dodir /etc/slimserver insinto /etc/slimserver doins "${WORKDIR}/formats.conf" \ "${WORKDIR}/convert.conf" keepdir /var/log/slimserver keepdir /var/run/slimserver keepdir /var/cache/slimserver insinto /var/cache/slimserver doins "${WORKDIR}/slimserver.conf" ### ### I'm thinking that hardcoding this is not ### a good idea, actually. Leave them blank ### by default and make the user set them? ### keepdir "${SLIM_MUSIC_DIR}" keepdir "${SLIM_PLAYLISTS_DIR}" keepdir "${SLIM_ITUNES_DIR}" keepdir "${SLIM_ART_DIR}" fperms 0775 \ "${SLIM_MUSIC_DIR}" \ "${SLIM_PLAYLISTS_DIR}" \ "${SLIM_ITUNES_DIR}" \ "${SLIM_ART_DIR}" ### ### Only force owner/group on directories we're creating ### otherwise, we'll leave them in tact ### for DIR in "${SLIM_MUSIC_DIR}" "${SLIM_PLAYLISTS_DIR}" \ "${SLIM_ITUNES_DIR}" "${SLIM_ART_DIR}" do if [ ! -e "${DIR}" ] then fowners "${SLIM_USER}:${SLIM_GROUP}" "${DIR}" fi done } pkg_postinst() { # Very quick startup guide. einfo "Congratulations! You have successfully installed the SlimServer!" einfo "" einfo "You can start and stop the server by using /etc/init.d/slimserver" einfo "The service can be configured by editing /etc/conf.d/slimserver" einfo "If you would like to start your SlimServer on every reboot, then" einfo "execute the following command as root:" einfo "" einfo " rc-update add slimserver default" einfo "" einfo "The server is configured to run as ${SLIM_USER}:${SLIM_GROUP} by" einfo "default. If you would like to add the user ${SLIM_USER} to other" einfo "system groups, do so using the following command:" einfo "" einfo " gpasswd -a ${SLIM_USER} [group]" einfo "" einfo "Also note that this distribution is notably different than the" einfo "official package. All file and folder location information is" einfo "stored in /etc/conf.d/slimserver, and cannot be changed through" einfo "the web interface. This is to maintain consistency within our" einfo "distribution." einfo "" einfo "For further assistance, please consult the SlimServer documentation" einfo "and website before reporting bugs to Gentoo." einfo "" }