#!/sbin/runscript # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ opts="${opts} listformats" depend() { use net } checkconfig() { SLIM_OPTIONS="${SLIM_OPTIONS:-}" SLIM_USER="${SLIM_USER:-slimserver}" SLIM_GROUP="${SLIM_GROUP:-slimserver}" SLIM_MUSIC_DIR="${SLIM_MUSIC_DIR:-<>}" SLIM_PLAYLISTS_DIR="${SLIM_PLAYLISTS_DIR:-<>}" SLIM_ITUNES_DIR="${SLIM_ITUNES_DIR:-<>}" SLIM_ART_DIR="${SLIM_ART_DIR:-<>}" FORMATSDB=$(cat /etc/slimserver/formats.conf | grep -v '^[[:space:]]*\(#.*\)\?$' | sed -e 's#[[:space:]]*:[[:space:]]*#:#g') [ -f /var/cache/slimserver/slimserver.conf ] || die "/var/cache/slimserver/slimserver.conf not found!" [ -f /etc/slimserver/formats.conf ] || die "/etc/slimserver/formats.conf not found!" [ -f /etc/slimserver/convert.conf ] || die "/etc/slimserver/convert.conf not found!" } function formats_update() { cat > /usr/lib/slimserver/convert.conf.new << EOF # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # \$Header \$ # # DO NOT MODIFY THIS FILE -- IT HAS BEEN AUTO-GENERATED # EOF for IN in ${SLIM_INPUT_FORMATS} do IN_LINE=$(echo "${FORMATSDB}" | grep -m 1 "^${IN}:") if [ -z "${IN_LINE}" ] then eerror "ERROR: Format '${IN}' not defined in formats file" return 1 else IN_NAME=$(echo "${IN_LINE}" | cut -d : -f 2) IN_DEC=$(echo "${IN_LINE}" | cut -d : -f 3) IN_ENC=$(echo "${IN_LINE}" | cut -d : -f 4) IN_TRANS=$(echo "${IN_LINE}" | cut -d : -f 5) echo "###" >> /usr/lib/slimserver/convert.conf.new echo "### Conversions for ${IN_NAME}" >> /usr/lib/slimserver/convert.conf.new echo "###" >> /usr/lib/slimserver/convert.conf.new for OUT in ${SLIM_OUTPUT_FORMATS} do OUT_LINE=$(echo "${FORMATSDB}" | grep -m 1 "^${OUT}:") if [ -z "${OUT_LINE}" ] then eerror "ERROR: Format '${OUT}' not defined in formats file" return 1 else OUT_NAME=$(echo "${OUT_LINE}" | cut -d : -f 2) OUT_DEC=$(echo "${OUT_LINE}" | cut -d : -f 3) OUT_ENC=$(echo "${OUT_LINE}" | cut -d : -f 4) OUT_TRANS=$(echo "${OUT_LINE}" | cut -d : -f 5) if [ "${IN}" = "${OUT}" ] then # Either passthru or transcoding echo -e "${IN} ${OUT} * *" >> /usr/lib/slimserver/convert.conf.new echo -e "\t-" >> /usr/lib/slimserver/convert.conf.new if [ -n "${IN_TRANS}" -a "${IN_TRANS}" != "\$NONE\$" ] then echo -e "${IN} ${OUT} transcode *" >> /usr/lib/slimserver/convert.conf.new echo -e "\t${IN_TRANS}" >> /usr/lib/slimserver/convert.conf.new fi elif [ -n "${IN_DEC}" -a -n "${OUT_ENC}" -a "${IN_DEC}" != "\$NONE\$" ] then # Some other, more standard pipeline [ "${OUT_ENC}" = "\$NONE\$" ] && OUT_ENC="" || OUT_ENC="| ${OUT_ENC}" echo -e "${IN} ${OUT} * *" >> /usr/lib/slimserver/convert.conf.new echo -e "\t${IN_DEC} ${OUT_ENC}" >> /usr/lib/slimserver/convert.conf.new else [ -z "${IN_DEC}" ] && eerror "ERROR: Input decoder for format '${IN}' not defined" && return 1 [ -z "${OUT_ENC}" ] && eerror "ERROR: Output encoder for format '${OUT}' not defined" && return 1 fi fi done echo "" >> /usr/lib/slimserver/convert.conf.new fi done cat /etc/slimserver/convert.conf >> /usr/lib/slimserver/convert.conf.new mv -f /usr/lib/slimserver/convert.conf.new /usr/lib/slimserver/convert.conf return $? } start() { checkconfig || die "Configuration errors were found!" # # Update the formats config file if we need to # if [ /etc/slimserver/formats.conf -nt /usr/lib/slimserver/convert.conf ] || \ [ /etc/slimserver/convert.conf -nt /usr/lib/slimserver/convert.conf ] || \ [ /etc/conf.d/slimserver -nt /usr/lib/slimserver/convert.conf ] || \ [ ! -f /usr/lib/slimserver/convert.conf ] then ebegin "Updating format conversion tables" formats_update || rm -f /usr/lib/slimserver/convert.conf.new eend $? fi pushd /usr/lib/slimserver >/dev/null ebegin "Starting SlimServer" # # Force settings for MUSIC, PLAYLIST, ITUNES, and ART dirs to be whatever we got from # /etc/conf.d/slimserver # sed \ -e "s#^audiodir: .*\$#audiodir: '${SLIM_MUSIC_DIR}'#g" \ -e "s#^playlistdir: .*\$#playlistdir: '${SLIM_PLAYLISTS_DIR}'#g" \ -e "s#^artfolder: .*\$#artfolder: '${SLIM_ART_DIR}'#g" \ -e "s#^itunes_library_music_path: .*\$#itunes_library_music_path: '${SLIM_ITUNES_DIR}'#g" \ -e "s#^itunes_library_xml_path: .*\$#itunes_library_xml_path: '${SLIM_ITUNES_XML}'#g" \ -e "s#timeFormat: \\(.*\\)[[:space:]]*\$#timeFormat: '\\1'#g" \ /var/cache/slimserver/slimserver.conf > \ /var/cache/slimserver/slimserver.conf.new && \ mv -f /var/cache/slimserver/slimserver.conf.new /var/cache/slimserver/slimserver.conf # # Make sure the permissions are correct on critical hard-coded file paths # chown -R ${SLIM_USER}:${SLIM_GROUP} \ /var/log/slimserver \ /var/run/slimserver \ /var/cache/slimserver # # Build the slimserver command line from the settings in our conf.d file # [ -n "${SLIM_HTTP_PORT}" ] && SLIM_OPTIONS="${SLIM_OPTIONS} --httpport=${SLIM_HTTP_PORT}" [ -n "${SLIM_HTTP_ADDR}" ] && SLIM_OPTIONS="${SLIM_OPTIONS} --httpaddr=${SLIM_HTTP_ADDR}" [ -n "${SLIM_CLI_PORT}" ] && SLIM_OPTIONS="${SLIM_OPTIONS} --cliport=${SLIM_CLI_PORT}" [ -n "${SLIM_CLI_ADDR}" ] && SLIM_OPTIONS="${SLIM_OPTIONS} --cliaddr=${SLIM_CLI_ADDR}" [ -n "${SLIM_PLAYER_ADDR}" ] && SLIM_OPTIONS="${SLIM_OPTIONS} --playeraddr=${SLIM_PLAYER_ADDR}" [ -n "${SLIM_STREAM_ADDR}" ] && SLIM_OPTIONS="${SLIM_OPTIONS} --streamaddr=${SLIM_STREAM_ADDR}" [ "${SLIM_DISABLE_SERVER_SETUP}" = "yes" ] && SLIM_OPTIONS="${SLIM_OPTIONS} --noserver" [ "${SLIM_DISABLE_SETUP}" = "yes" ] && SLIM_OPTIONS="${SLIM_OPTIONS} --nosetup" [ "${SLIM_DEBUG}" = "yes" ] && SLIM_OPTIONS="${SLIM_OPTIONS} --diag" [ "${SLIM_QUIET}" = "no" ] || SLIM_OPTIONS="${SLIM_OPTIONS} --quiet" # # Make sure SLIM_PRIORITY is valid before trying to use it # [ -n "${SLIM_PRIORITY}" ] && \ if [ ${SLIM_PRIORITY} -ge -20 -a ${SLIM_PRIORITY} -le 20 ] ; then SLIM_PRIORITY="--nicelevel ${SLIM_PRIORITY}" else ewarn "Invalid priority: ${SLIM_PRIORITY}" SLIM_PRIORITY="" fi # # Oh, yeah... we actually need to start the daemon eventually... # start-stop-daemon --start --quiet --chuid ${SLIM_USER}:${SLIM_GROUP} ${SLIM_PRIORITY} --exec /usr/lib/slimserver/slimserver.pl -- \ --daemon \ --prefsfile=/var/cache/slimserver/slimserver.conf \ --logfile=/var/log/slimserver/slimserver.log \ --cachedir=/var/cache/slimserver \ --pidfile=/var/run/slimserver/slimserver.pid \ ${SLIM_OPTIONS} eend $? popd >/dev/null } stop() { checkconfig || die "/var/cache/slimserver/slimserver.conf not found!" pushd /usr/lib/slimserver >/dev/null ebegin "Stopping SlimServer" start-stop-daemon --stop --quiet --pidfile /var/run/slimserver/slimserver.pid eend $? popd >/dev/null } listformats() { checkconfig || die "/var/cache/slimserver/slimserver.conf not found!" einfo "The following formats are recognized by the SlimServer:" echo "" echo "${FORMATSDB}" | sed -e 's#\([^:]*\):\([^:]*\):.*#\t\1 - \2#g' echo "" } # vim: ts=4 :