forked from pocopico/tinycore-redpill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rploader.sh
2171 lines (1712 loc) · 74.7 KB
/
rploader.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
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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# Author :
# Date : 22041911
# Version : 0.7.0.5
#
#
# User Variables :
rploaderver="0.7.0.5"
rploaderfile="https://raw.githubusercontent.com/pocopico/tinycore-redpill/main/rploader.sh"
rploaderrepo="https://github.com/pocopico/tinycore-redpill/raw/main/"
redpillextension="https://github.com/pocopico/rp-ext/raw/main/redpill/rpext-index.json"
modextention="https://github.com/pocopico/rp-ext/raw/main/rpext-index.json"
modalias4="https://raw.githubusercontent.com/pocopico/tinycore-redpill/main/modules.alias.4.json.gz"
modalias3="https://raw.githubusercontent.com/pocopico/tinycore-redpill/main/modules.alias.3.json.gz"
dtcbin="https://raw.githubusercontent.com/pocopico/tinycore-redpill/main/dtc"
dtsfiles="https://raw.githubusercontent.com/pocopico/tinycore-redpill/main"
fullupdatefiles="custom_config.json global_config.json modules.alias.3.json.gz modules.alias.4.json.gz rpext-index.json user_config.json dtc rploader.sh ds1621p.dts ds920p.dts"
# END Do not modify after this line
######################################################################################################
function downloadextractor() {
loaderdisk="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)"
tcrppart="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)3"
local_cache="/mnt/${tcrppart}/auxfiles"
temp_folder="/tmp/synoesp"
if [ -d ${local_cache/extractor /} ] && [ -f ${local_cache}/extractor/scemd ]; then
echo "Found extractor locally cached"
echo "Copying required libraries to local lib directory"
sudo cp /mnt/${tcrppart}/auxfiles/extractor/lib* /lib/
echo "Linking lib to lib64"
[ ! -h /lib64 ] && sudo ln -s /lib /lib64
echo "Copying executable"
sudo cp /mnt/${tcrppart}/auxfiles/extractor/scemd /bin/syno_extract_system_patch
echo "Removing temp folder /tmp/synoesp"
rm -rf $temp_folder
echo "Checking if tool is accessible"
/bin/syno_extract_system_patch 2>&1 >/dev/null
if [ $? -eq 255 ]; then echo "Executed succesfully"; else echo "Cound not execute"; fi
else
echo "Getting required extraction tool"
echo "------------------------------------------------------------------"
echo "Checking tinycore cache folder"
[ -d $local_cache ] && echo "Found tinycore cache folder, linking to home/tc/custom-module" && [ ! -h /home/tc/custom-module ] && sudo ln -s $local_cache /home/tc/custom-module
echo "Creating temp folder /tmp/synoesp"
mkdir ${temp_folder}
if [ -d /home/tc/custom-module ] && [ -f /home/tc/custom-module/*42218*.pat ]; then
patfile=$(ls /home/tc/custom-module/*42218*.pat | head -1)
echo "Found custom pat file ${patfile}"
echo "Processing old pat file to extract required files for extraction"
tar -C${temp_folder} -xf /${patfile} rd.gz
else
curl --location https://global.download.synology.com/download/DSM/release/7.0.1/42218/DSM_DS3622xs%2B_42218.pat --output /home/tc/oldpat.tar.gz
[ -f /home/tc/oldpat.tar.gz ] && tar -C${temp_folder} -xf /home/tc/oldpat.tar.gz rd.gz
fi
echo "Entering synoesp"
cd ${temp_folder}
xz -dc <rd.gz >rd 2>/dev/null || echo "extract rd.gz"
echo "finish"
cpio -idm <rd 2>&1 || echo "extract rd"
mkdir extract
mkdir /mnt/${tcrppart}/auxfiles && cd /mnt/${tcrppart}/auxfiles
echo "Copying required files to local cache folder for future use"
mkdir /mnt/${tcrppart}/auxfiles/extractor
for file in usr/lib/libcurl.so.4 usr/lib/libmbedcrypto.so.5 usr/lib/libmbedtls.so.13 usr/lib/libmbedx509.so.1 usr/lib/libmsgpackc.so.2 usr/lib/libsodium.so usr/lib/libsynocodesign-ng-virtual-junior-wins.so.7 usr/syno/bin/scemd; do
echo "Copying $file to /mnt/${tcrppart}/auxfiles"
cp $file /mnt/${tcrppart}/auxfiles/extractor
done
echo "Copying required libraries to local lib directory"
sudo cp /mnt/${tcrppart}/auxfiles/extractor/lib* /lib/
echo "Linking lib to lib64"
[ ! -h /lib64 ] && sudo ln -s /lib /lib64
echo "Copying executable"
sudo cp /mnt/${tcrppart}/auxfiles/extractor/scemd /bin/syno_extract_system_patch
echo "Removing temp folder /tmp/synoesp"
rm -rf $temp_folder
echo "Checking if tools is accessible"
/bin/syno_extract_system_patch
if [ $? -eq 255 ]; then echo "Executed succesfully"; else echo "Cound not execute"; fi
fi
}
function processpat() {
loaderdisk="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)"
tcrppart="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)3"
local_cache="/mnt/${tcrppart}/auxfiles"
temp_pat_folder="/tmp/pat"
if [ "${TARGET_PLATFORM}" = "apollolake" ]; then
SYNOMODEL="ds918p_$TARGET_REVISION" && MODEL="DS918+"
elif [ "${TARGET_PLATFORM}" = "bromolow" ]; then
SYNOMODEL="ds3615xs_$TARGET_REVISION" && MODEL="DS3615xs"
elif [ "${TARGET_PLATFORM}" = "broadwell" ]; then
SYNOMODEL="ds3617xs_$TARGET_REVISION" && MODEL="DS3617xs"
elif [ "${TARGET_PLATFORM}" = "broadwellnk" ]; then
SYNOMODEL="ds3622xsp_$TARGET_REVISION" && MODEL="DS3622xs+"
elif [ "${TARGET_PLATFORM}" = "v1000" ]; then
SYNOMODEL="ds1621p_$TARGET_REVISION" && MODEL="DS1621+"
elif [ "${TARGET_PLATFORM}" = "denverton" ]; then
SYNOMODEL="dva3221_$TARGET_REVISION" && MODEL="DVA3221"
elif [ "${TARGET_PLATFORM}" = "geminilake" ]; then
SYNOMODEL="ds920p_$TARGET_REVISION" && MODEL="DS920+"
fi
if [ ! -d "${temp_pat_folder}" ]; then
echo "Creating temp folder ${temp_pat_folder} "
mkdir ${temp_pat_folder} && cd ${temp_pat_folder}
fi
echo "Checking for cached pat file"
[ -d $local_cache ] && echo "Found tinycore cache folder, linking to home/tc/custom-module" && [ ! -h /home/tc/custom-module ] && sudo ln -s $local_cache /home/tc/custom-module
if [ -d ${local_cache} ] && [ -f ${local_cache}/*${SYNOMODEL}*.pat ] || [ -f ${local_cache}/*${MODEL}*${TARGET_REVISION}*.pat ]; then
[ -f /home/tc/custom-module/*${SYNOMODEL}*.pat ] && patfile=$(ls /home/tc/custom-module/*${SYNOMODEL}*.pat | head -1)
[ -f ${local_cache}/*${MODEL}*${TARGET_REVISION}*.pat ] && patfile=$(ls /home/tc/custom-module/*${MODEL}*${TARGET_REVISION}*.pat | head -1)
echo "Found locally cached pat file ${patfile}"
testarchive "${patfile}"
if [ ${isencrypted} = "no" ]; then
echo "File ${patfile} is already unencrypted"
echo "Copying file to /home/tc/redpill-load/cache folder"
cp ${patfile} /home/tc/redpill-load/cache/
elif [ ${isencrypted} = "yes" ]; then
[ -f /home/tc/redpill-load/cache/${SYNOMODEL}.pat ] && testarchive /home/tc/redpill-load/cache/${SYNOMODEL}.pat
if [ -f /home/tc/redpill-load/cache/${SYNOMODEL}.pat ] && [ ${isencrypted} = "no" ]; then
echo "Unecrypted file is already cached in : /home/tc/redpill-load/cache/${SYNOMODEL}.pat"
patfile="/home/tc/redpill-load/cache/${SYNOMODEL}.pat"
else
echo "Extracting encrypted pat file : ${patfile} to ${temp_pat_folder}"
sudo /bin/syno_extract_system_patch ${patfile} ${temp_pat_folder} || echo "extract latest pat"
echo "Creating unecrypted pat file ${SYNOMODEL}.pat to /home/tc/redpill-load/cache folder "
mkdir -p /home/tc/redpill-load/cache/
cd ${temp_pat_folder} && tar -czf /home/tc/redpill-load/cache/${SYNOMODEL}.pat ./
patfile="/home/tc/redpill-load/cache/${SYNOMODEL}.pat"
fi
else
echo "Something went wrong, please check cache files"
exit 99
fi
tar xvf /home/tc/redpill-load/cache/${SYNOMODEL}.pat ./VERSION && . ./VERSION && rm ./VERSION
os_sha256=$(sha256sum ${patfile} | awk '{print $1}')
echo "Pat file sha256sum is : $os_sha256"
echo -n "Checking config file existence -> "
if [ -f "/home/tc/redpill-load/config/$MODEL/${major}.${minor}.${micro}-${buildnumber}/config.json" ]; then
echo "OK"
configfile="/home/tc/redpill-load/config/$MODEL/${major}.${minor}.${micro}-${buildnumber}/config.json"
else
echo "No config file found, please use the proper repo, clean and download again"
exit 99
fi
echo -n "Editing config file -> "
sed -i "/\"os\": {/!b;n;n;n;c\"sha256\": \"$os_sha256\"" ${configfile}
echo -n "Verifying config file -> "
verifyid="$(cat ${configfile} | jq -r -e '.os .sha256')"
if [ "$os_sha256" == "$verifyid" ]; then
echo "OK ! "
else
echo "config file, os sha256 verify FAILED, check ${configfile} "
exit 99
fi
echo "Clearing temp folders"
sudo rm -rf ${temp_pat_folder}
return
else
echo "Could not find pat file locally cached"
configdir="/home/tc/redpill-load/config/${MODEL}/${TARGET_VERSION}-${TARGET_REVISION}"
configfile="${configdir}/config.json"
pat_url=$(cat ${configfile} | jq '.os .pat_url' | sed -s 's/"//g')
echo -e "Configdir : $configdir \nConfigfile: $configfile \nPat URL : $pat_url"
echo "Downloading pat file from URL : ${pat_url} "
if [ $(df -h /${local_cache} | grep mnt | awk '{print $4}' | cut -c 1-3) -le 370 ]; then
echo "No adequate space on ${local_cache} to download file into cache folder, clean up the space and restart"
exit 99
fi
[ -n $pat_url ] && curl --location ${pat_url} -o "/${local_cache}/${SYNOMODEL}.pat"
patfile="/${local_cache}/${SYNOMODEL}.pat"
if [ -f ${patfile} ]; then
testarchive ${patfile}
else
echo "Failed to download PAT file $patfile from ${pat_url} "
exit 99
fi
if [ "${isencrypted}" = "yes" ]; then
echo "File ${patfile}, has been cached but its encrypted, re-running decrypting process"
processpat
else
return
fi
fi
}
function testarchive() {
archive="$1"
archiveheader="$(od -bc ${archive} | head -1 | awk '{print $3}')"
case ${archiveheader} in
105)
echo "${archive}, is a Tar file"
isencrypted="no"
return 0
;;
255)
echo "File ${archive}, is encrypted"
isencrypted="yes"
return 1
;;
213)
echo "File ${archive}, is a compressed tar"
isencrypted="no"
;;
*)
echo "Could not determine if file ${archive} is encrypted or not, maybe corrupted"
ls -ltr ${archive}
echo ${archiveheader}
exit 99
;;
esac
}
function addrequiredexts() {
echo "Processing add_extensions entries found on custom_config.json file : ${EXTENSIONS}"
for extension in ${EXTENSIONS_SOURCE_URL}; do
echo "Adding extension ${extension} "
cd /home/tc/redpill-load/ && ./ext-manager.sh add "$(echo $extension | sed -s 's/"//g' | sed -s 's/,//g')"
done
for extension in ${EXTENSIONS}; do
echo "Updating extension : ${extension} contents for model : ${SYNOMODEL} "
cd /home/tc/redpill-load/ && ./ext-manager.sh _update_platform_exts ${SYNOMODEL} ${extension}
done
if [ ${TARGET_PLATFORM} = "geminilake" ] || [ ${TARGET_PLATFORM} = "v1000" ]; then
patchdtc
fi
}
function installapache() {
echo "Installing apache2 and php module"
tce-load -iw apache2.4.tcz
tce-load -iw apache2.4-doc.tcz
tce-load -iw php-8.0-mod.tcz
tce-load -iw libnghttp2.tcz
#cd /usr/local/
#sudo tar xvf /home/tc/tcrphtml/tc.apache.tar.gz etc/httpd/
#apachectl start
}
function postupdate() {
echo "Mounting root to get the latest dsmroot patch in /.syno/patch "
if [ ! -f /home/tc/redpill-load/user_config.json ]; then
[ ! -h /home/tc/redpill-load/user_config.json ] && ln -s /home/tc/user_config.json /home/tc/redpill-load/user_config.json
fi
if [ $(mount | grep -i dsmroot | wc -l) -le 0 ]; then
mountdsmroot
[ $(mount | grep -i dsmroot | wc -l) -le 0 ] && echo "Failed to mount DSM root, cannot continue the postupdate process, returning" && return
else
echo "Already mounted"
fi
echo "Clearing last created loader "
rm -f redpill-load/loader.img
if [ ! -d "/lib64" ]; then
echo "/lib64 does not exist, bringing linking /lib"
[ ! -h /lib64 ] && ln -s /lib /lib64
fi
if [ ! -n "$(which bspatch)" ]; then
echo "bspatch does not exist, bringing over from repo"
curl --location "https://raw.githubusercontent.com/pocopico/tinycore-redpill/main/bspatch" -O
chmod 777 bspatch
sudo mv bspatch /usr/local/bin/
fi
echo "Checking available patch"
if [ -d "/mnt/dsmroot/.syno/patch/" ]; then
cd /mnt/dsmroot/.syno/patch/
. ./VERSION
. ./GRUB_VER
else
echo "Patch directory not found, please remember that you have to run update usign DSM manual upgrade first"
echo "Postupdate is not possible, returning"
return
fi
echo "Found Platform : ${PLATFORM} Model : $MODEL Version : ${major}.${minor}.${micro}-${buildnumber} "
echo -n "Do you want to use this for the loader ? [yY/nN] : "
read answer
if [ "$answer" == "y" ] || [ "$answer" == "Y" ]; then
patfile="$(echo ${MODEL}_${buildnumber} | sed -e 's/\+/p/' | tr '[:upper:]' '[:lower:]').pat"
echo "Creating pat file ${patfile} using contents of : $(pwd) "
[ ! -d "/home/tc/redpill-load/cache" ] && mkdir /home/tc/redpill-load/cache/
tar cfz /home/tc/redpill-load/cache/${patfile} *
os_sha256=$(sha256sum /home/tc/redpill-load/cache/${patfile} | awk '{print $1}')
echo "Created pat file with sha256sum : $os_sha256"
cd /home/tc
else
echo "OK, see you later"
return
fi
echo -n "Checking config file existence -> "
if [ -f "/home/tc/redpill-load/config/$MODEL/${major}.${minor}.${micro}-${buildnumber}/config.json" ]; then
echo "OK"
configfile="/home/tc/redpill-load/config/$MODEL/${major}.${minor}.${micro}-${buildnumber}/config.json"
else
echo "No config file found, please use the proper repo, clean and download again"
exit 99
fi
echo -n "Editing config file -> "
sed -i "/\"os\": {/!b;n;n;n;c\"sha256\": \"$os_sha256\"" ${configfile}
echo -n "Verifying config file -> "
verifyid="$(cat ${configfile} | jq -r -e '.os .sha256')"
if [ "$os_sha256" == "$verifyid" ]; then
echo "OK ! "
else
echo "config file, os sha256 verify FAILED, check ${configfile} "
exit 99
fi
removebundledexts
cd /home/tc/redpill-load/
addrequiredexts
echo "Creating loader ${MODEL} ${major}.${minor}.${micro}-${buildnumber} ... "
sudo ./build-loader.sh ${MODEL} ${major}.${minor}.${micro}-${buildnumber}
loadername="redpill-${MODEL}_${major}.${minor}.${micro}-${buildnumber}"
loaderimg=$(ls -ltr /home/tc/redpill-load/images/${loadername}* | tail -1 | awk '{print $9}')
echo "Moving loader ${loaderimg} to loader.img "
if [ -f "${loaderimg}" ]; then
mv -f $loaderimg loader.img
else
echo "Failed to find loader ${loaderimg}, exiting"
exit 99
fi
if [ ! -n "$(losetup -j loader.img | awk '{print $1}' | sed -e 's/://')" ]; then
echo -n "Setting up loader img loop -> "
sudo losetup -fP ./loader.img
loopdev=$(losetup -j loader.img | awk '{print $1}' | sed -e 's/://')
echo "$loopdev"
else
echo -n "Loop device exists, removing "
losetup -d $(losetup -j loader.img | awk '{print $1}' | sed -e 's/://')
echo -n "Setting up loader img loop -> "
sudo losetup -fP ./loader.img
loopdev=$(losetup -j loader.img | awk '{print $1}' | sed -e 's/://')
fi
echo -n "Mounting loop disks -> "
[ ! -d /home/tc/redpill-load/localdiskp1 ] && mkdir /home/tc/redpill-load/localdiskp1
[ ! -d /home/tc/redpill-load/localdiskp2 ] && mkdir /home/tc/redpill-load/localdiskp2
[ ! -n "$(mount | grep -i localdiskp1)" ] && sudo mount ${loopdev}p1 localdiskp1
[ ! -n "$(mount | grep -i localdiskp2)" ] && sudo mount ${loopdev}p2 localdiskp2
[ -n "mount |grep -i localdiskp1" ] && [ -n "mount |grep -i localdiskp2" ] && echo "mounted succesfully"
echo -n "Mounting loader disk -> "
loaderdisk="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)"
sudo mount /dev/${loaderdisk}1
sudo mount /dev/${loaderdisk}2
[ -n "mount |grep -i ${loaderdisk}1" ] && [ -n "mount |grep -i ${loaderdisk}2" ] && echo "mounted succesfully"
echo -n "Copying loader files -> "
echo -n "rd.gz : "
cp -f /home/tc/redpill-load/localdiskp1/rd.gz /mnt/${loaderdisk}1/rd.gz
cp -f /home/tc/redpill-load/localdiskp2/rd.gz /mnt/${loaderdisk}2/rd.gz
[ "$(sha256sum /home/tc/redpill-load/localdiskp1/rd.gz | awk '{print $1}')" == "$(sha256sum /mnt/${loaderdisk}1/rd.gz | awk '{print $1}')" ] && [ "$(sha256sum /home/tc/redpill-load/localdiskp2/rd.gz | awk '{print $1}')" == "$(sha256sum /mnt/${loaderdisk}2/rd.gz | awk '{print $1}')" ] && echo -n "OK !!!"
echo -n " zImage : "
cp -f /home/tc/redpill-load/localdiskp1/zImage /mnt/${loaderdisk}1/zImage
cp -f /home/tc/redpill-load/localdiskp2/zImage /mnt/${loaderdisk}2/zImage
[ "$(sha256sum /home/tc/redpill-load/localdiskp1/zImage | awk '{print $1}')" == "$(sha256sum /mnt/${loaderdisk}1/zImage | awk '{print $1}')" ] && [ "$(sha256sum /home/tc/redpill-load/localdiskp2/zImage | awk '{print $1}')" == "$(sha256sum /mnt/${loaderdisk}2/zImage | awk '{print $1}')" ] && echo -n "OK !!!"
echo -n " grub.cfg : "
cp -f /home/tc/redpill-load/localdiskp1/boot/grub/grub.cfg /mnt/${loaderdisk}1/boot/grub/grub.cfg
[ "$(sha256sum /home/tc/redpill-load/localdiskp1/boot/grub/grub.cfg | awk '{print $1}')" == "$(sha256sum /mnt/${loaderdisk}1/boot/grub/grub.cfg | awk '{print $1}')" ] && echo "OK !!!"
echo "Creating tinycore entry"
tinyentry | sudo tee --append /mnt/${loaderdisk}1/boot/grub/grub.cfg
echo "Do you want to overwrite your custom.gz as well ? [yY/nN] : "
read answer
if [ "$answer" == "y" ] || [ "$answer" == "Y" ]; then
echo "Copying custom.gz"
cp -f /home/tc/redpill-load/localdiskp1/custom.gz /mnt/${loaderdisk}1/custom.gz
[ "$(sha256sum /home/tc/redpill-load/localdiskp1/custom.gz | awk '{print $1}')" == "$(sha256sum /mnt/${loaderdisk}1/custom.gz | awk '{print $1}')" ] && echo "OK !!!"
else
echo "OK, you should be fine keeping your existing custom.gz"
fi
echo "Cleaning up... "
echo -n "Unmounting loaderdisk ${loaderdisk} -> "
sudo umount /dev/${loaderdisk}1 && sudo umount /dev/${loaderdisk}2
[ -z $(mount | grep -i ${loaderdisk}1) ] && [ -z $(mount | grep -i ${loaderdisk}2) ] && echo "OK !!!"
echo -n "Unmounting loader image ${loopdev} -> "
sudo umount ${loopdev}p1 && sudo umount ${loopdev}p2
[ -z $(mount | grep -i ${loopdev}p1) ] && [ -z $(mount | grep -i ${loopdev}p2) ] && echo "OK !!!"
echo -n "Detaching loop loader image -> "
sudo losetup -d ${loopdev}
[ -z $(losetup | grep -i loader.img) ] && echo "OK !!!"
if [ -f /home/tc/redpill-load/loader.img ]; then
echo -n "Removing loader.img -> "
sudo rm -rf /home/tc/redpill-load/loader.img
[ ! -f /home/tc/redpill-load/loader.img ] && echo "OK !!!"
fi
echo "Unmounting dsmroot -> "
[ ! -z "$(mount | grep -i dsmroot)" ] && sudo umount /mnt/dsmroot
[ -z "$(mount | grep -i dsmroot)" ] && echo "OK !!! "
echo "Done, closing"
}
function removebundledexts() {
echo "Entering redpill-load directory"
cd /home/tc/redpill-load/
echo "Removing bundled exts directories"
for bundledext in $(grep ":" bundled-exts.json | awk '{print $2}' | sed -e 's/"//g' | sed -e 's/,/\n/g'); do
bundledextdir=$(curl --location -s "$bundledext" | jq -r -e '.id')
if [ -d /home/tc/redpill-load/custom/extensions/${bundledextdir} ]; then
echo "Removing : ${bundledextdir}"
sudo rm -rf /home/tc/redpill-load/custom/extensions/${bundledextdir}
fi
done
}
function fullupgrade() {
backupdate="$(date +%Y-%b-%d-%H-%M)"
echo "Performing a full TCRP upgrade"
echo "Warning some of your local files will be moved to /home/tc/old/xxxx.${backupdate}"
[ ! -d /home/tc/old ] && mkdir /home/tc/old
for updatefile in ${fullupdatefiles}; do
echo "Updating ${updatefile}"
sudo mv $updatefile old/${updatefile}.${backupdate}
sudo curl --location "${rploaderrepo}/${updatefile}" -O
done
sudo chown tc:staff $fullupdatefiles
gunzip -f modules.alias.*.gz
sudo chmod 700 rploader.sh
backup
}
function backuploader() {
loaderdisk="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)"
tcrppart="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)3"
homesize=$(du -sh /home/tc | awk '{print $1}')
backupdate="$(date +%Y-%b-%d-%H-%M)"
if [ ! -n "$loaderdisk" ] || [ ! -n "$tcrppart" ]; then
echo "No Loader disk or no TCRP partition found, return"
return
fi
if [ $(df -h /mnt/${tcrppart} | grep mnt | awk '{print $4}' | cut -c 1-3) -le 50 ]; then
echo "No adequate space on TCRP loader partition /mnt/${tcrppart} "
return
fi
echo "Backing up current loader"
echo "Checking backup folder existence"
[ ! -d /mnt/${tcrppart}/backup ] && mkdir /mnt/${tcrppart}/backup
echo "The backup folder holds the following backups"
ls -ltr /mnt/${tcrppart}/backup
echo "Creating backup folder $backupdate"
[ ! -d /mnt/${tcrppart}/backup/${backupdate} ] && mkdir /mnt/${tcrppart}/backup/${backupdate}
echo "Mounting partition 1"
mount /dev/${loaderdisk}1
cd /mnt/${loaderdisk}1
tar cfz /mnt/${tcrppart}/backup/${backupdate}/partition1.tgz *
echo "Mounting partition 2"
mount /dev/${loaderdisk}2
cd /mnt/${loaderdisk}2
tar cfz /mnt/${tcrppart}/backup/${backupdate}/partition2.tgz *
cd
echo "Listing backup files : "
ls -ltr /mnt/${tcrppart}/backup/${backupdate}/
echo "Partition 1 : $(tar tfz /mnt/${tcrppart}/backup/${backupdate}/partition1.tgz | wc -l) files and directories "
echo "Partition 2 : $(tar tfz /mnt/${tcrppart}/backup/${backupdate}/partition2.tgz | wc -l) files and directories "
echo "DONE"
}
function restoreloader() {
loaderdisk="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)"
tcrppart="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)3"
homesize=$(du -sh /home/tc | awk '{print $1}')
PS3="Select backup folder to restore : "
options=""
if [ ! -n "$loaderdisk" ] || [ ! -n "$tcrppart" ]; then
echo "No Loader disk or no TCRP partition found, return"
return
fi
echo "Restoring loader from backup"
echo "The backup folder holds the following backups"
for folder in $(ls /mnt/${tcrppart}/backup | sed -e 's/\///g'); do
options=" $options ${folder}"
echo -n $folder
echo -n "Partition 1 : $(tar tfz /mnt/${tcrppart}/backup/${folder}/partition1.tgz | wc -l) files and directories "
echo "Partition 2 : $(tar tfz /mnt/${tcrppart}/backup/${folder}/partition2.tgz | wc -l) files and directories "
done
select restorefolder in ${options[@]}; do
if [ "$REPLY" == "quit" ]; then
return
fi
if [ -f "/mnt/${tcrppart}/backup/$restorefolder/partition1.tgz" ]; then
echo " Restore folder : $restorefolder"
echo -n "You have chosen ${restorefolder} : "
echo "Folder contains : "
ls -ltr /mnt/${tcrppart}/backup/$restorefolder
echo -n "Do you want to restore [yY/nN] : "
read answer
if [ "$answer" == "y" ] || [ "$answer" == "Y" ]; then
echo restoring $restorefolder
echo "Mounting partition 1"
mount /dev/${loaderdisk}1
echo "Restoring partition1 "
cd /mnt/${loaderdisk}1
tar xfz /mnt/${tcrppart}/backup/${restorefolder}/partition1.tgz *
ls -ltr /mnt/${loaderdisk}1
echo "Mounting partition 2"
mount /dev/${loaderdisk}2
echo "Restoring partition2 "
cd /mnt/${loaderdisk}2
tar xfz /mnt/${tcrppart}/backup/${restorefolder}/partition2.tgz *
ls -ltr /mnt/${loaderdisk}2
return
else
echo "OK, retry "
return
fi
fi
echo "Invalid choice : $REPLY"
done
}
function checkforscsi() {
# Make sure we load SCSI modules if SCSI/RAID/SAS HBAs exist on the system
#
if [ $(lspci -nn | grep -ie "\[0100\]" -ie "\[0104\]" -ie "\[0107\]" | wc -l) -gt 0 ]; then
echo "Found SCSI HBAs, We need to install the SCSI modules"
tce-load -iw scsi-5.10.3-tinycore64.tcz
[ $(losetup | grep -i "scsi-" | wc -l) -gt 0 ] && echo "Succesfully installed SCSI modules"
fi
}
function mountdsmroot() {
# DSM Disks will be linux_raid_member and will have the
# same DSM PARTUUID with the addition of the partition number e.g :
#/dev/sdb1: UUID="629ae3df-7eef-54e3-05d9-49f7b0bbaec7" TYPE="linux_raid_member" PARTUUID="d5ff7cea-01"
#/dev/sdb2: UUID="260b3a01-ff65-a527-05d9-49f7b0bbaec7" TYPE="linux_raid_member" PARTUUID="d5ff7cea-02"
# So a command like the below will list the first partition of a DSM disk
#blkid /dev/sd* |grep -i raid | awk '{print $1 " " $4}' |grep UUID | grep "\-01" | awk -F ":" '{print $1}'
checkforscsi
dsmrootdisk="$(blkid /dev/sd* | grep -i raid | awk '{print $1 " " $4}' | grep UUID | grep sd[a-z]1 | head -1 | awk -F ":" '{print $1}')"
# OLD DSM
#dsmrootdisk="$(blkid /dev/sd* | grep -i raid | awk '{print $1 " " $4}' | grep UUID | grep "\-01" | awk -F ":" '{print $1}' | head -1)"
[[ ! -d /mnt/dsmroot ]] && mkdir /mnt/dsmroot
[ ! $(mount | grep -i dsmroot | wc -l) -gt 0 ] && sudo mount -t ext4 $dsmrootdisk /mnt/dsmroot
if [ $(mount | grep -i dsmroot | wc -l) -gt 0 ]; then
echo "Succesfully mounted under /mnt/dsmroot"
else
echo "Failed to mount"
return
fi
echo "Checking if patch version exists"
if [ -d /mnt/dsmroot/.syno/patch ]; then
echo "Patch directory exists"
sudo cp /mnt/dsmroot/.syno/patch/VERSION /tmp/VERSION
sudo chmod 666 /tmp/VERSION
. /tmp/VERSION
echo "DSM Root holds a patch version $productversion-$base-$nano "
else
echo "No DSM patch directory exists"
return
fi
}
function mountdatadisk() {
echo "Assembling MD ..."
sudo mdadm -Asf
for mdarray in "$(ls /dev/md* | awk -F "\/" '{print $3}')"; do
echo "Mounting $mdarray"
echo "Getting md devices for array $mdarray"
# Keep for LVM root disks recovery in future release
if [ "$(fstype /dev/${mdarray})" == "LVM2_member" ]; then
echo "Found LVM array, downloading LVM"
tce-load -iw lvm2
sudo vgchange -a y
for volume in $(sudo lvs | grep -i vol | awk '{print $2"-"$1}'); do
if [ "$(fstype /dev/mapper/$volume)" == "btrfs" ]; then
echo "BTRFS Mounting is not supported in tinycore"
return
fi
mkdir /mnt/$volume
sudo mount /dev/mapper/$volume
done
else
echo "Mounting $mdarray "
sudo mkdir /mnt/$mdarray
sudo mount /dev/$mdarray /mnt/$mdarray
fi
done
}
function patchdtc() {
loaderdisk=$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)
localdisks=$(lsblk | grep -i disk | grep -i sd | awk '{print $1}' | grep -v $loaderdisk)
localnvme=$(lsblk | grep -i nvme | awk '{print $1}')
usbpid=$(cat user_config.json | jq '.extra_cmdline .pid' | sed -e 's/"//g' | sed -e 's/0x//g')
usbvid=$(cat user_config.json | jq '.extra_cmdline .vid' | sed -e 's/"//g' | sed -e 's/0x//g')
loaderusb=$(lsusb | grep "${usbvid}:${usbpid}" | awk '{print $2 "-" $4 }' | sed -e 's/://g' | sed -s 's/00//g')
if [ "${TARGET_PLATFORM}" = "v1000" ]; then
dtbfile="ds1621p"
elif [ "${TARGET_PLATFORM}" = "geminilake" ]; then
dtbfile="ds920p"
else
echo "${TARGET_PLATFORM} does not require model.dtc patching "
return
fi
if [ ! -d /lib64 ]; then
[ ! -h /lib64 ] && sudo ln -s /lib /lib64
fi
echo "Downloading dtc binary"
curl --location --progress-bar "$dtcbin" -O
chmod 700 dtc
if [ ! -f ${dtbfile}.dts ]; then
echo "dts file for ${dtbfile} not found, trying to download"
curl --location --progress-bar -O "${dtsfiles}/${dtbfile}.dts"
fi
echo "Found $(echo $localdisks | wc -w) disks and $(echo $localnvme | wc -w) nvme"
let diskslot=1
echo "Collecting disk paths"
for disk in $localdisks; do
diskpath=$(udevadm info --query path --name $disk | awk -F "\/" '{print $4 ":" $5 }' | awk -F ":" '{print $2 ":" $3 "," $6}' | sed 's/,*$//')
diskport=$(udevadm info --query path --name $disk | sed -n '/target/{s/.*target//;p;}' | awk -F: '{print $1}')
echo "Found local disk $disk with path $diskpath, adding into internal_slot $diskslot with portnumber $diskport"
if [ "${dtbfile}" == "ds920p" ]; then
sed -i "/internal_slot\@${diskslot} {/!b;n;n;n;n;n;n;n;cpcie_root = \"$diskpath\";" ${dtbfile}.dts
sed -i "/internal_slot\@${diskslot} {/!b;n;n;n;n;n;n;n;n;cata_port = <0x$diskport>;" ${dtbfile}.dts
let diskslot=$diskslot+1
else
sed -i "/internal_slot\@${diskslot} {/!b;n;n;n;n;n;cpcie_root = \"$diskpath\";" ${dtbfile}.dts
sed -i "/internal_slot\@${diskslot} {/!b;n;n;n;n;n;n;cata_port = <0x$diskport>;" ${dtbfile}.dts
let diskslot=$diskslot+1
fi
done
if [ $(echo $localnvme | wc -w) -gt 0 ]; then
let nvmeslot=1
echo "Collecting nvme paths"
for nvme in $localnvme; do
nvmepath=$(udevadm info --query path --name $nvme | awk -F "\/" '{print $4 ":" $5 }' | awk -F ":" '{print $2 ":" $3 "," $6}' | sed 's/,*$//')
echo "Found local nvme $nvme with path $nvmepath, adding into m2_card $nvmeslot"
if [ "${dtbfile}" == "ds920p" ]; then
sed -i "/nvme_slot\@${nvmeslot} {/!b;n;cpcie_root = \"$nvmepath\";" ${dtbfile}.dts
let diskslot=$diskslot+1
else
sed -i "/m2_card\@${nvmeslot} {/!b;n;n;n;cpcie_root = \"$nvmepath\";" ${dtbfile}.dts
let nvmeslot=$diskslot+1
fi
done
else
echo "NO NVME disks found, returning"
fi
if
[ ! -z $loaderusb ] && [ -n $loaderusb ]
then
echo "Patching USB to include your loader. Loader found in ${loaderusb} port"
sed -i "/usb_slot\@1 {/!b;n;n;n;n;n;n;n;cusb_port = \"3-5\";" ${dtbfile}.dts
else
echo "Your loader is not in USB, i will not try to patch dtb for USB"
fi
echo "Converting dts file : ${dtbfile}.dts to dtb file : >${dtbfile}.dtb "
./dtc -q -I dts -O dtb ${dtbfile}.dts >${dtbfile}.dtb
dtbextfile="$(find /home/tc/redpill-load/custom -name model_${dtbfile}.dtb)"
if [ ! -z ${dtbextfile} ] && [ -f ${dtbextfile} ]; then
echo -n "Copying patched dtb file ${dtbfile}.dtb to ${dtbextfile} -> "
sudo cp ${dtbfile}.dtb ${dtbextfile}
if [ $(sha256sum ${dtbfile}.dtb | awk '{print $1}') = $(sha256sum ${dtbextfile} | awk '{print $1}') ]; then
echo -e "OK ! File copied and verified !"
else
echo -e "ERROR !\nFile has not been copied succesfully, you will need to copy it yourself"
fi
else
[ -z ${dtbextfile} ] && echo "dtb extension is not loaded and its required for DSM to find disks on ${SYNOMODEL}"
echo "Copy of the DTB file ${dtbfile}.dtb to ${dtbextfile} was not succesfull."
echo "Please remember to replace the dtb extension model file ..."
echo "execute manually : cp ${dtbfile}.dtb ${dtbextfile} and re-run"
exit 99
fi
}
function mountshare() {
echo "smb user of the share, leave empty when you do not want to use one"
read -r user
echo "smb password of the share, leave empty when you do not want to use one"
read -r password
if [ -n "$user" ] && [ -z "$password" ]; then
echo "u used a username, so we need a password too"
echo "smb password of the share"
read -r password
fi
echo "smb host ip or hostname"
read -r server
echo "smb shared folder. Start always with /"
read -r share
echo "local mount folder. Use foldername for the mount. This folder is created in /home/tc (default:/home/tc/mount)"
read -r mountpoint
if [ -z "$mountpoint" ]; then
echo "use /home/tc/mount folder, nothing was entered to use so we use the default folder"
mountpoint="/home/tc/mount"
if [ ! -d "$mountpoint" ]; then
sudo mkdir -p "$mountpoint"
fi
else
sudo mkdir -p "$mountpoint"
fi
if [ -n "$user" ] && [ -n "$password" ]; then
sudo mount.cifs "//$server$share" "$mountpoint" -o user="$user",pass="$password"
else
echo "No user/password given, mount without. Press enter"
sudo mount.cifs "//$server$share" "$mountpoint"
fi
}
function checkmachine() {
if grep -q ^flags.*\ hypervisor\ /proc/cpuinfo; then
MACHINE="VIRTUAL"
HYPERVISOR=$(dmesg | grep -i "Hypervisor detected" | awk '{print $5}')
echo "Machine is $MACHINE Hypervisor=$HYPERVISOR"
fi
}
function backup() {
loaderdisk=$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)
homesize=$(du -sh /home/tc | awk '{print $1}')
echo "Please make sure you are using the latest 1GB img before using backup option"
echo "Current /home/tc size is $homesize , try to keep it less than 1GB as it might not fit into your image"
echo "Should i update the $loaderdisk with your current files [Yy/Nn]"
read answer
if [ -n "$answer" ] && [ "$answer" = "Y" ] || [ "$answer" = "y" ]; then
echo -n "Backing up home files to $loaderdisk : "
if filetool.sh -b ${loaderdisk}3; then
echo ""
else
echo "Error: Couldn't backup files"
fi
else
echo "OK, keeping last status"
fi
}
function satamap() {
checkmachine
checkforscsi
let controller=0
let diskidxmap=0
if [ "$MACHINE" = "VIRTUAL" ] && [ "$HYPERVISOR" = "VMware" ]; then
echo "Running on VMware, Possible working solution, SataPortMap=1 DiskIdxMap=00"
else
for hba in $(lsscsi -Hv | grep pci | grep -v usb | cut -c 44-50 | uniq); do
if [ $(lsscsi -Hv | grep "$hba" | grep ata | wc -l) -gt 0 ]; then
echo "HBA: $hba Disks : $(lsscsi -Hv | grep "$hba" | wc -l)"
lsscsi -Hv | grep "$hba" | wc -l >>satamap.$$
if [ $controller = 0 ]; then
printf "%02X" $diskidxmap >>diskmap.$$
else
let diskidxmap=$diskidxmap+$(lsscsi -Hv | grep "$hba" | wc -l)
printf "%02X" $diskidxmap >>diskmap.$$
fi
else
if [ $(lsscsi -Hv | grep -B 2 $hba | head -1 | awk '{print $2}' | grep vmw | wc -l) -gt 0 ]; then
pcidev=$(lsscsi -Hv | grep $hba | awk '{print $3}')
echo "HBA: $hba Disks : $(ls -ltrd ${pcidev}/target* | wc -l)"
ls -ltrd ${pcidev}/target* | wc -l >>satamap.$$
if [ $controller = 0 ]; then
printf "%02X" $diskidxmap >>diskmap.$$
else
let diskidxmap=$diskidxmap+$(lsscsi -Hv | grep "$hba" | wc -l)
printf "%02X" $diskidxmap >>diskmap.$$
fi
else
pcidev=$(lsscsi -Hv | grep $hba | awk '{print $3}')
echo "HBA: $hba Disks : $(ls -ltrd ${pcidev}/port* | wc -l)"
ls -ltrd ${pcidev}/port* | wc -l >>satamap.$$
if [ $controller = 0 ]; then
printf "%02X" $diskidxmap >>diskmap.$$
else
let diskidxmap=$diskidxmap+$(lsscsi -Hv | grep "$hba" | wc -l)
printf "%02X" $diskidxmap >>diskmap.$$
fi
fi
fi
let controller=$controller+1
done
sataportmap=$(cat satamap.$$ | tr -d '\n')
diskidxmap=$(cat diskmap.$$ | tr -d '\n')
echo "SataPortMap=$sataportmap"
echo "DiskIdxMap=$diskidxmap"
echo "Should i update the user_config.json with these values ? [Yy/Nn]"
read answer
if [ -n "$answer" ] && [ "$answer" = "Y" ] || [ "$answer" = "y" ]; then
sed -i "/\"SataPortMap\": \"/c\ \"SataPortMap\": \"$sataportmap\"," user_config.json
sed -i "/\"DiskIdxMap\": \"/c\ \"DiskIdxMap\": \"$diskidxmap\"" user_config.json
else
echo "OK remember to update manually by editing user_config.json file"
fi
rm satamap.$$
rm diskmap.$$
fi
}
function usbidentify() {
checkmachine
if [ "$MACHINE" = "VIRTUAL" ] && [ "$HYPERVISOR" = "VMware" ]; then
echo "Running on VMware, no need to set USB VID and PID, you should SATA shim instead"
exit 0
fi
if [ "$MACHINE" = "VIRTUAL" ] && [ "$HYPERVISOR" = "QEMU" ]; then
echo "Running on QEMU, If you are using USB shim, VID 0x46f4 and PID 0x0001 should work for you"
vendorid="0x46f4"
productid="0x0001"
echo "Vendor ID : $vendorid Product ID : $productid"
echo "Should i update the user_config.json with these values ? [Yy/Nn]"
read answer
if [ -n "$answer" ] && [ "$answer" = "Y" ] || [ "$answer" = "y" ]; then
sed -i "/\"pid\": \"/c\ \"pid\": \"$productid\"," user_config.json
sed -i "/\"vid\": \"/c\ \"vid\": \"$vendorid\"," user_config.json
else
echo "OK remember to update manually by editing user_config.json file"
fi
exit 0
fi
loaderdisk=$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)
lsusb -v 2>&1 | grep -B 33 -A 1 SCSI >/tmp/lsusb.out
usblist=$(grep -B 33 -A 1 SCSI /tmp/lsusb.out)