-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodify1timage.sh
More file actions
656 lines (558 loc) · 27.2 KB
/
modify1timage.sh
File metadata and controls
656 lines (558 loc) · 27.2 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
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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
#!/bin/bash
# Author: Dennis Giese [dgiese@dontvacuum.me]
# Copyright 2017 by Dennis Giese
BASE_DIR="."
FLAG_DIR="."
IMG_DIR="./squashfs-root"
FEATURES_DIR="./features"
if [[ "$OSTYPE" != "linux-gnu"* ]]; then
echo "WARNING: Unsupported OS, image generation might fail or create bad images. Do not proceed if you are not sure what you are doing"
echo "press CTRL+C to abort"
sleep 5
fi
command -v unzip >/dev/null 2>&1 || { echo "ERROR: unzip command not found, aborting"; exit 1; }
command -v unsquashfs >/dev/null 2>&1 || { echo "ERROR: unzip command not found, aborting"; exit 1; }
command -v mksquashfs >/dev/null 2>&1 || { echo "ERROR: unzip command not found, aborting"; exit 1; }
command -v install >/dev/null 2>&1 || { echo "ERROR: install command not found, aborting"; exit 1; }
command -v md5sum >/dev/null 2>&1 || { echo "ERROR: md5sum command not found, aborting"; exit 1; }
command -v git >/dev/null 2>&1 || { echo "ERROR: git command not found, aborting"; exit 1; }
if [ ! -f ${BASE_DIR}/update.zip ]; then
echo "ERROR: File update.zip not found! Decryption and unpacking was apparently unsuccessful."
echo "please create zip file that contains rootfs.img, boot.img and mcu.bin. Make sure that the files are compatible with your device"
exit 1
fi
if [ ! -f ${BASE_DIR}/authorized_keys ]; then
echo "ERROR: authorized_keys not found. Please create your authorized_keys file first (it contains the public portion of your ssh key, likely starting with ssh-rsa)."
exit 1
fi
if [ ! -f ${FLAG_DIR}/devicetype ]; then
echo "ERROR: devicetype definition not found, aborting"
echo "you likely want to set the flags manually or by running _buildflags.sh from dustbuilder"
exit 1
fi
if [ ! -f ${FLAG_DIR}/jobid ]; then
echo "ERROR: jobid not found, aborting"
echo "you likely want to set the flags manually or by running _buildflags.sh from dustbuilder"
exit 1
fi
if [ ! -d ${FEATURES_DIR} ]; then
echo "ERROR: Features directory not found. You might want to clone the repo from https://github.com/dgiese/dustbuilder-features to ${FEATURES_DIR}, aborting"
exit 1
fi
DEVICETYPE=$(cat "${FLAG_DIR}/devicetype")
FRIENDLYDEVICETYPE=$(cat "${FLAG_DIR}/devicetype")
jobid=$(cat "${FLAG_DIR}/jobid")
jobidmd5=$(cat "${FLAG_DIR}/jobid" | md5sum | awk '{print $1}')
mkdir -p ${BASE_DIR}/output
echo "--------------"
echo "creating temp directory and unpacking squashfs"
unzip ${BASE_DIR}/update.zip
rm ${BASE_DIR}/update.zip
unsquashfs -d ${IMG_DIR} ${BASE_DIR}/rootfs.img
if [ -f ${BASE_DIR}/rootfs.img.vanilla ]; then
echo "moving vanilla image to template"
mv ${BASE_DIR}/rootfs.img.vanilla ${BASE_DIR}/rootfs.img.template
rm ${BASE_DIR}/rootfs.img
else
echo "moving rootfs to template"
mv ${BASE_DIR}/rootfs.img ${BASE_DIR}/rootfs.img.template
fi
if [ -f ${BASE_DIR}/mcu.bin ]; then
echo "importing mcu update"
cp ${BASE_DIR}/mcu.bin ${IMG_DIR}/mcu.bin
fi
if [ -f ${BASE_DIR}/UI.bin ]; then
echo "importing UI update"
cp ${BASE_DIR}/UI.bin ${IMG_DIR}/UI.bin
fi
if [ -f ${BASE_DIR}/UIMA.bin ]; then
echo "importing UIMA update"
cp ${BASE_DIR}/UI*.bin ${IMG_DIR}/
fi
echo "installing dropbear keys"
mkdir -p ${IMG_DIR}/etc/dropbear
chown root:root ${IMG_DIR}/etc/dropbear
cat ${BASE_DIR}/dropbear_rsa_host_key > ${IMG_DIR}/etc/dropbear/dropbear_rsa_host_key
cat ${BASE_DIR}/dropbear_dss_host_key > ${IMG_DIR}/etc/dropbear/dropbear_dss_host_key
cat ${BASE_DIR}/dropbear_ecdsa_host_key > ${IMG_DIR}/etc/dropbear/dropbear_ecdsa_host_key
cat ${BASE_DIR}/dropbear_ed25519_host_key > ${IMG_DIR}/etc/dropbear/dropbear_ed25519_host_key
echo "installing dropbear"
install -d ${IMG_DIR}/usr/local/sbin
install -m 0755 ${FEATURES_DIR}/dropbear_1t/dropbear ${IMG_DIR}/usr/local/sbin
install -d ${IMG_DIR}/usr/local/bin
install -m 0755 ${FEATURES_DIR}/dropbear_1t/dbclient ${IMG_DIR}/usr/local/bin
install -d ${IMG_DIR}/usr/local/bin
install -m 0755 ${FEATURES_DIR}/dropbear_1t/scp ${IMG_DIR}/usr/local/bin
cat ${BASE_DIR}/authorized_keys > ${IMG_DIR}/authorized_keys
echo "--------------"
echo "creating hooks for scripts"
cat ${FEATURES_DIR}/dropbear_1t/dropbear.sh > ${IMG_DIR}/etc/rc.d/dropbear.sh
chmod +x ${IMG_DIR}/etc/rc.d/dropbear.sh
echo "" >> ${IMG_DIR}/etc/rc.sysinit
echo "/etc/rc.d/dropbear.sh &" >> ${IMG_DIR}/etc/rc.sysinit
sed -i "s/\/usr\/local\/bin/\/data\/bin:\/usr\/local\/bin/g" ${IMG_DIR}/etc/rc.sysinit
echo "" > ${IMG_DIR}/etc/_root.tmp
echo "if [[ -f /data/_root.sh ]]; then" >> ${IMG_DIR}/etc/_root.tmp
echo " /data/_root.sh &" >> ${IMG_DIR}/etc/_root.tmp
echo "fi" >> ${IMG_DIR}/etc/_root.tmp
echo "" >> ${IMG_DIR}/etc/_root.tmp
sed -i "/mount_data.sh/r ${IMG_DIR}/etc/_root.tmp" ${IMG_DIR}/etc/rc.sysinit
rm ${IMG_DIR}/etc/_root.tmp
echo "if [[ -f /data/_root_postboot.sh ]]; then" >> ${IMG_DIR}/etc/rc.sysinit
echo " /data/_root_postboot.sh &" >> ${IMG_DIR}/etc/rc.sysinit
echo "fi" >> ${IMG_DIR}/etc/rc.sysinit
# Include the config value in the firmware for users that might lose it
if [ -f ${FLAG_DIR}/configvalue ]; then
cp "${FLAG_DIR}/configvalue" "${IMG_DIR}/dust_configvalue"
fi
if [ -f ${FLAG_DIR}/patch_dns ]; then
#EXPERIMENT-disable-rsyslog: Prevents writing of some log files onto /data, which should increase NAND flash lifetime
sed -i "s/rsyslogd/# rsyslogd/g" ${IMG_DIR}/etc/rc.d/rsyslog.sh
#EXPERIMENT-monitor_cpu: Prevents writing of some log files onto /data, which should increase NAND flash lifetime
sed -i "s/source \/usr\/bin\/config/exit 0\nsource \/usr\/bin\/config/g" ${IMG_DIR}/etc/rc.d/monitor_cpu.sh
#EXPERIMENT-disable_trans: No clue what this does, looks sketchy, might not be relevant for release fw
sed -i "s/source \/usr\/bin\/config/exit 0\nsource \/usr\/bin\/config/g" ${IMG_DIR}/etc/rc.d/msg_trans_monitor.sh
#EXPERIMENT-redirect-miio-log: same as above. We move it to tmp and not tmp/log to prevent uploads
sed -i "s/\/data\/log\//\/tmp\//g" ${IMG_DIR}/etc/rc.d/miio_monitor.sh
#EXPERIMENT-redirect-miio-log: not sure if we actually need it or if we can remove the log
sed -i "s/\/data\/log\//\/tmp\//g" ${IMG_DIR}/etc/rc.d/miio.sh
sed -i "s/5242880/1048576/g" ${IMG_DIR}/etc/rc.d/miio.sh
#EXPERIMENT-redirect-wifi-log: same as above. We move it to tmp and not tmp/log to prevent uploads
#sed -i "s/\/data\/log\//\/tmp\//g" ${IMG_DIR}/etc/rc.d/wifi_monitor.sh
if [ -f ${IMG_DIR}/usr/bin/dmio.sh ]; then
sed -i "s/source \/usr\/bin\/config/exit 0\nsource \/usr\/bin\/config/g" ${IMG_DIR}/usr/bin/dmio.sh
fi
if [ -f ${IMG_DIR}/usr/bin/dmio_monitor.sh ]; then
sed -i "s/source \/usr\/bin\/config/exit 0\nsource \/usr\/bin\/config/g" ${IMG_DIR}/usr/bin/dmio_monitor.sh
fi
if [ -f ${IMG_DIR}/usr/bin/mon_wifi.sh ]; then
sed -i "s/source \/usr\/bin\/config/exit 0\nsource \/usr\/bin\/config/g" ${IMG_DIR}/usr/bin/mon_wifi.sh
fi
# privacy: video remote access
rm ${IMG_DIR}/etc/rc.d/video_streamer.sh
rm ${IMG_DIR}/etc/rc.d/monitor_video_streamer.sh
rm ${IMG_DIR}/etc/rc.d/restart_video_streamer.sh
rm ${IMG_DIR}/usr/bin/video_monitor
# loudspeakerservice.json needs to stay intact for sound to work on the l10spuh
rm ${IMG_DIR}/ava/conf/video_monitor/cedar*
rm ${IMG_DIR}/ava/conf/video_monitor/recorder*
rm ${IMG_DIR}/ava/conf/video_monitor/video_*
rm ${IMG_DIR}/ava/conf/video_monitor/microphone*
sed -i "/\/etc\/rc.d\/create_agora_cert.sh/d" ${IMG_DIR}/etc/rc.sysinit
sed -i "/\/etc\/rc.d\/monitor_video_streamer.sh/d" ${IMG_DIR}/etc/rc.sysinit
sed -i "/video_monitor/d" ${IMG_DIR}/etc/rc.d/ava.sh
# privacy: speech recon and microphone stuff
rm -r ${IMG_DIR}/bdspeech
rm -r ${IMG_DIR}/speech
rm ${IMG_DIR}/usr/bin/speech_switch_type.sh
rm ${IMG_DIR}/usr/bin/reboot_monitor_bdspeech.sh
rm ${IMG_DIR}/usr/bin/dreame_nlp_server
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/usr/bin/speech_monitor.sh
sed -i "/\/usr\/bin\/speech_switch_type.sh/d" ${IMG_DIR}/etc/rc.sysinit
sed -i 's/\(.*MIC.*\) [0-9]*/\1 0/g' ${IMG_DIR}/etc/init.d/audio.sh
# privacy: telemetry stuff
ava_confs=("${IMG_DIR}/ava/conf"/r*.conf)
if [ ${#ava_confs[@]} -gt 0 ]; then
ava_conf_filename="${ava_confs[0]}"
mv "$ava_conf_filename" "$ava_conf_filename.bak"
jq 'del(.nodes[] | select(.ID == "AvaNodeImpfileUpload"))' "$ava_conf_filename.bak" > $ava_conf_filename
rm "$ava_conf_filename.bak"
fi
sed -i 's/"upload_flag": true/"upload_flag": false/g' ${IMG_DIR}/ava/conf/bduploadfreq.json
# # x50 stuff
# if [ ${FRIENDLYDEVICETYPE} == "dreame.vacuum.r2489" ]; then
# ava_confs=("${IMG_DIR}/ava/conf"/r*.conf)
# if [ ${#ava_confs[@]} -gt 0 ]; then
# ava_conf_filename="${ava_confs[0]}"
# mv "$ava_conf_filename" "$ava_conf_filename.bak"
# jq 'del(.nodes[] | select(.ID == "AvaNodeBigdataUpload"))' "$ava_conf_filename.bak" > $ava_conf_filename
# rm "$ava_conf_filename.bak"
# fi
# ava_confs=("${IMG_DIR}/ava/conf"/r*.conf)
# if [ ${#ava_confs[@]} -gt 0 ]; then
# ava_conf_filename="${ava_confs[0]}"
# mv "$ava_conf_filename" "$ava_conf_filename.bak"
# jq 'del(.nodes[] | select(.ID == "AvaNodeSpeechControl"))' "$ava_conf_filename.bak" > $ava_conf_filename
# rm "$ava_conf_filename.bak"
# fi
# fi
# #
rm ${IMG_DIR}/usr/bin/upload_file_ava
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/usr/bin/aimodels_hotupdate.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/usr/bin/dspmodel_hotupdate.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/usr/bin/check_silent_upgrade.sh
# matter does not work anyway if you have no cloud binding
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/etc/rc.d/matter.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/etc/rc.d/token.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/etc/rc.d/upload_file.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/etc/rc.d/QRPairHelper.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/etc/rc.d/msg_trans.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/etc/rc.d/msg_trans_monitor.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/etc/rc.d/mini_httpd.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/etc/rc.d/mi_tracking.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/etc/rc.d/boa.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/etc/init.d/wifi_ap_record.sh
sed -i '/check_silent_upgrade/d' ${IMG_DIR}/etc/crontabs/root
sed -i '/aimodels_hotupdate/d' ${IMG_DIR}/etc/crontabs/root
# changes introduced with x50 (just to be safe)
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/usr/bin/mtop.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/etc/rc.d/sys_monitor.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/usr/bin/sysmon.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/etc/rc.d/mi_tracking.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/upload_file.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/usr/bin/speech_switch_type.sh
echo -e "#!/bin/sh\nexit 0" > ${IMG_DIR}/usr/bin/check_silent_upgrade.sh
echo "export HISTFILE=/dev/null" >> ${IMG_DIR}/etc/profile
#
fi
echo "backdooring"
sed -i -E 's/::respawn:\/usr\/bin\/getty.sh//g' ${IMG_DIR}/etc/inittab
if [ ${FRIENDLYDEVICETYPE} == "dreame.vacuum.r2489" ]; then
sed -i -E 's/Put a getty on the serial port/\n::respawn:-\/sbin\/getty -n -l \/bin\/dustshell 115200 -L ttyAS0/g' ${IMG_DIR}/etc/inittab
else
sed -i -E 's/Put a getty on the serial port/\n::respawn:-\/sbin\/getty -n -l \/bin\/dustshell 115200 -L ttyS0/g' ${IMG_DIR}/etc/inittab
fi
echo -e "#!/bin/sh\n/bin/login -f root" > ${IMG_DIR}/bin/dustshell
chmod +x ${IMG_DIR}/bin/dustshell
echo "" > ${IMG_DIR}/etc/mdev.conf
if [[ ${FRIENDLYDEVICETYPE} == "dreame.vacuum.r"* || ${FRIENDLYDEVICETYPE} == "dreame.vacuum.p2114" ]]; then
if [ ! -f ${FLAG_DIR}/skip_sanitize ]; then
echo "r device, sanitizing"
echo $(pwd)
export IMG_DIR=${IMG_DIR}
${FEATURES_DIR}/../features/fwinstaller_r/sanitize.sh
fi
fi
if [ -f ${FLAG_DIR}/valetudo ]; then
echo "copy valetudo"
install -D -m 0755 ${FEATURES_DIR}/valetudo/valetudo-aarch64 ${BASE_DIR}/valetudo
install -m 0755 ${FEATURES_DIR}/fwinstaller_1t/_root_postboot.sh.tpl ${BASE_DIR}/_root_postboot.sh.tpl
touch ${FLAG_DIR}/patch_dns
fi
if [ -f ${FLAG_DIR}/vacuumstreamer ]; then
echo "installing vacuumstreamer"
install -D -m 0755 ${FEATURES_DIR}/vacuumstreamer/vacuumstreamer.so ${BASE_DIR}/usr/lib/
install -D -m 0755 ${FEATURES_DIR}/vacuumstreamer/dist/ava/conf/* ${BASE_DIR}/ava/conf/
install -m 0755 ${FEATURES_DIR}/vacuumstreamer/dist/usr/bin/video_monitor ${BASE_DIR}/usr/bin/video_monitor
fi
if [ -f ${FLAG_DIR}/patch_dns ]; then
echo "patching DNS"
install -m 0755 ${FEATURES_DIR}/fwinstaller_1t/vfactory_reset.sh ${IMG_DIR}/usr/bin
install -m 0755 ${FEATURES_DIR}/fwinstaller_1t/install-mcufw.sh ${IMG_DIR}/usr/bin
cat ${FEATURES_DIR}/nsswitch/nsswitch.conf > ${IMG_DIR}/etc/nsswitch.conf
if [ -f ${IMG_DIR}/usr/bin/miio_client_helper_mjac.sh ]; then
rm ${IMG_DIR}/usr/bin/miio_client_helper_mjac.sh
install -m 0755 ${FEATURES_DIR}/miio_clients/dreame_4.1.8_aarch64/miio_client_helper_nomqtt.sh ${IMG_DIR}/usr/bin/miio_client_helper_nomqtt.sh
fi
# EXPERIMENTAL: disable automatic OTA updates
grep "MIIO_AUTO_OTA=true" ${IMG_DIR}/usr/bin/config
if [ $? -eq 0 ]; then
sed -i -E 's/MIIO_AUTO_OTA=true/MIIO_AUTO_OTA=false/g' ${IMG_DIR}/usr/bin/config
fi
# EXPERIMENTAL: disable automatic OTA updates
grep "MIIO_AUTO_OTA=true" ${IMG_DIR}/usr/bin/boardconfig
if [ $? -eq 0 ]; then
sed -i -E 's/MIIO_AUTO_OTA=true/MIIO_AUTO_OTA=false/g' ${IMG_DIR}/usr/bin/boardconfig
fi
### newer firmwares do not use a custom mjac file anymore, so we need to catch that here
grep "MIIO_SDK_MJAC=true" ${IMG_DIR}/usr/bin/config
if [ $? -eq 0 ]; then
sed -i -E 's/MIIO_SDK_MJAC=true/MIIO_SDK_MJAC=false/g' ${IMG_DIR}/usr/bin/config
sed -i -E 's/MIIO_NET_AUTO_PROVISION=1/MIIO_NET_AUTO_PROVISION=0/g' ${IMG_DIR}/usr/bin/wifi_start.sh
fi
grep "MIIO_SDK_MJAC=true" ${IMG_DIR}/usr/bin/boardconfig
if [ $? -eq 0 ]; then
sed -i -E 's/MIIO_SDK_MJAC=true/MIIO_SDK_MJAC=false/g' ${IMG_DIR}/usr/bin/boardconfig
sed -i -E 's/MIIO_NET_AUTO_PROVISION=1/MIIO_NET_AUTO_PROVISION=0/g' ${IMG_DIR}/usr/bin/wifi_start.sh
fi
install -m 0755 ${FEATURES_DIR}/miio_clients/dreame_3.5.8_aarch64/miio_client.patchedlimit.nomdns ${IMG_DIR}/usr/bin/miio_client
### Downgrade the helper if we do not already have an older helper or use a patched newer one
grep -i "version: 4.3.2" ${IMG_DIR}/usr/bin/miio_client_helper_nomqtt.sh
if [ $? -eq 0 ]; then
# Install patched helper
install -m 0755 ${FEATURES_DIR}/miio_clients/dreame_4.3.2_aarch64/miio_client_helper_nomqtt.sh ${IMG_DIR}/usr/bin/miio_client_helper_nomqtt.sh
else
grep "version: 4.1.6" ${IMG_DIR}/usr/bin/miio_client_helper_nomqtt.sh
if [ $? -eq 1 ]; then
grep "version: 3.5.8" ${IMG_DIR}/usr/bin/miio_client_helper_nomqtt.sh
if [ $? -eq 1 ]; then
# Downgrade the helper
install -m 0755 ${FEATURES_DIR}/miio_clients/dreame_4.1.8_aarch64/miio_client_helper_nomqtt.sh ${IMG_DIR}/usr/bin/miio_client_helper_nomqtt.sh
fi
fi
fi
### Dreame tries to add some dm crypt stuff and we need to make some non-compatible robots compatible with the 4.1.8 miio helper
grep "DM_FLAG" ${IMG_DIR}/usr/bin/config
if [ $? -eq 1 ]; then
sed -i '1s/^/DM_FLAG=\/mnt\/misc\/dm\n/' ${IMG_DIR}/usr/bin/config
fi
### Some dreames may also act as a BLE gateway with the stock firmware (e.g P2148)
if [ -f ${IMG_DIR}/etc/init.d/ble.sh ]; then
sed -i "s/source \/usr\/bin\/config/exit 0\nsource \/usr\/bin\/config/g" ${IMG_DIR}/etc/init.d/ble.sh
fi
if [ -f ${IMG_DIR}/usr/bin/bt_init.sh ]; then
sed -i "s/source \/usr\/bin\/config/exit 0\nsource \/usr\/bin\/config/g" ${IMG_DIR}/usr/bin/bt_init.sh
fi
if [ -f ${IMG_DIR}/usr/bin/ble.sh ]; then
sed -i "s/source \/usr\/bin\/config/exit 0\nsource \/usr\/bin\/config/g" ${IMG_DIR}/usr/bin/ble.sh
fi
### This script is used for tracking
if [ -f ${IMG_DIR}/ava/script/curl_server.sh ]; then
sed -i "s/source \/usr\/bin\/config/exit 0\nsource \/usr\/bin\/config/g" ${IMG_DIR}/ava/script/curl_server.sh
fi
### While not a functional issue, this otherwise shows up as a resolved cloud domain
### when people monitor their internal dns queries which paints a wrong impression
if [ -f ${IMG_DIR}/usr/bin/report_data.sh ]; then
sed -i "s/nslookup/echo/g" ${IMG_DIR}/usr/bin/report_data.sh
fi
if [ -f ${IMG_DIR}/usr/bin/record_events.sh ]; then
sed -i "s/nslookup/echo/g" ${IMG_DIR}/usr/bin/record_events.sh
fi
if [ -f ${IMG_DIR}/etc/rc.d/wifi_monitor.sh ]; then
sed -i "s/nslookup/:/g" ${IMG_DIR}/etc/rc.d/wifi_monitor.sh
fi
if [ -f ${IMG_DIR}/usr/bin/network_hook.sh ]; then
sed -i "s/\"iot_connected\" \]; then/\"iot_connected\" ]; then exit 0;/" ${IMG_DIR}/usr/bin/network_hook.sh
sed -i "s/\"iot_disconnected\" \]; then/\"iot_disconnected\" ]; then exit 0;/" ${IMG_DIR}/usr/bin/network_hook.sh
fi
if [ ! -f ${IMG_DIR}/usr/lib/libjson-c.so.2 ]; then
install -m 0755 ${FEATURES_DIR}/miio_clients/3.5.8_aarch64.lib/* ${IMG_DIR}/usr/lib
fi
sed -i -E 's/110.43.0.83/127.000.0.1/g' ${IMG_DIR}/usr/bin/miio_client
sed -i -E 's/110.43.0.85/127.000.0.1/g' ${IMG_DIR}/usr/bin/miio_client
rm ${IMG_DIR}/etc/hosts
cat ${FEATURES_DIR}/valetudo/deployment/etc/hosts-local > ${IMG_DIR}/etc/hosts
install -m 0755 ${FEATURES_DIR}/fwinstaller_1t/_root_postboot.sh.tpl ${IMG_DIR}/misc/_root_postboot.sh.tpl
install -m 0755 ${FEATURES_DIR}/fwinstaller_1t/how_to_modify.txt ${IMG_DIR}/misc/how_to_modify.txt
sed -i 's/-oDISABLE_PSM//' ${IMG_DIR}/etc/rc.d/miio.sh
sed -i 's/set_change_user() {/set_change_user() { \n return 0\n/' ${IMG_DIR}/ava/script/msg_cvt.sh
sed -i "s/307545464D4D757233624A4261696A7A\"/307545464D4D757233624A4261696A7A\"\n avacmd msg_cvt '{\"type\":\"msgCvt\",\"cmd\":\"nation_matched\",\"result\":\"matched\"}' \&\n return 0\n/" ${IMG_DIR}/ava/script/msg_cvt.sh
#Disable encryption of FDS uploads (if enabled)
sed -i -E 's/ENC_FILE=yes/ENC_FILE=nah/g' ${IMG_DIR}/ava/lib/*
fi
if [ -f ${FLAG_DIR}/miio_target ]; then
echo "patching miio_target"
miio_target_ip=$(cat "${FLAG_DIR}/miio_target")
miio_target_ip=${miio_target_ip//[^0-9.]/}
sed -i -E 's/110.43.0.83/127.000.0.1/g' ${IMG_DIR}/usr/bin/miio_client
sed -i -E 's/110.43.0.85/127.000.0.1/g' ${IMG_DIR}/usr/bin/miio_client
sed -i -E "s/127.000.0.1/${miio_target_ip}/g" ${IMG_DIR}/usr/bin/miio_client
sed -i -E "s/127.000.0.1/${miio_target_ip}/g" ${IMG_DIR}/etc/hosts
fi
#echo "Fix broken Dreame cronjob scripts"
#sed -i -E 's/#source \/usr\/bin\/config/source \/usr\/bin\/config/g' ${IMG_DIR}/etc/rc.d/wifi_monitor.sh
#sed -i -E 's/#source \/usr\/bin\/config/source \/usr\/bin\/config/g' ${IMG_DIR}/etc/rc.d/miio_monitor.sh
echo "Remove chinese DNS server"
sed -i 's/echo "nameserver 114.114.114.114" >> $RESOLV_CONF//g' ${IMG_DIR}/usr/share/udhcpc/default.script
sed -i 's/echo "nameserver 114.114.114.114" > $RESOLV_CONF//g' ${IMG_DIR}/usr/share/udhcpc/default.script
#echo "Reduce wifi_manager loglevel to error to save the NAND"
#sed -i -E 's/-l4/-l1/g' ${IMG_DIR}/etc/rc.d/wifi_manager.sh
if [ -f ${FLAG_DIR}/tools ]; then
echo "installing tools"
cp -r ${FEATURES_DIR}/1t_tools/root-dir/* ${IMG_DIR}/
fi
if [ -f ${FLAG_DIR}/tools_pro ]; then
echo "installing tools_pro"
cp -r ${FEATURES_DIR}/1t_tools_pro/root-dir/* ${IMG_DIR}/
fi
if [ -f ${FLAG_DIR}/hostname ]; then
echo "patching Hostname"
cat ${FLAG_DIR}/hostname > ${IMG_DIR}/etc/hostname
# urgh...
sed -i -E 's/get_hostname()/get_host_name()/g' ${IMG_DIR}/etc/wifi/udhcpc.sh
sed -i -E 's/get_hostname/#get_hostname/g' ${IMG_DIR}/etc/wifi/udhcpc.sh
sed -i -E 's/get_host_name()/get_hostname()/g' ${IMG_DIR}/etc/wifi/udhcpc.sh
fi
if [ -f ${FLAG_DIR}/timezone ]; then
echo "patching Timezone"
cat ${FLAG_DIR}/timezone > ${IMG_DIR}/etc/timezone
fi
if [ -f ${FEATURES_DIR}/fwinstaller_1t/sanitize.sh ]; then
if [ ! -f ${FLAG_DIR}/skip_sanitize ]; then
echo "Cleanup Dreame backdoors"
${FEATURES_DIR}/fwinstaller_1t/sanitize.sh
fi
fi
touch ${IMG_DIR}/build.txt
echo "built with dustbuilder (https://builder.dontvacuum.me)" > ${IMG_DIR}/build.txt
date -u +"%Y-%m-%dT%H:%M:%SZ" >> ${IMG_DIR}/build.txt
if [ -f ${FLAG_DIR}/version ]; then
cat ${FLAG_DIR}/version >> ${IMG_DIR}/build.txt
fi
echo "" >> ${IMG_DIR}/build.txt
sed -i '$ d' ${IMG_DIR}/etc/banner
sed -i '$ d' ${IMG_DIR}/etc/banner
cat ${IMG_DIR}/build.txt >> ${IMG_DIR}/etc/banner
echo "--------------"
echo "creating rootfs"
mksquashfs ${IMG_DIR}/ rootfs_tmp.img -noappend -root-owned -comp xz -b 256k -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1'
rm -rf ${IMG_DIR}
dd if=${BASE_DIR}/rootfs_tmp.img of=${BASE_DIR}/rootfs.img bs=128k conv=sync
rm ${BASE_DIR}/rootfs_tmp.img
if [ -f ${FLAG_DIR}/vanilla ]; then
echo "vanilla mode, purge rootfs, use template"
rm ${BASE_DIR}/rootfs.img
cp ${FLAG_DIR}/rootfs.img.template ${BASE_DIR}/rootfs.img
if [ -f ${BASE_DIR}/vanilla_dir/toc1.fex ]; then
echo "copying toc1 to base dir"
cp ${BASE_DIR}/vanilla_dir/toc1.fex ${BASE_DIR}/toc1.img
echo "copying vanilla boot to base dir"
cp ${BASE_DIR}/vanilla_dir/boot.img ${BASE_DIR}/boot.img
cp ${BASE_DIR}/vanilla_dir/boot.fex ${BASE_DIR}/boot.img
echo "copying vanilla_rootfs to base dir"
cp ${BASE_DIR}/vanilla_dir/rootfs.img ${BASE_DIR}/rootfs.img
echo "copying vanilla_mcu to base dir"
cp ${BASE_DIR}/vanilla_dir/mcu.bin ${BASE_DIR}/mcu.bin
cp ${BASE_DIR}/vanilla_dir/mcu_md5sum ${BASE_DIR}/mcu_md5sum
cp ${BASE_DIR}/vanilla_dir/mcu_sha256sum ${BASE_DIR}/mcu_sha256sum
fi
fi
echo "computing md5"
md5sum ${BASE_DIR}/rootfs.img > ${BASE_DIR}/rootfs_md5sum
cp parameter.txt parameter
echo "check image file size"
if [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.mc1808" ]; then
echo "mc1808"
maximumsize=50000000
minimumsize=21000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.p2009" ]; then
echo "p2009"
maximumsize=30000000
minimumsize=20000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.p2029" ]; then
echo "p2029"
maximumsize=44000000
minimumsize=29000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.p2028" ]; then
echo "p2028"
maximumsize=44000000
minimumsize=29000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.p2041" ]; then
echo "p2041"
maximumsize=56000000
minimumsize=29000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.p2148" ]; then
echo "p2148"
maximumsize=56000000
minimumsize=29000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.p2149" ]; then
echo "p2149"
maximumsize=44000000
minimumsize=29000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.p2150" ]; then
echo "p2150"
maximumsize=44000000
minimumsize=29000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.p2114" ]; then
echo "p2114"
maximumsize=82000000
minimumsize=29000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2104" ]; then
echo "r2104"
maximumsize=70000000
minimumsize=29000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2240" ]; then
echo "r2240"
maximumsize=70000000
minimumsize=29000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2250" ]; then
echo "r2250"
maximumsize=70000000
minimumsize=29000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2228" ]; then
echo "r2228"
maximumsize=83000000
minimumsize=29000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2338" ]; then
echo "r2338"
maximumsize=162772160 #actual part size: 167772160
minimumsize=89000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2338h" ]; then
echo "r2338h"
maximumsize=162772160 #actual part size: 167772160
minimumsize=89000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r9309" ]; then
echo "r9309"
maximumsize=162772160 #actual part size: 167772160
minimumsize=89000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2416" ]; then
echo "r2416"
maximumsize=162772160 #actual part size: 167772160
minimumsize=89000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2449" ]; then
echo "r2449"
maximumsize=162772160 #actual part size: 167772160
minimumsize=89000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2465" ]; then
echo "r2465"
maximumsize=162772160 #actual part size: 167772160
minimumsize=89000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r9316" ]; then
echo "r9316"
maximumsize=162772160 #actual part size: 167772160
minimumsize=89000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2394" ]; then
echo "r2394"
maximumsize=162772160 #actual part size: 167772160
minimumsize=86000000
elif [ ${FRIENDLYDEVICETYPE} = "mova.vacuum.r2491" ]; then
echo "r2491"
maximumsize=162772160 #actual part size: 167772160
minimumsize=89000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2492" ]; then
echo "r2492"
maximumsize=162772160 #actual part size: 167772160
minimumsize=89000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2385" ]; then
echo "r2385"
maximumsize=162772160 #actual part size: 167772160
minimumsize=89000000
elif [ ${FRIENDLYDEVICETYPE} = "dreame.vacuum.r2489" ]; then
echo "r2489"
maximumsize=202000000 #actual part size: 209715000
minimumsize=89000000
else
echo "all others"
maximumsize=30000000
minimumsize=20000000
fi
actualsize=$(wc -c < ${BASE_DIR}/rootfs.img)
if [ "$actualsize" -gt "$maximumsize" ]; then
echo "(!!!) rootfs.img looks to big. The size might exceed the available space on the flash. $actualsize > $maximumsize"
echo "(!!!) rootfs.img looks to big. The size might exceed the available space on the flash. $actualsize > $maximumsize" > ${BASE_DIR}/output/error.txt
echo ${FRIENDLYDEVICETYPE} >> ${BASE_DIR}/output/error.txt
echo $actualsize >> ${BASE_DIR}/output/error.txt
echo $maximumsize >> ${BASE_DIR}/output/error.txt
exit 1
fi
if [ "$actualsize" -le "$minimumsize" ]; then
echo "(!!!) rootfs.img looks to small. Maybe something went wrong with the image generation."
echo "(!!!) rootfs.img looks to small. Maybe something went wrong with the image generation." > ${BASE_DIR}/output/error.txt
echo ${FRIENDLYDEVICETYPE} >> ${BASE_DIR}/output/error.txt
echo $actualsize >> ${BASE_DIR}/output/error.txt
echo $maximumsize >> ${BASE_DIR}/output/error.txt
exit 1
fi
if [ -d ${BASE_DIR}/burnBL ]; then
cp ${BASE_DIR}/burnBL/*.* ${BASE_DIR}/
fi
if [ -d ${BASE_DIR}/patchBL ]; then
cp ${BASE_DIR}/patchBL/*.* ${BASE_DIR}/
install -m 0755 ${FEATURES_DIR}/patchBL_1t/patchBL.sh ${BASE_DIR}/patchBL.sh
fi
md5sum ./*.img > ${BASE_DIR}/firmware.md5sum
echo "create installer package"
install -m 0755 ${FEATURES_DIR}/fwinstaller_1t/install-mcufw.sh ${BASE_DIR}/install-mcufw.sh
sed "s/DEVICEMODEL=.*/DEVICEMODEL=\"${DEVICETYPE}\"/g" ${FEATURES_DIR}/fwinstaller_1t/install.sh > ${BASE_DIR}/install.sh
sed -i "s/# maxsizeplaceholder/maximumsize=${maximumsize}/g" ${BASE_DIR}/install.sh
sed -i "s/# minsizeplaceholder/minimumsize=${minimumsize}/g" ${BASE_DIR}/install.sh
chmod +x install.sh
sed "s/DEVICEMODEL=.*/DEVICEMODEL=\"${DEVICETYPE}\"/g" ${FEATURES_DIR}/fwinstaller_1t/install-manual.sh > ${BASE_DIR}/install-manual.sh
sed -i "s/# maxsizeplaceholder/maximumsize=${maximumsize}/g" ${BASE_DIR}/install-manual.sh
sed -i "s/# minsizeplaceholder/minimumsize=${minimumsize}/g" ${BASE_DIR}/install-manual.sh
chmod +x install-manual.sh
tar -czf ${BASE_DIR}/output/${DEVICETYPE}_fw.tar.gz $(ls ${BASE_DIR}/*.img ${BASE_DIR}/mcu_md5sum mcu.bin ${BASE_DIR}/firmware.md5sum ${BASE_DIR}/install.sh ${BASE_DIR}/install-manual.sh ${BASE_DIR}/install-mcufw.sh ${BASE_DIR}/valetudo ${BASE_DIR}/_root_postboot.sh.tpl ${BASE_DIR}/ui_md5sum ${BASE_DIR}/UI.bin ${BASE_DIR}/UI*.bin ${BASE_DIR}/patchBL.* ${BASE_DIR}/STATION_MCU*.* 2>/dev/null)
md5sum ${BASE_DIR}/output/${DEVICETYPE}_fw.tar.gz > ${BASE_DIR}/output/md5.txt
echo "${DEVICETYPE}_fw.tar.gz" > ${BASE_DIR}/filename.txt
touch ${BASE_DIR}/server.txt
touch ${BASE_DIR}/output/done