#!/sbin/runscript
#FIXME: Change license.
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/media-sound/mpd/files/mpd.rc,v 1.4 2008/10/15 00:01:01 angelos Exp $

# FIXME leycec: Convert to "genesis" format when settled.
depend() {
    need alsasound localmount
    use net.lo netmount nfsmount esound pulseaudio
} 

start() {
    #FIXME: Parse these from "/etc/mpd.conf" (...or whatever!) via awk.
    MPD_USER=leycec
    MPD_LIB_PATH="/var/lib/mpd/"
    MPD_RUN_PATH="/var/run/mpd/"

    if [ ! -f "$MPD_LIB_PATH/database" ]
    then ebegin "Starting MPD and creating song database" 
    else ebegin "Starting MPD" 
    fi

    # Make requisite paths on behalf of MPD, if not found.
    for MPD_PATH in "$MPD_LIB_PATH" "$MPD_RUN_PATH"; do
        if [ ! -d "$MPD_PATH" ]; then
            mkdir -p "$MPD_PATH" ||
	        eerror "\"$MPD_PATH\" could not be made!"
            chown $MPD_USER "$MPD_PATH" ||
	        eerror "\"$MPD_PATH\" could not be chowned by $MPD_USER!"
        fi
    done

    # Fork MPD as a daemon process.
    /usr/bin/mpd
    eend $?
}

stop() {
    ebegin "Stopping MPD"
    /usr/bin/mpd --kill
    eend $? 
}
