-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathttsqueue-cli.sh
executable file
·169 lines (143 loc) · 3.44 KB
/
ttsqueue-cli.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
# Define ttsqueue root
TTSROOT=$(dirname $0)
# Do some checks
if [ ! -f $TTSROOT/ttsqueue.conf ]; then
echo -e ""
echo -e "ERROR: Config file ttsqueue.conf in $TTSROOT not found"
echo -e ""
exit 10;
else
# Load configuration
source $TTSROOT/ttsqueue.conf
# Check: Given user
TTSUSERID=$(cat /etc/passwd | grep $TTSUSER | cut -d ":" -f4)
if ( [ "$?" -ne 0 ] && [ "$UID" -ne 0 ] ) ; then
echo -e ""
echo -e "ERROR: Please run this script only with user root or $TTSUSER"
echo -e ""
exit 12;
fi
# Check: Variable defined
if [ ! $TTSQUEUE ]; then
echo -e ""
echo -e "ERROR: TTSQUEUE not defined in ttsqueue.conf"
echo -e ""
exit 11;
fi
# Check: Path exist
if [ ! -d $TTSQUEUE ]; then
echo -e ""
echo -e "ERROR: Queue path $TTSQUEUE does not exist"
echo -e ""
exit 12;
fi
# Check: User can write
if [ ! -w $TTSQUEUE ]; then
echo -e ""
echo -e "ERROR: Queue path $TTSQUEUE is not writeable by user $TTSUSER"
echo -e ""
exit 13;
fi
fi
# Some default defintions
TTS=""
# Function for displaying help
function usage {
echo -e ""
echo -e "Usage:"
echo -e " ttsqueue-cli.sh action parameter"
echo -e ""
echo -e "Actions:"
echo -e ""
echo -e " add\t\t\tAdd text to text-to-speach queue."
echo -e "\t\t\tParameter is the text to be spoken. Script returns the id of the queued text."
echo -e ""
echo -e "\t\t\tExample:"
echo -e "\t\t\t\tuser@pc:/home/user>ttsqueue-cli.sh add \"This is a test\""
echo -e "\t\t\t\t7263"
echo -e "\t\t\t\tuser@pc:/home/user>"
echo -e ""
echo -e " check\t\t\tCheck text is already spoken."
echo -e "\t\t\tScript returns exit codes: 0 = not spoken, 1 = spoken/removed."
echo -e ""
echo -e "\t\t\tExample:"
echo -e "\t\t\t\tuser@pc:/home/user>ttsqueue-cli.sh check 7263"
echo -e "\t\t\t\tuser@pc:/home/user>echo \$?"
echo -e "\t\t\t\t0"
echo -e "\t\t\t\tuser@pc:/home/user>"
echo -e ""
echo -e " remove\t\tRemove text from text-to-speach queue."
echo -e "\t\t\tParameter is the id which was returned during action add. Script returns exit codes: 0 = success, 1 = failed (text maybe already spoken)."
echo -e ""
echo -e "\t\t\tExample:"
echo -e "\t\t\t\tuser@pc:/home/user>ttsqueue-cli.sh remove 7263"
echo -e "\t\t\t\tuser@pc:/home/user>echo \$?"
echo -e "\t\t\t\t1"
echo -e "\t\t\t\tuser@pc:/home/user>"
echo -e ""
}
# Handling with parameters
case $1 in
# Handle parameter add
add)
# If no text given, return error
if [ "$2" == "" ] ; then
echo -e ""
echo -e "ERROR: No text for speach given"
echo -e ""
exit 14;
# If text given, queue
else
TTS="$2"
echo "$TTS" > $TTSQUEUE/$$
chown $TTSUSER $TTSQUEUE/$$
echo $$
exit 0;
fi
;;
# Handle parameter remove
remove)
# If no id given, return error
if [ "$2" == "" ] ; then
echo -e ""
echo -e "ERROR: No text id given"
echo -e ""
exit 15
# Handle remove of text
else
# If text exists/is removable, do it
if [ -w $TTSQUEUE/$2 ] ; then
rm $TTSQUEUE/$2 >/dev/null 2>&1
exit 0;
# If text already spoken/not removeable, return error code
else
exit 1;
fi
fi
;;
# Handle parameter remove
check)
# If no id given, return error
if [ "$2" == "" ] ; then
echo -e ""
echo -e "ERROR: No text id given"
echo -e ""
exit 15
# Handle remove of text
else
# If text exists, report it
if [ -f $TTSQUEUE/$2 ] ; then
exit 0;
# If text already spoken, report it
else
exit 1;
fi
fi
;;
*)
usage;
exit 20;
;;
esac
exit 0