Drop grml-postfix
[grml-scripts.git] / usr_sbin / swspeak-setup
1 #!/bin/sh
2 # Filename:      swspeak-setup
3 # Purpose:       script for activating software speak(up) features
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 ################################################################################
8 # Note: the script is used via swspeak() function in grml's zshrc so
9 #       the prompt of zsh is set accordingly
10 # TODO: support disabling swspeakup again?
11
12 if [ -r /etc/grml/script-functions ] ; then
13    . /etc/grml/script-functions
14 else
15    echo "Failed to source /etc/grml/script-functions - exiting.">&2
16    exit 1
17 fi
18
19 if [ -r /etc/grml/lsb-functions ] ; then
20    . /etc/grml/lsb-functions
21 else
22    echo "Failed to source /etc/grml/lsb-functions - exiting.">&2
23    exit 1
24 fi
25
26 if [ "$1" = '-h' ] || [ "$1" = '--help' ] ; then
27    cat << EOF
28 swspeak - script for activating software speak features
29
30 Usage: swspeak [-a] [-e|-s] [-f] [-h]
31
32 Supported options:
33
34    -e   use espeakup (default, if available)
35    -s   use speechd-up (fallback, if available)
36    -a   do not execute aumix for setting mixer levels
37    -f   disable flite sound output
38    -h   display this help text
39 EOF
40    exit 0
41 fi
42
43 NOAUMIX=''
44 [ "$1" = '-a' ] && NOAUMIX=1
45 ESPEAK=''
46 [ "$1" = '-e' ] && ESPEAK=1
47 NOFLITE=''
48 [ "$1" = '-f' ] && NOFLITE=1
49 SPEECHD=''
50 [ "$1" = '-s' ] && SPEECHD=1
51
52 check4root || exit 1
53
54 # execute flite only if it's present
55 flitewrapper() {
56    if [ -x /usr/bin/flite -a -z "$NOFLITE" ] ; then
57       flite -o play -t "$*"
58    fi
59 }
60
61 # execute aumix
62 if [ -x /usr/bin/aumix -a -z "$NOAUMIX" ] ; then
63    einfo "Setting mixer levels to 90"
64    aumix -w 90 -v 90 -p 90 -m 90
65    eend $?
66 fi
67
68 # check for software synthesizer support
69 if ! [ -r /dev/softsynth ] ; then
70    if [ ! -d /proc/speakup/ ] && ! grep -q speakup /proc/modules ; then
71       ewarn "Kernel does not support software speakup - trying to load kernel module:" ; eend 0
72       eindent
73       einfo "Loading speakup_soft"
74       if modprobe speakup_soft ; then
75          eend 0
76       else
77          flitewrapper "Fatal error setting up software speakup"
78          eend 1
79          exit 1
80       fi
81       eoutdent
82    fi
83 fi
84
85 # the kernel module takes some time until it can be accessed
86 sleep 1
87
88 # helper functions for espeakup and speechd-up
89 espeak() {
90 if [ -x /usr/bin/espeakup ] ; then
91    espeakup
92 else
93    flitewrapper "espeakup not available, sorry."
94    return 1
95 fi
96 }
97
98 speechd() {
99 if [ -x /usr/bin/speechd-up ] ; then
100    /etc/init.d/speech-dispatcher start
101    nice -n -20 speechd-up
102 else
103    flitewrapper "speechd-up not available, sorry."
104    return 1
105 fi
106 }
107
108 # finally execute the according program:
109 if [ -n "$ESPEAK" ] ; then
110    espeak && exit 0 || exit 1
111 fi
112
113 if [ -n "$SPEECHD" ] ; then
114    speechd && exit 0 || exit 1
115 fi
116
117 if grep -q 'swspeak=espeak' /proc/cmdline ; then
118    ( espeak && exit 0 ) || ( speechd && exit 0 ) || exit 1
119 elif grep -q 'swspeak=speechd' /proc/cmdline ; then
120    ( speechd && exit 0 ) || ( espeak && exit 0 ) || exit 1
121 else
122    ( espeak && exit 0 ) || ( speechd && exit 0 ) || exit 1
123 fi
124
125 ## END OF FILE #################################################################
126 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3