This repository has been archived by the owner on Mar 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.sh
executable file
·323 lines (271 loc) · 5.97 KB
/
install.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#! /bin/sh
# sh -c "OPT=install; $(curl -fsSkL http://raw.github.com/Josef-Friedrich/Hue-shell/master/install.sh)"
# To restore values on upgrade
# sh -c "OPT=install;R_IP=192.168.2.31;R_USERNAME=joseffriedrich;R_ALL_LIGHTS=1,2,3,4,5,6,7,8,9;R_DEBUG=0;R_LOG=0; $(curl -fsSkL http://raw.github.com/Josef-Friedrich/Hue-shell/master/install.sh)"
if [ -f /etc/hue-shell/hue-shell.conf ]; then
# shellcheck disable=SC1091
. /etc/hue-shell/hue-shell.conf
elif [ -f ./config/hue-shell.conf ]; then
# shellcheck disable=SC1091
. ./config/hue-shell.conf
else
NO_CONFIG=1
fi
if [ -z "$OPT" ]; then
OPT=$1
fi
# shellcheck disable=SC2039
if type sudo > /dev/null ; then
_sudo() {
sudo "$@"
}
else
_sudo() {
"$@"
}
fi
_cp() {
echo "install: $*"
_sudo cp -f "$@"
}
_mkdir() {
echo "mkdir: $*"
_sudo mkdir -p "$@"
}
_rm() {
echo "uninstall: $*"
_sudo rm -rf "$@"
}
_usage() {
if [ -f "${PREFIX}/share/doc/hue-shell/hue-manager.txt" ] ; then
cat "${PREFIX}/share/doc/hue-shell/hue-manager.txt"
else
echo "Usage: $(basename "$0") (help|install|reinstall|upgrade|uninstall)"
fi
# shellcheck disable=SC2086
exit $1
}
_download() {
cd /tmp || exit
curl -fsSkL -o Hue-shell.tar.gz http://github.com/Josef-Friedrich/Hue-shell/archive/master.tar.gz
tar -xzvf Hue-shell.tar.gz
cd Hue-shell-master || exit
}
_install_base() {
# bin
_cp bin/hue* "$DIR_BIN"
_cp install.sh "$DIR_BIN/hue-manager"
# conf
_sudo mkdir -p "$DIR_CONF"
if [ -n "$UPGRADE" ]; then
_new_conf() {
_cp "./config/$1" "$DIR_CONF/$1.new"
}
_new_conf hue-shell.conf
_new_conf random-scenes.conf
_new_conf scenes/default.scene
else
if [ -f "$DIR_CONF/hue-shell.conf" ]; then
_cp "$DIR_CONF/hue-shell.conf" "$DIR_CONF/hue-shell.conf.bak"
fi
_cp -r config/* "$DIR_CONF"
fi
# doc
_mkdir "$DIR_DOC"
_cp doc/* "$DIR_DOC"
# lib
_mkdir "$DIR_LIB"
_cp base.sh "$DIR_LIB"
# log
_sudo touch "$FILE_LOG"
_sudo chmod 666 "$FILE_LOG"
# run
# By Hue-shell generated run files that should "survive" reboot.
_mkdir "$DIR_RUN_PERM"
_sudo chmod 777 "$DIR_RUN_PERM"
_sudo touch "$FILE_RANDOM_SEED"
_sudo chmod 666 "$FILE_RANDOM_SEED"
_sudo touch "$FILE_PIDS"
_sudo chmod 666 "$FILE_PIDS"
}
_install_services() {
# OpenWrt
if [ -f /etc/openwrt_version ]; then
echo "Installing init.d services ..."
_install() {
_cp "service/openwrt.initd/$1" "/etc/init.d/hue-$1"
if [ -z "$UPGRADE" ]; then
"/etc/init.d/hue-$1" enable
fi
}
_install load-default
_install detect-lights
_install detect-bridge
# systemd
elif command -v systemctl > /dev/null 2>&1; then
echo "Installing systemd services ..."
_install() {
_cp "service/systemd/$1" "/lib/systemd/system/hue-$1.service"
if [ -z "$UPGRADE" ]; then
_sudo systemctl enable "/lib/systemd/system/hue-$1.service"
fi
}
_install load-default
_install detect-lights
_install detect-bridge
# SysVinit
elif [ -d '/etc/init.d' ]; then
echo "Installing SysVinit services ..."
_install() {
_cp "service/SysVinit/$1" "/etc/init.d/$1"
}
_install load-default
fi
}
_install_triggerhappy() {
if [ -d /etc/triggerhappy/triggers.d ]; then
_cp triggerhappy/hue-shell.conf /etc/triggerhappy/triggers.d/
fi
}
_cleanup() {
_rm /tmp/Hue-shell-master
_rm /tmp/Hue-shell.tar.gz
}
_install() {
if [ ! -f ./bin/hue ]; then
_download
fi
if [ "$NO_CONFIG" = 1 ]; then
# shellcheck disable=SC1091
. ./config/hue-shell.conf
fi
_install_base
_install_services
_install_triggerhappy
_cleanup
}
_restore_configuration() {
_replace() {
_sudo sed -i.test.bak "s;$1;$2;" /etc/hue-shell/hue-shell.conf
}
while true ; do
case "$1" in
-a|--all-lights)
R_ALL_LIGHTS=$2
shift 2
;;
-d|--debug)
R_DEBUG=$2
shift 2
;;
-g|--gamut)
R_GAMUT=$2
shift 2
;;
-i|--ip)
R_IP=$2
shift 2
;;
-l|--log)
R_LOG=$2
shift 2
;;
-t|--test)
R_TEST=$2
shift 2
;;
-u|--username)
R_USERNAME=$2
shift 2
;;
*)
break
;;
esac
done
if [ -n "$R_ALL_LIGHTS" ]; then _replace 'ALL_LIGHTS="1,2,3"' "ALL_LIGHTS=\"$R_ALL_LIGHTS\"" ; fi
if [ -n "$R_DEBUG" ]; then _replace 'DEBUG=0' "DEBUG=$R_DEBUG" ; fi
if [ -n "$R_GAMUT" ]; then _replace 'GAMUT="B"' "GAMUT=\"$R_GAMUT\"" ; fi
if [ -n "$R_IP" ]; then _replace 'IP="192.168.1.2"' "IP=\"$R_IP\"" ; fi
if [ -n "$R_LOG" ]; then _replace 'LOG=0' "LOG=$R_LOG" ; fi
if [ -n "$R_TEST" ]; then _replace 'TEST=0' "TEST=$R_TEST" ; fi
if [ -n "$R_USERNAME" ]; then _replace 'USERNAME="yourusername"' "USERNAME=\"$R_USERNAME\"" ; fi
}
_uninstall() {
if [ "$1" = '--purge' ]; then
PURGE=1
shift
fi
if [ ! "$@" = '-y' ]; then
echo 'Uninstall hue-shell? (y|n): '
read -r COMFIRMATION
if [ ! "$COMFIRMATION" = 'y' ]; then
exit 1
fi
fi
_rm "$DIR_LIB"
_rm "$DIR_BIN"/hue*
_rm "$DIR_DOC"
if [ "$PURGE" = 1 ]; then
_rm "$DIR_CONF"
_rm "$DIR_RUN_PERM"
_rm "$DIR_RUN_TMP/$NAME-lights-reachable"
_rm "$DIR_RUN_TMP/$NAME-lights-all"
_rm "$DIR_LOG/$NAME.log"
_rm /etc/triggerhappy/triggers.d/hue-shell.conf
fi
# OpenWrt
if [ -f /etc/openwrt_version ]; then
_disable() {
"/etc/init.d/hue-$1" disable
}
_disable load-default
_disable detect-lights
_disable detect-bridge
elif command -v systemctl > /dev/null 2>&1; then
echo "Uninstall systemd services ..."
_disable() {
_sudo systemctl disable "hue-$1.service"
}
_disable load-default
_disable detect-lights
_disable detect-bridge
_rm /lib/systemd/system/hue*
fi
_rm /etc/init.d/hue-*
}
case "$OPT" in
help)
_usage
;;
install)
_install
if [ "$#" -gt 0 ]; then shift; fi
# shellcheck disable=SC2068
_restore_configuration $@
;;
purge)
# shellcheck disable=SC2068
_uninstall --purge $@
;;
reinstall)
_uninstall -y
_install
if [ "$#" -gt 0 ]; then shift; fi
# shellcheck disable=SC2068
_restore_configuration $@
;;
upgrade)
UPGRADE=1
_install
;;
uninstall)
# shellcheck disable=SC2068
_uninstall $@
;;
*)
_usage 1
;;
esac
# vim: set ts=8 sw=8 sts=8 et :
# sublime: tab_size 8;