-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
413 lines (368 loc) · 13.6 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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#!/bin/bash
# installer zway to raspberry
USER=domojs
INSTALL_DIR=/home
DOMOJS_DIR=$INSTALL_DIR/$USER
TEMP_DIR=/tmp
##### The percentage of updates #####
write_upi "10%\nStarting upgrading"
#####################################
# Check for root priviledges
if [[ $(id -u) != 0 ]]
then
echo "Superuser (root) priviledges are required to install domojs"
echo "Please do 'sudo -s' first"
exit 1
fi
# Check if Z-Way was already installed
upgrade_domojs="no"
if [[ -d $DOMOJS_DIR ]]; then
upgrade_domojs="yes"
else
echo "domojs new installation"
fi
echo "Installing additional libraries"
apt-get -y update
apt-get -qy install git
echo "Installing additional libraries for HomeKit"
apt-get -qy install libavahi-compat-libdnssd-dev
git clone https://github.com/domojs/domojs $TEMP_DIR
# If downloading and extracting is ok, then make backup and move z-way-server from /tmp to /data
if [[ "$?" -eq "0" ]]; then
# if need upgrade
if [[ "$upgrade_domojs" = "yes" ]]; then
echo "Previous domojs installation found"
# Stopping domojs
if [[ -e /etc/systemd/system/multi-user.target.wants/domojs.service ]]
then
systemctl stop domojs
fi
# Make backup
TMP_DOMOJS_DIR=${DOMOJS_DIR}_$(date "+%Y-%m-%d-%H-%M-%S")
echo "Making backup of previous version of domojs in $TMP_DOMOJS_DIR"
mv $DOMOJS_DIR $TMP_DOMOJS_DIR
mv $TEMP_DIR/z-way-server $INSTALL_DIR/
# Copy old configuration files to the new location
echo "Copying settings"
cp $TMP_DOMOJS_DIR/config/Configuration.xml $DOMOJS_DIR/config/
cp $TMP_DOMOJS_DIR/config/Rules.xml $DOMOJS_DIR/config/
cp -R $TMP_DOMOJS_DIR/config/maps $DOMOJS_DIR/config/
cp -R $TMP_DOMOJS_DIR/config/zddx $DOMOJS_DIR/config/
if [[ -e $TMP_DOMOJS_DIR/automation/.syscommand ]]
then
cp $TMP_DOMOJS_DIR/automation/.syscommand $DOMOJS_DIR/automation/.syscommand
fi
if [[ -d $TMP_DOMOJS_DIR/automation/storage ]]
then
rm -Rf $DOMOJS_DIR/automation/storage
cp -R $TMP_DOMOJS_DIR/automation/storage $DOMOJS_DIR/automation/
fi
if [[ -d $TMP_DOMOJS_DIR/automation/userModules ]]
then
rm -Rf $DOMOJS_DIR/automation/userModules
cp -R $TMP_DOMOJS_DIR/automation/userModules $DOMOJS_DIR/automation/
fi
if ! diff $DOMOJS_DIR/config.xml $TMP_DOMOJS_DIR/config.xml -w > /dev/null
then
echo "config.xml replaced by the new one - make sure to restore your changes"
echo "diff $DOMOJS_DIR/config.xml $TMP_DOMOJS_DIR/config.xml:"
diff $DOMOJS_DIR/config.xml $TMP_DOMOJS_DIR/config.xml -w
echo
fi
echo "!!! Defaults.xml and config.xml updated with new versions !!!"
else
mv $TEMP_DIR/z-way-server $INSTALL_DIR/
echo "New version z-way-server installed"
fi
else
write_upi "30%\nDownloading and extracting z-way-server failed"
echo "Downloading and extracting z-way-server failed"
echo "Exiting"
exit 1
fi
mkdir -p /etc/z-way
echo "v2.0.1" > /etc/z-way/VERSION
echo "razberry" > /etc/z-way/box_type
# Create Z-Way startup script
echo "Creating Z-Way startup script"
echo '#! /bin/sh
### BEGIN INIT INFO
# Provides: z-way-server
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: RaZberry Z-Wave service
# Description: Start Z-Way server for to allow Raspberry Pi talk with Z-Wave devices using RaZberry
### END INIT INFO
# Description: RaZberry Z-Way server
# Author: Yurkin Vitaliy <[email protected]>
PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=z-way-server
DAEMON_PATH=/opt/z-way-server
PIDFILE=/var/run/$NAME.pid
# adding z-way libs to library path
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/z-way-server/libs
case "$1" in
start)
echo -n "Starting z-way-server: "
start-stop-daemon --start --pidfile $PIDFILE --make-pidfile --background --no-close --chdir $DAEMON_PATH --exec $NAME > /dev/null 2>&1
echo "done."
;;
stop)
echo -n "Stopping z-way-server: "
start-stop-daemon --stop --quiet --pidfile $PIDFILE
rm $PIDFILE
echo "done."
;;
restart)
echo "Restarting z-way-server: "
sh $0 stop
sleep 10
sh $0 start
;;
save)
echo "Saving z-way-server configuration"
PID=`sed s/[^0-9]//g $PIDFILE`
/bin/kill -10 $PID
;;
*)
echo "Usage: /etc/init.d/z-way-server {start|stop|restart|save}"
exit 1
;;
esac
exit 0' > /etc/init.d/z-way-server
chmod +x /etc/init.d/z-way-server
# Add z-way-server.log to logrotate
echo '/var/log/z-way-server.log {
daily
size=10M
rotate 4
compress
nodelaycompress
missingok
notifempty
postrotate
/usr/bin/killall -HUP z-way-server 2>/dev/null || true
endscript
}' > /etc/logrotate.d/z-way-server
# Add Z-Way to autostart
echo "Adding z-way-server to autostart"
update-rc.d z-way-server defaults
##### The percentage of updates #####
write_upi "70%\nGetting Webif for Raspberry Pi and installing"
#####################################
# Getting Webif and installing
echo "Getting Webif for Raspberry Pi and installing"
wget -4 http://razberry.z-wave.me/webif_raspberry.tar.gz -O - | tar -zx -C /
# If first install, get new ID
if [[ ! -e /etc/init.d/zbw_connect ]]
then
echo "First install, getting razberry ID"
echo '#!/bin/bash
### BEGIN INIT INFO
# Provides: zbw_autosetup
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: zbw_autosetup
# Description: the script setup a zbw_connect script
### END INIT INFO
function delete_me()
{
insserv -r zbw_autosetup
rm -f /etc/init.d/zbw_autosetup
rm -f $0
}
if [[ $0 == "/tmp/zbw_autosetup" ]]; then
delete_me;
exit
fi
case "$1" in
start)
# if we already have zbw_connect, delete ourself
if [[ -x /etc/init.d/zbw_connect ]]; then
# a hack to eliminate an error on a remouting / ro
cp $0 /tmp/zbw_autosetup
exec /tmp/zbw_autosetup
fi
if wget -4 http://find.zwave.me/zbw_new_user -O /tmp/zbw_connect_setup.run; then
sleep 10
if bash /tmp/zbw_connect_setup.run; then
/etc/init.d/zbw_connect start
# a hack to eliminate an error on a remouting / ro
cp $0 /tmp/zbw_autosetup
exec /tmp/zbw_autosetup
fi
mount -o remount,ro /
fi
;;
esac
' > /etc/init.d/zbw_autosetup
chmod +x /etc/init.d/zbw_autosetup
/etc/init.d/zbw_autosetup start
else
# Update zbw_connect to new version
cd /etc/init.d/
./zbw_connect stop
echo 'begin-base64 644 zb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WFRZUEU9JEJPWFRZUEUKCndo
aWxlIHRydWUKZG8KICAgIGdldF9sb2NhbF9pcHMKCiAgICBzc2ggLWkgL3Rt
cC96YndfY29ubmVjdC5wcml2IC1UIC1vICdTdHJpY3RIb3N0S2V5Q2hlY2tp
bmcgbm8nIC1vICdVc2VyS25vd25Ib3N0c0ZpbGUgL2Rldi9udWxsJyAtbyAn
QmF0Y2hNb2RlIHllcycgLW8gJ1NlbmRFbnYgWkJXXyonIC1vICJFeGl0T25G
b3J3YXJkRmFpbHVyZSB5ZXMiIC1vICJTZXJ2ZXJBbGl2ZUludGVydmFsIDMw
IiAtbyAiU2VydmVyQWxpdmVDb3VudE1heCAzIiAkRldEX09QVFMgJFNTSF9V
U0VSQCRTRVJWRVIKICAgIHNsZWVwIDEKZG9uZQoKZXhpdCAwCg==
====' | uudecode -o zbw_connect.new
tail -n 29 zbw_connect >> zbw_connect.new
mv zbw_connect.new zbw_connect
chmod +x zbw_connect
echo "zbw_connect patched"
./zbw_connect start
fi
##### The percentage of updates #####
write_upi "80%\nGetting webserver mongoose for Webif"
#####################################
# Getting webserver mongoose for webif
cd $TEMP_DIR
if [[ -e mongoose.pkg.rPi.tgz ]]; then
echo "Removing duplicate of mongoose"
rm -rf mongoose.pkg.rPi.tgz
fi
echo "Getting webserver mongoose for Webif"
wget -4 http://razberry.z-wave.me/mongoose.pkg.rPi.tgz -P $TEMP_DIR
##### The percentage of updates #####
write_upi "90%\nRestarting Webif and Z-Way"
#####################################
# Stopping mongoose
if [[ -e /etc/init.d/mongoose ]]
then
echo "Stopping mongoose http server"
/etc/init.d/mongoose stop
fi
# Installing webserver mongoose for webif
tar -zxf $TEMP_DIR/mongoose.pkg.rPi.tgz -C /
# Adding webserver to autostart
echo "Adding mongoose to autostart"
update-rc.d mongoose defaults
# Starting webserver mongoose
echo "Start mongoose http server"
/etc/init.d/mongoose start
# Prepare AMA0
sed 's/console=ttyAMA0,115200//; s/kgdboc=ttyAMA0,115200//' /boot/cmdline.txt > /tmp/zway_install_cmdline.txt
sed 's|[^:]*:[^:]*:respawn:/sbin/getty[^:]*ttyAMA0[^:]*||' /etc/inittab > /tmp/zway_install_inittab
# Transform old DevicesData.xml to new format
(cd $DOMOJS_DIR && test -x ./z-cfg-update && ls -1 config/zddx/*.xml | LD_LIBRARY_PATH=./libs xargs -l ./z-cfg-update)
if diff /boot/cmdline.txt /tmp/zway_install_cmdline.txt > /dev/null || diff /etc/inittab /tmp/zway_install_inittab > /dev/null
then
rm /tmp/zway_install_cmdline.txt /tmp/zway_install_inittab
# Starting z-way-server mongoose
echo "Starting z-way-server"
/etc/init.d/z-way-server start
else
echo "Preparing AMA0 interface:"
echo " removing 'console=ttyAMA0,115200' and 'kgdboc=ttyAMA0,115200' from kernel command line (/boot/cmdline.txt)"
mv /tmp/zway_install_cmdline.txt /boot/cmdline.txt
echo " removing '*:*:respawn:/sbin/getty ttyAMA0' from /etc/inittab"
mv /tmp/zway_install_inittab /etc/inittab
echo "AMA0 interface reconfigured, please restart Raspberry"
fi
# Make sure to save changes
sync
# Subscribe user to news
if [[ "$BOXED" != "yes" ]]
then
echo "Do you want to receive emails with news about RaZberry project?"
echo "! Please subscribe again if you did it before 30.03.2013"
while true
do
echo -n "yes/no: "
read ANSWER < /dev/tty
case $ANSWER in
yes)
echo -n "Enter your email address: "
read EMAIL < /dev/tty
curl -d "email=$EMAIL" http://razberry.z-wave.me/subscribe.php
break
;;
no)
break
;;
esac
echo "Please answer yes or no"
done
fi
echo "Thank you for using RaZberry!"
exit 0