-
Notifications
You must be signed in to change notification settings - Fork 340
/
Copy pathequip_test.sh
445 lines (332 loc) · 10.1 KB
/
equip_test.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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!/bin/sh
######################################################
# Xiaomi Yi hack
######################################################
#
# Features
# ========
#
# * no more cloud !
# * network configuration done in this file. No more need to use a Xiaomi app on a smartphone!
# * http server : port 80
# * telnet server : port 23
# * ftp server : port 21
# * rtsp server : port 554
# rtsp://192.168.1.121:554/ch0_0.h264 : replace with your ip
# rtsp://192.168.1.121:554/ch0_1.h264 : replace with your ip
#
# How it works
# ============
#
# See http://github.com/fritz-smh/yi-hack/
#
# TODO
# ====
#
# * strem audio from network to camera ==> svoxpico ?
# * create a watchdog script
led() {
# example usage :
# led -boff -yon
# options :
# -bfast
# -bon
# -boff
# -yfast
# -yon
# -yoff
# first, kill current led_ctl process
kill $(ps | grep led_ctl | grep -v grep | awk '{print $1}')
# then process
/home/led_ctl $@ &
}
LOG_DIR=/home/hd1/test/
LOG_FILE=${LOG_DIR}/log.txt
log_init() {
# clean the previous log file and add a starting line
echo "Starting to log..." > /home/hd1/test/log.txt
}
log() {
# do_logging
echo "$@" >> /home/hd1/test/log.txt
sync
}
get_config() {
key=$1
grep $1 /home/hd1/test/yi-hack.cfg | cut -d"=" -f2
}
### first we assume that this script is started from /home/init.sh and will replace it from the below lines (which are not commented in init.sh :
#if [ -f "/home/hd1/test/equip_test.sh" ]; then
# /home/hd1/test/equip_test.sh
# exit
#fi
######################################################
# start of our custom script !!!!!!
######################################################
### Launch Telnet server
log "Start telnet server..."
telnetd &
### configure timezone
echo "$(get_config TIMEZONE)" > /etc/TZ
### get time is done after wifi configuration!
### first, let's do as the orignal script does....
export LD_LIBRARY_PATH=/home/libusr:$LD_LIBRARY_PATH
mv /home/default.script /usr/share/udhcpc -f
rm /etc/resolv.conf
ln -s /tmp/resolv.conf /etc/resolv.conf
### TODO : comment this?
/home/log_server &
# some things from the original script...
cd /home
mount |grep "/tmp"
/home/productioninfoget.sh
insmod cpld_periph.ko
cd /home/3518
./load3518_audio -i
# added :
himm 0x20050074 0x06802424
### Let ppl hear that we start
/home/rmm "/home/hd1/voice/welcome.g726" 1
/home/rmm "/home/hd1/voice/wait.g726" 1
### start blinking blue led for configuration in progress
#/home/led_ctl -boff -yon &
led -yoff -bfast
insmod /home/mtprealloc7601Usta.ko
insmod /home/mt7601Usta.ko
ifconfig ra0 up
### INFORMATION : the 'clic' 'clic' is done after this line
sysctl -w fs.mqueue.msg_max=256
mkdir /dev/mqueue
mount -t mqueue none /dev/mqueue
#insmod /home/cpld_wdg.ko
#insmod /home/cpld_periph.ko
#insmod /home/iap_auth.ko
/home/gethwplatform
#now begin app
sysctl -w net.ipv4.tcp_mem='3072 4096 2000000'
sysctl -w net.core.wmem_max='2000000'
sysctl -w net.ipv4.tcp_keepalive_time=300 net.ipv4.tcp_keepalive_intvl=6 net.ipv4.tcp_keepalive_probes=3
insmod /home/as-iosched.ko
echo "anticipatory" > /sys/block/mmcblk0/queue/scheduler
echo "1024" > /sys/block/mmcblk0/queue/read_ahead_kb
### The followinf unmount+mount of hd1 allows a rw mount (on startup, it is ro mounted)
umount /home/hd1
umount /home/hd2
mount -t vfat /dev/hd1 /home/hd1
mkdir /home/hd1/record
mkdir /home/hd1/record_sub
mount -t vfat /dev/hd2 /home/hd2
mkdir /home/hd2/record_sub
rm /home/web/sd/* -rf
cd /home/3518
./load3518_left -i
### Detect the hardware version
# result will be written in /tmp/hwplatform
/home/detect_ver
himm 0x20050074 0x06802424
### what is this ?
cd /home
./peripheral &
./dispatch &
./exnet &
#./mysystem &
count=5
while [ $count -gt 0 ]
do
if [ -f "/tmp/init_finish" ]; then
break
else
count=`expr $count - 1`
echo "wait init" $count
sleep 1
fi
done
### INFORMATION : the 'clic' 'clic' is done before this line
### we copy our wpa_supplicant file in /home
cp /home/hd1/test/wpa_supplicant.conf /home/wpa_supplicant.conf
### Init logs
log_init
# Put version informations in logs and a file which will be included in the http server default page
TMP_VERSION_FILE=/tmp/version_information
rm -f ${TMP_VERSION_FILE}
echo "Hardware version informations : " >> ${TMP_VERSION_FILE}
cat /tmp/hwplatform | sed "s/^/ /" >> ${TMP_VERSION_FILE}
echo "Software version informations : " >> ${TMP_VERSION_FILE}
cat /home/version | sed "s/^/ /" >> ${TMP_VERSION_FILE}
FIRMWARE_LETTER=$(cat /home/version | grep "version=" | head -1 | cut -d"=" -f2 | sed "s/^[0-9]\.[0-9]\.[0-9]\.[0-9]\([A-Z]\).*/\1/")
echo "Firmware letter is : '${FIRMWARE_LETTER}'" >> ${TMP_VERSION_FILE}
cat ${TMP_VERSION_FILE} >> ${LOG_FILE}
case ${FIRMWARE_LETTER} in
# 1.8.6.1
A) # NOT TESTTED YET
RTSP_VERSION='M'
HTTP_VERSION='M'
;;
# 1.8.5.1
M) # Tested :)
RTSP_VERSION='M'
HTTP_VERSION='M'
;;
L) # Tested :)
RTSP_VERSION='M'
HTTP_VERSION='M'
;;
K) # NOT TESTED YET
RTSP_VERSION='K'
HTTP_VERSION='M'
;;
B|E|F|H|I|J) # NOT TESTED YET
RTSP_VERSION='I'
HTTP_VERSION='J'
;;
*)
RTSP_VERSION='M'
HTTP_VERSION='M'
log "WARNING : I don't know which RTSP binary version is compliant with your firmware! I will try to use the M..."
;;
esac
log "The RTSP server binary version which will be used is the '${RTSP_VERSION}'"
log "The HTTP server binary version which will be used is the '${HTTP_VERSION}'"
log "Check for some files size..."
ls -l /home/hd1/test/rtspsvr* /home/hd1/test/http/server* | sed "s/^/ /" >> ${LOG_FILE}
log "The blue led is currently blinking"
log "Debug mode = $(get_config DEBUG)"
# first, configure wifi
### Let ppl hear that we start connect wifi
/home/rmm "/home/hd1/voice/connectting.g726" 1
log "Check for wifi configuration file...*"
log $(find /home -name "wpa_supplicant.conf")
log "Start wifi configuration..."
res=$(/home/wpa_supplicant -B -i ra0 -c /home/wpa_supplicant.conf )
log "Status for wifi configuration=$? (0 is ok)"
log "Wifi configuration answer: $res"
log "Do network configuration 1/2 (ip and gateway)"
#ifconfig ra0 192.168.1.121 netmask 255.255.255.0
#route add default gw 192.168.1.254
ifconfig ra0 $(get_config IP) netmask $(get_config NETMASK)
route add default gw $(get_config GATEWAY)
log "Done"
log "Configuration is :"
ifconfig | sed "s/^/ /" >> ${LOG_FILE}
### configure DNS (google one)
log "Do network configuration 2/2 (DNS)"
echo "nameserver $(get_config NAMESERVER)" > /etc/resolv.conf
log "Done"
### configure time on a NTP server
log "Get time from a NTP server..."
NTP_SERVER=$(get_config NTP_SERVER)
log "But first, test the NTP server '${NTP_SERVER}':"
ping -c1 ${NTP_SERVER} >> ${LOG_FILE}
log "Previous datetime is $(date)"
ntpd -q -p ${NTP_SERVER}
log "Done"
log "New datetime is $(date)"
### Check if reach gateway and notify
ping -c1 -W2 $(get_config GATEWAY) > /dev/null
if [ 0 -eq $? ]; then
/home/rmm "/home/hd1/voice/wifi_connected.g726" 1
fi
### set the root password
root_pwd=$(get_config ROOT_PASSWORD)
[ $? -eq 0 ] && echo "root:$root_pwd" | chpasswd
### start blue led for configuration finished
log "Start blue led on"
led -yoff -bon
### Rename the timeout sound file to avoid being spammed with chinese audio stuff...
[ -f /home/timeout.g726 ] && mv /home/timeout.g726 /home/timeout.g726.OFF
sync
### Launch FTP server
log "Start ftp server..."
if [[ $(get_config DEBUG) == "yes" ]] ; then
tcpsvd -vE 0.0.0.0 21 ftpd -w / > /${LOG_DIR}/log_ftp.txt 2>&1 &
else
tcpsvd -vE 0.0.0.0 21 ftpd -w / &
fi
sleep 1
log "Check for ftp process : "
ps | grep tcpsvd | grep -v grep >> ${LOG_FILE}
### Launch web server
# first, prepare the index.html page
cd /home/hd1/test/http/
cat index.html.tpl_header ${TMP_VERSION_FILE} index.html.tpl_footer > index.html
# then, bind the record folder
mkdir /home/hd1/test/http/record/
mount -o bind /home/hd1/record/ /home/hd1/test/http/record/
# prepare the GET /motion url
touch /home/hd1/test/http/motion
# start the server
log "Start http server : server${HTTP_VERSION}..."
if [[ $(get_config DEBUG) == "yes" ]] ; then
./server${HTTP_VERSION} 80 > /${LOG_DIR}/log_http.txt 2>&1 &
else
./server${HTTP_VERSION} 80 &
fi
sleep 1
log "Check for http server process : "
ps | grep server | grep -v grep | grep -v log_server >> ${LOG_FILE}
sync
### Launch record event
cd /home
./record_event &
./mp4record 60 &
### Some configuration
himm 0x20050068 0x327c2c
#himm 0x20050068 0x0032562c
himm 0x20050074 0x06802424
himm 0x20050078 0x18ffc001
#himm 0x20050078 0x1effc001
himm 0x20110168 0x10601
himm 0x20110188 0x10601
himm 0x20110184 0x03ff2
himm 0x20030034 0x43
himm 0x200300d0 0x1
himm 0x2003007c 0x1
himm 0x20030040 0x102
himm 0x20030040 0x202
himm 0x20030040 0x302
himm 0x20030048 0x102
himm 0x20030048 0x202
himm 0x20030048 0x302
rm /home/hd1/FSCK*
# Check and create crontabs folder
crontab_folder="/var/spool/cron/crontabs"
if [ ! -r "$crontab_folder" ]; then
mkdir -p "$crontab_folder"
fi
# Start crond daemon
/usr/sbin/crond -b
### Final led color
### Check if reach gateway and notify
ping -c1 -W2 $(get_config GATEWAY) > /dev/null
if [ 0 -eq $? ]; then
led $(get_config LED_WHEN_READY)
/home/rmm "/home/hd1/voice/success.g726" 1
else
led -boff -yfast
fi
### Rmm stuff
# without this, most things does not work (http server, rtsp)
# It starts to use the cloud (which is no more launched) so you will find timeout in the logs
# This must be launched after all "/home/rmm" command calls
cd /home
./rmm &
### Rtsp server
cd /home/hd1/test/
log "Start rtsp server : rtspsvr${RTSP_VERSION}..."
if [[ $(get_config DEBUG) == "yes" ]] ; then
./rtspsvr${RTSP_VERSION} > /${LOG_DIR}/log_rtsp.txt 2>&1 &
else
./rtspsvr${RTSP_VERSION} &
fi
sleep 1
log "Check for rtsp process : "
ps | grep rtspsvr | grep -v grep >> ${LOG_FILE}
sleep 5
### List the processes after startup
log "Processes after startup :"
ps >> ${LOG_FILE}
### List storage status
log "Storage status :"
df -h >> ${LOG_FILE}
### to make sure log are written...
sync