forked from pocopico/tinycore-redpill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rploader.sh
2662 lines (2104 loc) · 94.1 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 : 220705
# Version : 0.8.0.5
#
#
# User Variables :
rploaderver="0.8.0.5"
build="main"
rploaderfile="https://raw.githubusercontent.com/pocopico/tinycore-redpill/$build/rploader.sh"
rploaderrepo="https://github.com/pocopico/tinycore-redpill/raw/$build/"
redpillextension="https://github.com/pocopico/rp-ext/raw/$build/redpill/rpext-index.json"
modextention="https://github.com/pocopico/rp-ext/raw/$build/rpext-index.json"
modalias4="https://raw.githubusercontent.com/pocopico/tinycore-redpill/$build/modules.alias.4.json.gz"
modalias3="https://raw.githubusercontent.com/pocopico/tinycore-redpill/$build/modules.alias.3.json.gz"
dtcbin="https://raw.githubusercontent.com/pocopico/tinycore-redpill/$build/dtc"
dtsfiles="https://raw.githubusercontent.com/pocopico/tinycore-redpill/$build"
timezone="UTC"
ntpserver="pool.ntp.org"
fullupdatefiles="custom_config.json custom_config_jun.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 history() {
cat <<EOF
--------------------------------------------------------------------------------------
0.7.0.0 Added build for version greater than 42218
0.7.0.1 Added required extension parsing adding and downloading
0.7.0.2 Added usb patch in patchdtc
0.7.0.3 Added portnumber on patchdtc
0.7.0.4 Make sure that local cache folder is created early in the process
0.7.0.5 Enabled interactive
0.7.0.6 Added save/restore session functions
0.7.0.7 Added a check date function
0.7.0.8 Added the ability to use local dtb file
0.7.0.9 Added flyride satamap review
0.7.1.0 Added the history, version and enhanced patchdtc function
0.7.1.1 Added a syntaxcheck function
0.7.1.2 Added sync time with NTP server : pool.ntp.org (Set timezone and ntpserver variables accordingly )
0.7.1.3 Added the option to create JUN mod loader (By Jumkey)
0.7.1.4 Added the use of the additional custom_config_jun.json for JUN mod loader creation
0.7.1.5 Updated satamap function to support higher the 9 port counts per HBA.
0.7.1.6 Updated satamap function to fix the broken q35 KVM controller, and to stop scanning for CD-ROM's
0.7.1.7 Updated serialgen function to include the option for using the realmac
0.7.1.8 Updated satamap function to fine tune SATA port identification and identify SATABOOT
0.7.1.9 Updated patchdtc function to fix wrong port identification for VMware hosted systems
0.8.0.0 Stable version. All new features will be moved to develop repo
0.8.0.1 Updated postupdate to facilitate update to update2
0.8.0.2 Updated satamap to support DUMMY PORT detection
0.8.0.3 Updated satamap to avoid the use of 0 in first controller that cause KP
0.8.0.4 Fixed missing binary
0.8.0.5 Fixed a jq issue in listextension
--------------------------------------------------------------------------------------
EOF
}
function syntaxcheck() {
if [ $# -lt 2 ] && [ "$1" == "download" ] || [ "$1" == "build" ] || [ "$1" == "ext" ] || [ "$1" == "restoresession" ] || [ "$1" == "listmods" ] || [ "$1" == "serialgen" ] || [ "$1" == "patchdtc" ] || [ "$1" == "postupdate" ]; then
echo "Error : Number of arguments : $#, options $@ "
case $1 in
download)
echo "Syntax error, You have to specify one of the existing platforms" && getPlatforms
;;
build)
echo "Syntax error, You have to specify one of the existing platforms" && getPlatforms
;;
ext)
echo "Syntax error, You have to specify one of the existing platforms, the action and the extension URL"
echo "example:"
echo "rploader.sh ext apollolake-7.0.1-42218 add https://raw.githubusercontent.com/pocopico/rp-ext/master/e1000/rpext-index.json"
echo "or for auto detect use"
echo "rploader.sh ext apollolake-7.0.1-42218 auto"
;;
restoresession)
echo "Syntax error, You have to specify one of the existing platforms" && getPlatforms
;;
listmods)
echo "Syntax error, You have to specify one of the existing platforms" && getPlatforms
;;
serialgen)
echo "Syntax error, You have to specify one of the existing models"
echo "DS3615xs DS3617xs DS916+ DS918+ DS920+ DS3622xs+ FS6400 DVA3219 DVA3221 DS1621+"
;;
patchdtc)
echo "Syntax error, You have to specify one of the existing platforms" && getPlatforms
;;
postupdate)
echo "Syntax error, You have to specify one of the existing platforms" && getPlatforms
;;
*)
echo "Syntax error, not valid arguments or not enough options"
showhelp
;;
esac
exit 99
else
return
fi
}
function version() {
shift 1
echo $rploaderver
[ "$1" == "history" ] && history
}
function savesession() {
lastsessiondir="/mnt/${tcrppart}/lastsession"
echo -n "Saving user session for future use. "
[ ! -d ${lastsessiondir} ] && sudo mkdir ${lastsessiondir}
echo -n "Saving current extensions "
cat /home/tc/redpill-load/custom/extensions/*/*json | jq '.url' >${lastsessiondir}/extensions.list
[ -f ${lastsessiondir}/extensions.list ] && echo " -> OK !"
echo -n "Saving current user_config.json "
cp /home/tc/user_config.json ${lastsessiondir}/user_config.json
[ -f ${lastsessiondir}/user_config.json ] && echo " -> OK !"
}
function restoresession() {
lastsessiondir="/mnt/${tcrppart}/lastsession"
if [ -d $lastsessiondir ]; then
echo -n "Found last user session : , restore session ? [yY/nN] : "
read answer
if [ "$answer" == "y" ] || [ "$answer" == "Y" ]; then
if [ -d $lastsessiondir ] && [ -f ${lastsessiondir}/extensions.list ]; then
for extension in $(cat ${lastsessiondir}/extensions.list); 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
fi
if [ -d $lastsessiondir ] && [ -f ${lastsessiondir}/user_config.json ]; then
echo "Copying last user_config.json"
cp ${lastsessiondir}/user_config.json /home/tc
fi
fi
else
echo "OK, we will not restore last session"
fi
}
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() {
loaderdisk="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)"
cd /home/tc
echo "Creating temp ramdisk space" && mkdir /home/tc/ramdisk
echo "Mounting partition ${loaderdisk}1" && sudo mount /dev/${loaderdisk}1
echo "Mounting partition ${loaderdisk}2" && sudo mount /dev/${loaderdisk}2
cd /home/tc/ramdisk
echo "Extracting update ramdisk"
if [ $(od /mnt/${loaderdisk}2/rd.gz | head -1 | awk '{print $2}') == "000135" ]; then
sudo unlzma -c /mnt/${loaderdisk}2/rd.gz | cpio -idm 2>&1 >/dev/null
else
sudo cat /mnt/${loaderdisk}2/rd.gz | cpio -idm 2>&1 >/dev/null
fi
. ./etc.defaults/VERSION && echo "Found Version : ${productversion}-${buildnumber}-${smallfixnumber}"
echo -n "Do you want to use this for the loader ? [yY/nN] : "
read answer
if [ "$answer" == "y" ] || [ "$answer" == "Y" ]; then
echo "Extracting redpill ramdisk"
if [ $(od /mnt/${loaderdisk}1/rd.gz | head -1 | awk '{print $2}') == "000135" ]; then
sudo unlzma -c /mnt/${loaderdisk}1/rd.gz | cpio -idm
else
sudo cat /mnt/${loaderdisk}1/rd.gz | cpio -idm
fi
. ./etc.defaults/VERSION && echo "The new smallupdate version will be : ${productversion}-${buildnumber}-${smallfixnumber}"
echo -n "Do you want to use this for the loader ? [yY/nN] : "
read answer
if [ "$answer" == "y" ] || [ "$answer" == "Y" ]; then
echo "Recreating ramdisk " && sudo find . 2>/dev/null | cpio -o -H newc -R root:root | xz -9 --format=lzma >../rd.gz
cd ..
echo "Adding fake sign" && sudo dd if=/dev/zero of=rd.gz bs=68 count=1 conv=notrunc oflag=append
echo "Putting ramdisk back to the loader partition ${loaderdisk}1" && sudo cp -f rd.gz /mnt/${loaderdisk}1/rd.gz
echo "Removing temp ramdisk space " && rm -rf ramdisk
echo "Done"
else
exit 0
fi
fi
}
function postupdatev1() {
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/$build/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() {
checkmachine
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 /home/tc/custom-module/${dtbfile}.dts ] && [ ! -f /home/tc/custom-module/${dtbfile}.dtb ]; then
echo "Found locally cached dts file ${dtbfile}.dts and dtb file does not exist in cache, converting dts to dtb"
./dtc -q -I dts -O dtb /home/tc/custom-module/${dtbfile}.dts >/home/tc/custom-module/${dtbfile}.dtb
fi
if [ -f /home/tc/custom-module/${dtbfile}.dtb ]; then
echo "Fould locally cached dtb file"
read -p "Should i use that file ? [Yy/Nn]" answer
if [ -n "$answer" ] && [ "$answer" = "Y" ] || [ "$answer" = "y" ]; then
echo "OK copying over the cached dtb file"
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 /home/tc/custom-module/${dtbfile}.dtb ${dtbextfile}
if [ $(sha256sum /home/tc/custom-module/${dtbfile}.dtb | awk '{print $1}') = $(sha256sum ${dtbextfile} | awk '{print $1}') ]; then
echo -e "OK ! File copied and verified !"
return
else
echo -e "ERROR !\nFile has not been copied succesfully, you will need to copy it yourself"
return
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