#!/bin/sh
# Didier Spaier <didier~at~slint.fr> 2019
# I wrote this script from scratch and put it in the public domain.
if [ $(id -u) -eq 0 ]; then
	echo "Please run this script as regular user."
	exit
fi
features='emacspeak
speechd-el'
descriptions=\
'emacspeak (The Complete Audio Desktop, based on emacs)
speechd-el (Emacs client to speech synthesizers and Braille displays)'

emacspeak_cmd='(load-file "/usr/share/emacs/site-lisp/emacspeak/lisp/emacspeak-setup.el")'
speechd_el_cmd="(autoload 'speechd-speak \"speechd-speak\" nil t)"
usage() {
  echo "Usage: $0 <emacspeak> or <speechd-el>"
  echo "This script allows to disable:"
  echo "$descriptions"
  exit
}
if [ $# -ne 1 ]; then usage; fi
if  ! echo $features|grep -qw $1; then
	echo "$1 is an unknown feature."
	echo "Available features:"
	echo "$descriptions"
	exit
fi
case $1 in
	emacspeak)
		if [ "$(find /var/log/packages/ -name "${1}"*)" = "" ]; then
			echo "$1 is not installed"
			exit
		fi
		if grep -q emacspeak-setup.el ~/.emacs 2>/dev/null; then
			bof=$(mktemp)
			sed	'/emacspeak-setup.el/d
			/"DTK_PROGRAM" "outloud"/d' ~/.emacs > $bof
			mv $bof ~/.emacs
		fi
		echo "emacspeak is disabled."
	;;
	speechd-el)
		if [ "$(find /var/log/packages/ -name "${1}"*)" = "" ]; then
			echo "$1 is not installed."
			exit
		fi
		if grep -q speechd-speak ~/.emacs 2>/dev/null; then
			bof=$(mktemp)
			sed "/speechd-speak/d
			/speechd-out-active-drivers/d" ~/.emacs > $bof
			mv $bof ~/.emacs
		fi
		echo "speechd-el is disabled."
	;;
esac

