#!/bin/sh

### BEGIN INIT INFO
# Provides:          mpdmount
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the recpt1d
# Description: starts the mpdmount (USER=volumio)
### END INIT INFO

# cp mpdmount /etc/init.d
# cd /etc/init.d
# Auto Start , systemctl enable mpdmount
# Stopped , systemctl disable mpdmount

#MPDMOUNT=/var/www/html/mpdweb/shell/mpdmount.pl
MPDMOUNT=`find /var/www -name "mpdmount.pl"`
TASKNAME=mpdmount
if [ "${MPDMOUNT}" = "" ] ; then
	echo "Module Not Found Initiator Forced stop"
	exit
fi

# define functions
start() {
	echo -n "${TASKNAME} init.\n"
	${MPDMOUNT} mount chmod=0777 > /dev/null 2>&1 &
	return 0
}
stop() {
	echo -n "${TASKNAME} term.\n"
	${MPDMOUNT} umount > /dev/null 2>&1 &
	return 0
}
restart() {
	stop
	start
}

case "$1" in
	start)
		start
	;;
	stop)
		stop
	;;
	restart)
		restart
	;;
	*)
	echo "Usage: $0 {start|stop|restart)\n"
	RETVAL=2
esac
