#!/bin/sh

EMS_DIR=/usr/share/emacs/site-lisp/emacspeak

if [ -x "$DTK_PROGRAM" ]; then
  echo "Using $DTK_PROGRAM as Emacspeak speech server"
elif [ -n "$DTK_PROGRAM" ] && [ -x "$EMS_DIR/servers/$DTK_PROGRAM" ]; then
  echo "Using $EMS_DIR/servers/$DTK_PROGRAM as Emacspeak speech server"
elif [ -r /usr/lib/emacspeak/tclespeak.so ] && [ -x "$EMS_DIR"/servers/espeak ]; then
  DTK_PROGRAM="espeak"
elif [ -x "$EMS_DIR"/servers/eflite ]; then
  DTK_PROGRAM="eflite"
else
  echo "Emacspeak speech server is not installed."
  echo "Please install it with this command:"
  echo "  apk add emacspeak-server-espeak"
  echo "               OR"
  echo "  apk add emacspeak-server-eflite"
  exit 1
fi

export DTK_PROGRAM

if [ -r "$HOME"/.emacs.d/init.el ]; then
  exec emacs -q -l cl-lib -l emacspeak-setup -l "$HOME"/.emacs.d/init.el "$@"
else
  exec emacs -q -l cl-lib -l emacspeak-setup "$@"
fi
