-
Notifications
You must be signed in to change notification settings - Fork 3
/
ip-flash
executable file
·112 lines (101 loc) · 2.93 KB
/
ip-flash
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
#!/bin/bash
#
# ip-flash :: flash the IP address on led0 (or the specified LED) of a system
#
# 1 - 9 short flashes indicate the digits 1 - 9
# 10 short flashes indicate the digit 0
# a long flash indicates an octet separator (dot)
# a brief pause separates digits
#
# Arguments:
# $1 - directory for LED control (default /sys/class/leds/led0)
#
# Note: This script requires trigger control of the specified LED - the kernel
# must provide the none and default-on targets for the LED trigger, and
# this script must be executed with appropriate privilege (root by default).
#
# The default LED is valid for the Raspberry Pi and some other development
# boards.
#
# 0.1 - Chris Tyler, Seneca College <[email protected]> 2012-07-17
# 0.2 - Chris Tyler, Seneca College <[email protected]> 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
#
# Control directory for the LED
CTL=${1:-/sys/class/leds/led0}
# 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
# Flash on designated LED
if cd ${CTL} >/dev/null 2>&1
then
SAVE=$(sed "s/.*\[\(.*\)\].*/\1/" trigger) # Save LED trigger state
for REPEAT in 1 2
do
echo none > trigger
sleep 4
for ((x=0; x<${#IP}; x++))
do
DIGIT=${IP:$x:1}
if [[ "$DIGIT" = "." ]]
then
echo default-on > trigger
echo 255 > brightness
sleep 1.5
echo none > trigger
sleep 1.5
else
if [[ "$DIGIT" = 0 ]]
then
DIGIT=10
fi
for ((y=0; y<DIGIT; y++))
do
echo default-on >trigger
sleep 0.25
echo none > trigger
sleep 0.25
done
sleep 1.5
fi
done
sleep 4
echo $SAVE > trigger
done
else
echo "$0: LED control directory $CTL does not exist." >&2
exit 3
fi