-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheloi
More file actions
executable file
·107 lines (98 loc) · 4.06 KB
/
eloi
File metadata and controls
executable file
·107 lines (98 loc) · 4.06 KB
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
#!/bin/bash -ue
# electric light orchestration
# CLI interface to tellstick / tdtool / telldusd
# network enabled, like it's from the far future or something!
#
# Copyright (c) 2012 Christian Bryn <chr.bryn@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
listen_port=9700
prompt() {
echo "> $@"
}
print_usage() {
cat <<EOF
Usage: ${0} [-h|-l|-p|-a]
-h Halp.
-l Listen for remote connections
-p Listen port, used with -l (default: $listen_port)
-a Announce telnet service using avahi (use with listen)
EOF
}
function kill_children() {
# XXX: fix this
c=$( jobs -p )
[ "${c}" == "" ] || kill $( jobs -p ) >/dev/null 2>&1 || true
}
trap "kill_children" EXIT
# default config
listen="false"
announce="false"
while getopts hp:la o
do
case $o in
h)
print_usage ; exit ;;
p)
listen_port="${OPTARG}" ;;
l)
listen="true" ;;
a)
if ( which avahi-publish-service >/dev/null )
then
announce="true"
else
echo "error> avahi-publish-service not found in PATH, service announcement not enabled "
fi
;;
esac
done
shift $(($OPTIND-1))
# avahi-publish-service prints info messages to stderr...
[ "${listen}" == "true" -a "${announce}" == "true" ] && avahi-publish-service eloi _telnet._tcp 9700 "Control lights and stuff" >/dev/null 2>&1 &
[ "${listen}" == "true" ] && { socat tcp-listen:${listen_port},reuseaddr,fork,crlf system:"${0}",pty,stderr,sigint,sane,setsid,echo=0 ; exit; }
prompt ' _ '
prompt ' ___| | ___ '
prompt ' / _ \ |/ _ \ '
prompt '| __/ | (_) |'
prompt ' \___|_|\___/ '
prompt ''
prompt '* electric light orchestration *'
prompt welcome to elo - YOUR interface to futuristic home CONTRLOL
prompt "available commands are list,learn,on <device>,off <device>,dim <device> [<value>],help,exit"
prompt 'valid values for dim are 0-255'
while read -p '> ' command arg val; do
case $command in
'')
continue ;;
help)
prompt 'available commands: list,learn,on,off,help,exit' ;;
list)
tdtool -l | egrep -v "^$" | sed 1d || { prompt "'$command' command failed"; continue; } ;;
on)
[ "${arg:-}" == "" ] && { prompt "'$command' needs an argument (id or name)"; continue; }
tdtool -n $arg || { prompt "'$command' command failed"; continue; } ;;
off)
[ "${arg:-}" == "" ] && { prompt "'$command' needs an argument (id or name)"; continue; }
tdtool -f $arg || { prompt "'$command' command failed"; continue; } ;;
dim)
[ "${arg:-}" == "" ] && { prompt "'$command' needs an argument (id or name)"; continue; }
if [ "${val:-}" == "" ]
then
tdtool --dim "$arg" || { prompt "'$command' command failed"; continue; }
else
tdtool --dimlevel "$val" --dim "$arg" || { prompt "'$command' command failed"; continue; }
fi ;;
learn)
[ "${arg:-}" == "" ] && { prompt "'$command' needs an argument (id or name)"; continue; }
tdtool -e $arg || { prompt "'$command' command failed!"; continue; } ;;
exit)
break ;;
*)
echo "unknown command '$command'" ; continue ;;
esac
done