-
Notifications
You must be signed in to change notification settings - Fork 3
/
ip-read
executable file
·60 lines (53 loc) · 1.86 KB
/
ip-read
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
#!/bin/bash
#
# ip-read :: read the IP address using espeak
#
# 0.1 - Chris Tyler, Seneca College <chris.tyler@senecacollege.ca> 2012-07-17
# 0.2 - Chris Tyler, Seneca College <chris.tyler@senecacollege.ca> 2013-03-26
#
# ip-info
#
# Copyright (C)2012 Chris Tyler, Seneca College, and others (see above)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
#
# IP address (first IPv4 address that is not loopback)
if [ -x /usr/sbin/ip ]
then
IP=$(ip addr|sed -n "s/^[[:space:]]\+inet \([0-9.]\+\).*/\1/p"|
grep -v 127.0.0.1|head -1)
elif [ -x /usr/bin/ifconfig ]
then
IP=$(ifconfig|sed -n "s/.*inet [^0-9]*\([0-9.]\+\) .*/\1/p"|
grep -v 127.0.0.1|head -1)
else
echo "$0: Cannot determine IP address - /usr/sbin/{ip,ifconfig} missing" >&2
exit 1
fi
if [ "$IP" = "" ]
then
echo "$0: No IPv4 address found." >&2
exit 2
fi
# Reformatted for speaking
IPWORDS="$(echo "$IP"|sed -e "s/\./, dot, /g" -e "s/^/IP address: /")"
if [ "$(id -u)" = 0 ] # Work around root pulseaudio access
then
export AUDIODRIVER=alsa
espeak "$IPWORDS. Repeat, $IPWORDS" --stdout|play -t wav - >/dev/null 2>&1
else
echo "$IPWORDS. Repeat, $IPWORDS"|espeak
fi