#!/bin/sh
#/etc/init.d/festival
#
# Init script for starting Festival as a system-wide server process.
#
# Written by David Huggins-Daines <dhd@cepstral.com>
# LSBINITInfo by Kartik Mistry <kartik.mistry@gmail.com>
# LSB logging functions by David Härdeman <david@hardeman.nu>

### BEGIN INIT INFO
# Provides:          festival
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts Festival engine at boot time
# Description:       Init script for starting Festival TTS as a
#                    system-wide server process
### END INIT INFO

# WARNING: It is inherently insecure to run a festival instance as a
# server, mainly because it exposes the whole system to exploits which
# can be easily used by attackers to gain access to your
# computer. This is because of the inherent design of the festival
# server. Please use it only in a situation where you are sure that
# you will not be subjected to such an attack, or have adequate
# security precautions.

# This file has been provided as an example file for your use, should
# you wish to run festival as a server.

[ -r /etc/default/festival ] && . /etc/default/festival
if [ "$RUN_FESTIVAL" != yes ]; then
	echo Not starting festival server, as /etc/default/festival does not have RUN_FESTIVAL=yes.
	exit 0
fi

# NOTE: Not just anybody can connect to your server; the list of allowed
# hostnames is a regexp. Check /usr/share/festival/festival.scm for more
# helpful comments; add your settings to /etc/festival.scm.

set -e

DAEMON=/usr/bin/festival
REALPROC=/usr/bin/festival
NAME=festival

. /lib/lsb/init-functions

test -x $DAEMON || exit 0

case "$1" in
  start)
    log_daemon_msg "Starting Festival server" "$NAME"
    start-stop-daemon --start --chuid festival --background \
		      --exec $DAEMON -- --server -b /etc/festival.scm
    log_end_msg 0
    ;;
  stop)
    log_daemon_msg "Stopping Festival server" "$NAME"
    start-stop-daemon --stop --oknodo --exec $REALPROC
    log_end_msg 0
    ;;
  restart|reload|force-reload)
    log_daemon_msg "Restarting Festival server" "$NAME"
    start-stop-daemon --stop --oknodo --exec $REALPROC
    start-stop-daemon --start --chuid festival --background \
		      --exec $DAEMON -- --server -b /etc/festival.scm
    log_end_msg 0
    ;;
  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart}" >&2
    exit 2
    ;;
esac

exit 0
