#!/bin/sh -e if [ -n "$MPD_DEBUG" ]; then set -x MPD_OPTS=--verbose fi umask 0022 PATH=/sbin:/bin:/usr/sbin:/usr/bin # edit /etc/default/mpd to change these: DAEMON=/usr/bin/mpd MPDCONF=/etc/mpd-nad.conf START_MPD=true if [ -r /etc/default/mpd ]; then . /etc/default/mpd fi check_conf () { if ! (grep -q db_file $MPDCONF && grep -q pid_file $MPDCONF); then echo "$MPDCONF must have db_file and pid_file set; not starting." exit 0 fi } check_dbfile () { DBFILE=`sed -n -e 's/^[[:space:]]*db_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p' $MPDCONF` if [ "$FORCE_CREATE_DB" -o ! -f "$DBFILE" ]; then echo -n "creating $DBFILE... " $DAEMON --create-db "$MPDCONF" > /dev/null 2>&1 fi } mpd_start () { if [ "$START_MPD" != "true" ]; then echo "Not starting MPD: disabled by /etc/default/mpd." exit 0 fi echo -n "Starting Music Player Daemon: " check_conf check_dbfile if $DAEMON $MPD_OPTS "$MPDCONF"; then echo "mpd." else echo "failed." fi } mpd_stop () { echo -n "Stopping Music Player Daemon: " if $DAEMON --kill "$MPDCONF" >/dev/null 2>&1; then echo "mpd." else echo "not running or no pid_file set." fi } # note to self: don't call the non-standard args for this in # {post,pre}{inst,rm} scripts since users are not forced to upgrade # /etc/init.d/mpd when mpd is updated case "$1" in start) mpd_start ;; stop) mpd_stop ;; restart|reload) mpd_stop mpd_start ;; force-start|start-create-db) FORCE_CREATE_DB=1 mpd_start ;; force-restart|force-reload) FORCE_CREATE_DB=1 mpd_stop mpd_start ;; *) echo "Usage: $0 {start|start-create-db|stop|restart|reload}" exit 1 ;; esac