forked from pocopico/tinycore-redpill
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathrploader.sh
executable file
·3653 lines (2888 loc) · 142 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 : pocopico
# Date : 221115
# Version : 0.9.4.0-1
#
#
##### INCLUDES ######################################################################################
source /home/tc/functions.h
#####################################################################################################
rploaderver="1.0.2.9"
build="master"
redpillmake="prod"
rploaderfile="https://raw.githubusercontent.com/PeterSuh-Q3/tinycore-redpill/$build/rploader.sh"
rploaderrepo="https://raw.githubusercontent.com/PeterSuh-Q3/tinycore-redpill/$build/"
redpillextension="https://raw.githubusercontent.com/PeterSuh-Q3/rp-ext/master/redpill${redpillmake}/rpext-index.json"
modextention="https://raw.githubusercontent.com/PeterSuh-Q3/rp-ext/master/rpext-index.json"
modalias4="https://raw.githubusercontent.com/PeterSuh-Q3/tinycore-redpill/$build/modules.alias.4.json.gz"
modalias3="https://raw.githubusercontent.com/PeterSuh-Q3/tinycore-redpill/$build/modules.alias.3.json.gz"
dtcbin="https://raw.githubusercontent.com/PeterSuh-Q3/tinycore-redpill/$build/tools/dtc"
dtsfiles="https://raw.githubusercontent.com/PeterSuh-Q3/tinycore-redpill/$build"
timezone="UTC"
ntpserver="pool.ntp.org"
userconfigfile="/home/tc/user_config.json"
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 rploader.sh"
HOMEPATH="/home/tc"
TOOLSPATH="https://raw.githubusercontent.com/PeterSuh-Q3/tinycore-redpill/main/tools/"
TOOLS="bspatch bzImage-template-v4.gz bzImage-template-v5.gz bzImage-to-vmlinux.sh calc_run_size.sh crc32 dtc kexec ramdisk-patch.sh vmlinux-to-bzImage.sh xxd zimage-patch.sh kpatch grub-editenv pigz modprobe"
# END Do not modify after this line
######################################################################################################
# extract nano LD_LIBRARY_PATH=/home/tc/archive/lib /home/tc/archive/synoarchive.nano -xvf ../synology_geminilake_dva1622.pat
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.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.9.0.0 Development version. Moving all new features to development build
0.9.0.1 Updated postupdate to facilitate update to update2
0.9.0.2 Added system monitor function
0.9.0.3 Updated satamap to support DUMMY PORT detection
0.9.0.4 More satamap fixes
0.9.0.5 Added the option to get grub variables into user_config.json
0.9.0.6 Experimental DVA1622 (geminilake) addition
0.9.0.7 Experimental DVA1622 serialgen
0.9.0.8 Experimental DVA1622 increase disk count to 16
0.9.0.9 Fixed missing bspatch
0.9.1.0 Added dtc depth patch
0.9.1.1 Default action for DTB system is to use the dtbpatch by fbelavenuto
0.9.1.2 Fixed a jq issue in listextension
0.9.1.3 Fixed bsdiff not found issue
0.9.1.4 Fixed overlaping downloadextractor processes
0.9.1.5 Enhanced postupdate process to update user_config.json to new format
0.9.1.6 Fixed compressed non-compressed RAMDISK issue
0.9.1.7 Enhanced build process to update user_config.json during build process
0.9.1.8 Enhanced build process to create friend files
0.9.1.9 Further enhanced build process
0.9.2.0 Introducing TCRP Friend
0.9.2.1 If TCRP Friend is used then default option will be TCRP Friend
0.9.2.2 Upgrade your system by adding TCRP Friend with command bringfriend
0.9.2.3 Adding experimental DS2422+ support
0.9.2.4 Added the redpillmake variable to select between prod and dev modules
0.9.2.5 Adding experimental RS4021xs+ support
0.9.2.6 Added the downloadupgradepat action **experimental
0.9.2.7 Added setting the static network configuration for TCRP Friend
0.9.2.8 Changed all calls to use the -k flag to avoid expired certificate issues
0.9.2.9 Added the smallfixnumber key in user_config.json and changed the platform ids to model ids
0.9.3.0 Changed set root entry to search for FS UUID
0.9.4.3-1 Multilingual menu support
0.9.5.0 Add storage panel size selection menu
0.9.6.0 To prevent partition space shortage, rd.gz is no longer used in partition 1
0.9.7.0 Improved build processing speed (removed pat file download process)
0.9.7.1 Back to DSM Pat Handle Method
1.0.0.0 Kernel patch process improvements
1.0.0.1 Improved platform release ID identification method
1.0.0.2 Setplatform() function converted to custom_config.json reference method
1.0.0.3 To prevent partition space shortage, custom.gz is no longer used in partition 1
1.0.0.4 Prevents kernel panic from occurring due to rp-lkm.zip download failure
when ramdisk patching occurs without internet.
1.0.0.5 Add offline loader build function
1.0.1.0 Upgrade from Tinycore version 12.0 (kernel 5.10.3) to 14.0 (kernel 6.1.2) to improve compatibility with the latest devices.
1.0.1.1 Fix monitor fuction about ethernet infomation
1.0.1.2 Fix for SA6400
1.0.2.0 Remove restrictions on use of DT-based models when using HBA (apply mpt3sas blacklist instead)
1.0.2.1 Changed extension file organization method
1.0.2.2 Recycle initrd-dsm instead of custom.gz (extract /exts), The priority starts from custom.gz
1.0.2.3 Added RedPill bootloader hard disk porting function
1.0.2.4 Added NVMe bootloader support
1.0.2.5 Provides menu option to disable i915 module loading to prevent console blackout in ApolloLake (DS918+), GeminiLake (DS920+), and Epyc7002 (SA6400)
1.0.2.6 Added multilingual support languages (locales) (Arabic, Hindi, Hungarian, Indonesian, Turkish)
1.0.2.7 dbgutils Addon Add/Delete selection menu
1.0.2.8 Added multilingual support languages (locales) (Amharic-Ethiopian, Thai)
1.0.2.9 Release img image with gettext.tgz
--------------------------------------------------------------------------------------
EOF
}
function msgalert() {
echo -e "\033[1;31m$1\033[0m"
}
function msgwarning() {
echo -e "\033[1;33m$1\033[0m"
}
function msgnormal() {
echo -e "\033[1;32m$1\033[0m"
}
function st() {
echo -e "[$(date '+%T.%3N')]:-------------------------------------------------------------" >> /home/tc/buildstatus
echo -e "\e[35m$1\e[0m \e[36m$2\e[0m $3" >> /home/tc/buildstatus
}
function readanswer() {
while true; do
read answ
case $answ in
[Yy]* ) answer="$answ"; break;;
[Nn]* ) answer="$answ"; break;;
* ) msgwarning "Please answer yY/nN.";;
esac
done
}
function setnetwork() {
if [ -f /opt/eth*.sh ] && [ "$(grep dhcp /opt/eth*.sh | wc -l)" -eq 0 ]; then
ipset="static"
ipgw="$(route | grep default | head -1 | awk '{print $2}')"
ipprefix="$(grep ifconfig /opt/eth*.sh | head -1 | awk '{print "ipcalc -p " $3 " " $5 }' | sh - | awk -F= '{print $2}')"
myip="$(grep ifconfig /opt/eth*.sh | head -1 | awk '{print $3 }')"
ipaddr="${myip}/${ipprefix}"
ipgw="$(grep route /opt/eth*.sh | head -1 | awk '{print $5 }')"
ipdns="$(grep nameserver /opt/eth*.sh | head -1 | awk '{print $3 }')"
ipproxy="$(env | grep -i http | awk -F= '{print $2}' | uniq)"
for field in ipset ipaddr ipgw ipdns ipproxy; do
jsonfile=$(jq ".ipsettings+={\"$field\":\"${!field}\"}" $userconfigfile)
echo $jsonfile | jq . >$userconfigfile
done
fi
}
function httpconf() {
tce-load -iw lighttpd 2>&1 >/dev/null
cat >/home/tc/lighttpd.conf <<EOF
server.document-root = "/home/tc/html"
server.modules = ( "mod_cgi" , "mod_alias" )
server.errorlog = "/home/tc/html/error.log"
server.pid-file = "/home/tc/html/lighttpd.pid"
server.username = "tc"
server.groupname = "staff"
server.port = 80
alias.url = ( "/rploader/" => "/home/tc/html/" )
cgi.assign = ( ".sh" => "/usr/local/bin/bash" )
index-file.names = ( "index.html","index.htm", "index.sh" )
EOF
sudo lighttpd -f /home/tc/lighttpd.conf
[ $(sudo netstat -an 2>/dev/null | grep LISTEN | grep ":80" 2>/dev/null | wc -l) -eq 1 ] && echo "Server started succesfully"
# Add entry to bootlocal and backup
# cat /opt/bootlocal.sh
}
function getgrubconf() {
# tcrpdisk="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)"
grubdisk="${tcrpdisk}1"
echo "Mounting bootloader disk to get grub contents"
sudo mount /dev/$grubdisk
if [ $(df | grep -i $grubdisk | wc -l) -gt 0 ]; then
echo -n "Mounted succesfully : $(df -h | grep $grubdisk)"
[ -f /mnt/$grubdisk/boot/grub/grub.cfg ] && [ $(cat /mnt/$grubdisk/boot/grub/grub.cfg | wc -l) -gt 0 ] && echo " -> Grub cfg is accessible and readable"
else
echo "Couldnt mount device : $grubdisk "
exit 99
fi
echo "Getting known loader grub variables"
grep pid /mnt/$grubdisk/boot/grub/grub.cfg >/tmp/grub.vars
while IFS=" " read -r -a line; do
printf "%s\n" "${line[@]}"
done </tmp/grub.vars | egrep -i "sataportmap|sn|pid|vid|mac|hddhotplug|diskidxmap|netif_num" | sort | uniq >/tmp/known.vars
if [ -f /tmp/known.vars ]; then
echo "Sourcing vars, found in grub : "
. /tmp/known.vars
rows="%-15s| %-15s | %-10s | %-10s | %-10s | %-15s | %-15s %c\n"
printf "$rows" Serial Mac Netif_num PID VID SataPortMap DiskIdxMap
printf "$rows" $sn $mac1 $netif_num $pid $vid $SataPortMap $DiskIdxMap
echo "Checking user config against grub vars"
for var in pid vid sn mac1 SataPortMap DiskIdxMap; do
if [ $(jq -r .extra_cmdline.$var user_config.json) == "${!var}" ]; then
echo "Grub var $var = ${!var} Matches your user_config.json"
else
echo "Grub var $var = ${!var} does not match your user_config.json variable which is set to : $(jq -r .extra_cmdline.$var user_config.json) "
echo "Should we populate user_config.json with these variables ? [Yy/Nn] "
readanswer
if [ -n "$answer" ] && [ "$answer" = "Y" ] || [ "$answer" = "y" ]; then
json="$(jq --arg newvar "${!var}" '.extra_cmdline.'$var'= $newvar' user_config.json)" && echo -E "${json}" | jq . >user_config.json
else
echo "OK, you can edit yourself later"
fi
fi
done
else
echo "Could not read variables"
fi
}
function getip() {
ethdevs=$(ls /sys/class/net/ | grep eth || true)
for eth in $ethdevs; do
DRIVER=$(ls -ld /sys/class/net/${eth}/device/driver 2>/dev/null | awk -F '/' '{print $NF}')
IP="$(ifconfig ${eth} | grep inet | awk '{print $2}' | awk -F \: '{print $2}')"
HWADDR="$(ifconfig ${eth} | grep HWaddr | awk '{print $5}')"
VENDOR=$(cat /sys/class/net/${eth}/device/vendor | sed 's/0x//')
DEVICE=$(cat /sys/class/net/${eth}/device/device | sed 's/0x//')
if [ ! -z "${VENDOR}" ] && [ ! -z "${DEVICE}" ]; then
MATCHDRIVER=$(echo "$(matchpciidmodule ${VENDOR} ${DEVICE})")
if [ ! -z "${MATCHDRIVER}" ]; then
if [ "${MATCHDRIVER}" != "${DRIVER}" ]; then
DRIVER=${MATCHDRIVER}
fi
fi
fi
echo "IP Address : $(msgnormal "${IP}"), ${HWADDR} : ${eth} (${DRIVER})"
done
}
function listpci() {
lspci -n | while read line; do
bus="$(echo $line | cut -c 1-7)"
class="$(echo $line | cut -c 9-12)"
vendor="$(echo $line | cut -c 15-18)"
device="$(echo $line | cut -c 20-23)"
#echo "PCI : $bus Class : $class Vendor: $vendor Device: $device"
case $class in
# 0100)
# echo "Found SCSI Controller : pciid ${vendor}d0000${device} Required Extension : $(matchpciidmodule ${vendor} ${device})"
# ;;
# 0106)
# echo "Found SATA Controller : pciid ${vendor}d0000${device} Required Extension : $(matchpciidmodule ${vendor} ${device})"
# ;;
# 0101)
# echo "Found IDE Controller : pciid ${vendor}d0000${device} Required Extension : $(matchpciidmodule ${vendor} ${device})"
# ;;
0104)
msgnormal "RAID bus Controller : Required Extension : $(matchpciidmodule ${vendor} ${device})"
echo `lspci -nn |grep ${vendor}:${device}|awk 'match($0,/0104/) {print substr($0,RSTART+7,100)}'`| sed 's/\['"$vendor:$device"'\]//' | sed 's/(rev 05)//'
;;
0107)
msgnormal "SAS Controller : Required Extension : $(matchpciidmodule ${vendor} ${device})"
echo `lspci -nn |grep ${vendor}:${device}|awk 'match($0,/0107/) {print substr($0,RSTART+7,100)}'`| sed 's/\['"$vendor:$device"'\]//' | sed 's/(rev 03)//'
;;
# 0200)
# msgnormal "Ethernet Interface : Required Extension : $(matchpciidmodule ${vendor} ${device})"
# ;;
# 0680)
# msgnormal "Ethernet Interface : Required Extension : $(matchpciidmodule ${vendor} ${device})"
# ;;
# 0300)
# echo "Found VGA Controller : pciid ${vendor}d0000${device} Required Extension : $(matchpciidmodule ${vendor} ${device})"
# ;;
# 0c04)
# echo "Found Fibre Channel Controller : pciid ${vendor}d0000${device} Required Extension : $(matchpciidmodule ${vendor} ${device})"
# ;;
esac
done
}
function monitor() {
# loaderdisk="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)"
mount /dev/${loaderdisk}1
mount /dev/${loaderdisk}2
while [ -z "$GATEWAY_INTERFACE" ]; do
clear
echo -e "-------------------------------System Information----------------------------"
echo -e "Hostname:\t\t"$(hostname)
echo -e "uptime:\t\t\t"$(uptime | awk '{print $3}' | sed 's/,//')" min"
echo -e "Manufacturer:\t\t"$(cat /sys/class/dmi/id/chassis_vendor)
echo -e "Product Name:\t\t"$(cat /sys/class/dmi/id/product_name)
echo -e "Version:\t\t"$(cat /sys/class/dmi/id/product_version)
echo -e "Serial Number:\t\t"$(sudo cat /sys/class/dmi/id/product_serial)
echo -e "Operating System:\t"$(grep PRETTY_NAME /etc/os-release | awk -F \= '{print $2}')
echo -e "Kernel:\t\t\t"$(uname -r)
echo -e "Processor Name:\t\t"$(awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//')
echo -e "Machine Type:\t\t"$(
vserver=$(lscpu | grep Hypervisor | wc -l)
if [ $vserver -gt 0 ]; then echo "VM"; else echo "Physical"; fi
)
msgnormal "CPU Threads:\t\t"$(lscpu |grep CPU\(s\): | awk '{print $2}')
echo -e "Current Date Time:\t"$(date)
#msgnormal "System Main IP:\t\t"$(ifconfig | grep inet | grep -v 127.0.0.1 | awk '{print $2}' | awk -F \: '{print $2}' | tr '\n' ',' | sed 's#,$##')
getip
listpci
echo -e "-------------------------------Loader boot entries---------------------------"
grep -i menuentry /mnt/${loaderdisk}1/boot/grub/grub.cfg | awk -F \' '{print $2}'
echo -e "-------------------------------CPU / Memory----------------------------------"
msgnormal "Total Memory (MB):\t"$(cat /proc/meminfo |grep MemTotal | awk '{printf("%.2f%"), $2/1000}')
echo -e "Swap Usage:\t\t"$(free | awk '/Swap/{printf("%.2f%"), $3/$2*100}')
echo -e "CPU Usage:\t\t"$(cat /proc/stat | awk '/cpu/{printf("%.2f%\n"), ($2+$4)*100/($2+$4+$5)}' | awk '{print $0}' | head -1)
echo -e "-------------------------------Disk Usage >80%-------------------------------"
df -Ph /mnt/${loaderdisk}1 /mnt/${loaderdisk}2 /mnt/${loaderdisk}3
echo "Press ctrl-c to exit"
sleep 10
done
}
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://github.com/PeterSuh-Q3/rp-ext/raw/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+ DS1019+ DS920+ DS3622xs+ FS6400 DVA3219 DVA3221 DS1621+ DS1621xs+ DS2422+ DS1520+ FS2500 RS4021xs+ RS3618xs RS3413xs+ DS923+"
;;
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 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
if [ $(lscpu |grep Intel |wc -l) -gt 0 ]; then
CPU="INTEL"
else
CPU="AMD"
fi
}
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] : "
readanswer
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 downloadtools() {
echo "Downloading Kernel Patch tools"
[ ! -d ${HOMEPATH}/tools ] && mkdir -p ${HOMEPATH}/tools
cd ${HOMEPATH}/tools
for FILE in $TOOLS; do
curl -skLO "$TOOLSPATH/${FILE}"
chmod +x $FILE
done
st "Patch Tools" "Download tools " "Kernel Patch Tools downloaded"
cd ${HOMEPATH}
}
function copyextractor() {
#m shell mofified
local_cache="/mnt/${tcrppart}/auxfiles"
echo "making directory ${local_cache}"
[ ! -d ${local_cache} ] && mkdir ${local_cache}
echo "making directory ${local_cache}/extractor"
[ ! -d ${local_cache}/extractor ] && mkdir ${local_cache}/extractor
[ ! -f /home/tc/extractor.gz ] && sudo curl -kL -# "https://raw.githubusercontent.com/PeterSuh-Q3/tinycore-redpill/master/extractor.gz" -o /home/tc/extractor.gz
sudo tar -zxvf /home/tc/extractor.gz -C ${local_cache}/extractor
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 "pigz copy for multithreaded compression"
sudo cp /mnt/${tcrppart}/auxfiles/extractor/pigz /usr/local/bin/pigz
}
function downloadextractor() {
st "extractor" "Extraction tools" "Extraction Tools downloaded"
# 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"
#m shell mofified
copyextractor
if [ -d ${local_cache/extractor /} ] && [ -f ${local_cache}/extractor/scemd ]; then
msgnormal "Found extractor locally cached"
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 -kL https://global.download.synology.com/download/DSM/release/7.0.1/42218/DSM_DS3622xs%2B_42218.pat -o /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
fi
echo "Removing temp folder /tmp/synoesp"
rm -rf $temp_folder
msgnormal "Checking if tool is accessible"
if [ -d ${local_cache/extractor /} ] && [ -f ${local_cache}/extractor/scemd ]; then
/bin/syno_extract_system_patch 2>&1 >/dev/null
else
/bin/syno_extract_system_patch
fi
if [ $? -eq 255 ]; then echo "Executed succesfully"; else echo "Cound not execute"; fi
}
function chkavail() {
if [ $(df -h /mnt/${tcrppart} | grep mnt | awk '{print $4}' | grep G | wc -l) -gt 0 ]; then
avail_str=$(df -h /mnt/${tcrppart} | grep mnt | awk '{print $4}' | sed -e 's/G//g' | cut -c 1-3)
avail=$(echo "$avail_str 1000" | awk '{print $1 * $2}')
else
avail=$(df -h /mnt/${tcrppart} | grep mnt | awk '{print $4}' | sed -e 's/M//g' | cut -c 1-3)
fi
avail_num=$(($avail))
echo "Avail space ${avail_num}M on /mnt/${tcrppart}"
}
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"
temp_dsmpat_folder="/tmp/dsmpat"
setplatform
if [ ! -d "${temp_pat_folder}" ]; then
msgnormal "Creating temp folder ${temp_pat_folder} "
mkdir ${temp_pat_folder} && sudo mount -t tmpfs -o size=512M tmpfs ${temp_pat_folder} && cd ${temp_pat_folder}
mkdir ${temp_dsmpat_folder} && sudo mount -t tmpfs -o size=512M tmpfs ${temp_dsmpat_folder}
fi
echo "Checking for cached pat file"
[ -d $local_cache ] && msgnormal "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)
msgnormal "Found locally cached pat file ${patfile}"
st "iscached" "Caching pat file" "Patfile ${SYNOMODEL}.pat is cached"
testarchive "${patfile}"
if [ ${isencrypted} = "no" ]; then
echo "File ${patfile} is already decrypted"
msgnormal "Copying file to /home/tc/redpill-load/cache folder"
mv -f ${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 "Decrypted file is already cached in : /home/tc/redpill-load/cache/${SYNOMODEL}.pat"
else
echo "Copying encrypted pat file : ${patfile} to ${temp_dsmpat_folder}"
mv -f ${patfile} ${temp_dsmpat_folder}/${SYNOMODEL}.pat
echo "Extracting encrypted pat file : ${temp_dsmpat_folder}/${SYNOMODEL}.pat to ${temp_pat_folder}"
sudo /bin/syno_extract_system_patch ${temp_dsmpat_folder}/${SYNOMODEL}.pat ${temp_pat_folder} || echo "extract latest pat"
echo "Decrypting pat file ${SYNOMODEL}.pat to /home/tc/redpill-load/cache folder (multithreaded comporession)"
mkdir -p /home/tc/redpill-load/cache/
thread=$(lscpu |grep CPU\(s\): | awk '{print $2}')
cd ${temp_pat_folder} && tar -cf - ./ | pigz -p $thread > ${temp_dsmpat_folder}/${SYNOMODEL}.pat && cp -f ${temp_dsmpat_folder}/${SYNOMODEL}.pat /home/tc/redpill-load/cache/${SYNOMODEL}.pat
fi
patfile="/home/tc/redpill-load/cache/${SYNOMODEL}.pat"
else
echo "Something went wrong, please check cache files"
exit 99
fi
cd /home/tc/redpill-load/cache
st "patextraction" "Pat file extracted" "VERSION:${TARGET_VERSION}-${TARGET_REVISION}"
tar xvf /home/tc/redpill-load/cache/${SYNOMODEL}.pat ./VERSION && . ./VERSION && cat ./VERSION && rm ./VERSION
os_sha256=$(sha256sum /home/tc/redpill-load/cache/${SYNOMODEL}.pat | awk '{print $1}')
msgnormal "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, The download may be corrupted or may not be run the original repo. Please re-download from original repo."
exit 99
fi
msgnormal "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
msgnormal "Clearing temp folders"
sudo umount ${temp_pat_folder} && sudo rm -rf ${temp_pat_folder}
sudo umount ${temp_dsmpat_folder} && sudo rm -rf ${temp_dsmpat_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} "
chkavail
if [ $avail_num -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 -kL ${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')"
if [ $? -ne 0 ]; then
echo "FAILED : Processing add_extensions failed check the output for any errors"
./rploader.sh clean
exit 99
fi
done
if [ "${ORIGIN_PLATFORM}" = "epyc7002" ]; then
vkersion=${major}${minor}_${KVER}
else
vkersion=${KVER}
fi
for extension in ${EXTENSIONS}; do
echo "Updating extension : ${extension} contents for platform, kernel : ${ORIGIN_PLATFORM}, ${vkersion} "
platkver="$(echo ${ORIGIN_PLATFORM}_${vkersion} | sed 's/\.//g')"
echo "platkver = ${platkver}"
cd /home/tc/redpill-load/ && ./ext-manager.sh _update_platform_exts ${platkver} ${extension}
if [ $? -ne 0 ]; then
echo "FAILED : Processing add_extensions failed check the output for any errors"
./rploader.sh clean
exit 99
fi
done
#m shell only
#Use user define dts file instaed of dtbpatch ext now
if [ ${ORIGIN_PLATFORM} = "geminilake" ] || [ ${ORIGIN_PLATFORM} = "v1000" ] || [ ${ORIGIN_PLATFORM} = "r1000" ]; then
echo "For user define dts file instaed of dtbpatch ext"
patchdtc
echo "Patch dtc is superseded by fbelavenuto dtbpatch"
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 updateuserconfig() {
echo "Checking user config for general block"
generalblock="$(jq -r -e '.general' $userconfigfile)"
if [ "$generalblock" = "null" ] || [ -n "$generalblock" ]; then
echo "Result=${generalblock}, File does not contain general block, adding block"
for field in model version smallfixnumber redpillmake zimghash rdhash usb_line sata_line; do
jsonfile=$(jq ".general+={\"$field\":\"\"}" $userconfigfile)
echo $jsonfile | jq . >$userconfigfile
done
fi
}
function updateuserconfigfield() {
block="$1"
field="$2"
value="$3"
if [ -n "$1 " ] && [ -n "$2" ]; then
jsonfile=$(jq ".$block+={\"$field\":\"$value\"}" $userconfigfile)
echo $jsonfile | jq . >$userconfigfile
else
echo "No values to update specified"
fi
}
function removefriend() {
clear
# loaderdisk="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)"
echo "------------------------------------------------------------------------------------------------------------"
echo "You are not satisfied with TCRP friend."
echo "Understandable, but you will not be able to perform automatic patching after updates."
echo "you can still though use the postupdate process instead or just set the default option to SATA or USB as usual"
echo "------------------------------------------------------------------------------------------------------------"
echo -n "Do you still want to remove TCRP Friend, please answer [Yy/Nn]"
readanswer
if [ "${answer}" = "Y" ] || [ "${answer}" = "y" ]; then
mount /dev/${loaderdisk}1 2>/dev/null
mount /dev/${loaderdisk}2 2>/dev/null
mount /dev/${loaderdisk}3 2>/dev/null
echo "Removing TCRP Friend from ${loaderdisk}3 "
[ -f /mnt/${loaderdisk}3/initrd-friend ] && sudo rm -rf /mnt/${loaderdisk}3/initrd-friend
[ -f /mnt/${loaderdisk}3/bzImage-friend ] && sudo rm -rf /mnt/${loaderdisk}3/bzImage-friend
echo "Removing initrd-dsm and zimage-dsm from ${loaderdisk}3 "
[ ! "$(sha256sum /mnt/${loaderdisk}3/initrd-dsm | awk '{print $2}')" = "$(sha256sum /mnt/${loaderdisk}3/rd.gz | awk '{print $2}')" ] && cp /mnt/${loaderdisk}3/initrd-dsm /mnt/${loaderdisk}3/rd.gz
[ -f /mnt/${loaderdisk}3/initrd-dsm ] && sudo rm -rf /mnt/${loaderdisk}3/initrd-dsm
[ ! "$(sha256sum /mnt/${loaderdisk}3/zImage-dsm | awk '{print $2}')" = "$(sha256sum /mnt/${loaderdisk}1/zImage | awk '{print $2}')" ] && cp /mnt/${loaderdisk}3/zImage-dsm /mnt/${loaderdisk}1/zImage
[ -f /mnt/${loaderdisk}3/zimage-dsm ] && sudo rm -rf /mnt/${loaderdisk}3/zimage-dsm
echo "Removing TCRP Friend Grub entry "
[ $(grep -i "Tiny Core Friend" /mnt/${loaderdisk}1/boot/grub/grub.cfg | wc -l) -eq 1 ] && sed -i "/Tiny Core Friend/,+9d" /mnt/${loaderdisk}1/boot/grub/grub.cfg
if [ "$MACHINE" = "VIRTUAL" ]; then
echo "Setting default boot entry to SATA"
cd /home/tc/redpill-load/ && sudo sed -i "/set default=\"*\"/cset default=\"1\"" /mnt/${loaderdisk}1/boot/grub/grub.cfg
else
echo "Setting default boot entry to USB"
cd /home/tc/redpill-load/ && sudo sed -i "/set default=\"*\"/cset default=\"0\"" /mnt/${loaderdisk}1/boot/grub/grub.cfg
fi
else
echo "OK ! Wise choice !!! "
fi
}
function bringfriend() {
clear
# loaderdisk="$(mount | grep -i optional | grep cde | awk -F / '{print $3}' | uniq | cut -c 1-3)"
mount /dev/${loaderdisk}1 2>/dev/null
mount /dev/${loaderdisk}2 2>/dev/null
mount /dev/${loaderdisk}3 2>/dev/null
if [ -f /mnt/${loaderdisk}3/lastsession/user_config.json ]; then
cp /mnt/${loaderdisk}3/lastsession/user_config.json /home/tc/user_config.json
getgrubconf
else
getgrubconf
fi
if [ -f /mnt/${loaderdisk}3/bzImage-friend ] && [ -f /mnt/${loaderdisk}3/initrd-friend ] && [ -f /mnt/${loaderdisk}3/zImage-dsm ] && [ -f /mnt/${loaderdisk}3/initrd-dsm ] && [ -f /mnt/${loaderdisk}3/user_config.json ] && [ $(grep -i "Tiny Core Friend" /mnt/${loaderdisk}1/boot/grub/grub.cfg | wc -l) -eq 1 ]; then
echo "Your TCRP friend seems in place, do you want to re-run the process ?"
readanswer
if [ "${answer}" = "Y" ] || [ "${answer}" = "y" ]; then
echo "OK re-running the TCRP Friend bring over process"
else
echo "Wise choice"
exit 0
fi
fi
echo "You are upgrading your system with TCRP friend."
echo "Your system will still be able to boot using the USB/SATA options."
echo "After bringing over TCRP Friend, The default boot option will be set TCRP Friend."
echo "You will still have the option to move to SATA/USB but for automatic patching after an update,"
echo "please leave the default to TCRR Friend"
echo -n "If you agree with the above, please answer [Yy/Nn]"
readanswer
if [ "${answer}" = "Y" ] || [ "${answer}" = "y" ]; then
if [ ! -f /mnt/${loaderdisk}3/initrd-friend ] || [ ! -f /mnt/${loaderdisk}3/bzImage-friend ]; then
[ ! -f /home/tc/friend/initrd-friend ] && [ ! -f /home/tc/friend/bzImage-friend ] && bringoverfriend
if [ -f /home/tc/friend/initrd-friend ] && [ -f /home/tc/friend/bzImage-friend ]; then
cp /home/tc/friend/initrd-friend /mnt/${loaderdisk}3/
cp /home/tc/friend/bzImage-friend /mnt/${loaderdisk}3/
fi
fi
if [ -f /mnt/${loaderdisk}3/initrd-friend ] || [ -f /mnt/${loaderdisk}3/bzImage-friend ]; then
[ $(grep -i "Tiny Core Friend" /mnt/${loaderdisk}1/boot/grub/grub.cfg | wc -l) -eq 1 ] || tcrpfriendentry | sudo tee --append /mnt/${loaderdisk}1/boot/grub/grub.cfg
# Compining rd.gz and custom.gz
echo "Compining rd.gz and custom.gz and copying zimage to ${loaderdisk}3 "
[ ! -d /home/tc/rd.temp ] && mkdir /home/tc/rd.temp
[ -d /home/tc/rd.temp ] && cd /home/tc/rd.temp
if [ "$(od /mnt/${loaderdisk}3/rd.gz | head -1 | awk '{print $2}')" = "000135" ]; then
RD_COMPRESSED="true"
else
RD_COMPRESSED="false"
fi
if [ "$RD_COMPRESSED" = "false" ]; then
echo "Ramdisk in not compressed "
cat /mnt/${loaderdisk}3/rd.gz | sudo cpio -idm 2>/dev/null >/dev/null
cat /mnt/${loaderdisk}3/custom.gz | sudo cpio -idm 2>/dev/null >/dev/null
sudo chmod +x /home/tc/rd.temp/usr/sbin/modprobe
(cd /home/tc/rd.temp && sudo find . | sudo cpio -o -H newc -R root:root >/mnt/${loaderdisk}3/initrd-dsm) 2>&1 >/dev/null
else
unlzma -dc /mnt/${loaderdisk}3/rd.gz | sudo cpio -idm 2>/dev/null >/dev/null
cat /mnt/${loaderdisk}3/custom.gz | sudo cpio -idm 2>/dev/null >/dev/null
sudo chmod +x /home/tc/rd.temp/usr/sbin/modprobe
(cd /home/tc/rd.temp && sudo find . | sudo cpio -o -H newc -R root:root | xz -9 --format=lzma >/mnt/${loaderdisk}3/initrd-dsm) 2>&1 >/dev/null
fi
. /home/tc/rd.temp/etc/VERSION
MODEL="$(grep upnpmodelname /home/tc/rd.temp/etc/synoinfo.conf | awk -F= '{print $2}' | sed -e 's/"//g')"
VERSION="${productversion}-${buildnumber}"
cp -f /mnt/${loaderdisk}1/zImage /mnt/${loaderdisk}3/zImage-dsm
updateuserconfig
setnetwork
updateuserconfigfield "general" "model" "$MODEL"
updateuserconfigfield "general" "version" "${VERSION}"
updateuserconfigfield "general" "smallfixnumber" "${smallfixnumber}"
updateuserconfigfield "general" "redpillmake" "${redpillmake}"
zimghash=$(sha256sum /mnt/${loaderdisk}2/zImage | awk '{print $1}')
updateuserconfigfield "general" "zimghash" "$zimghash"
rdhash=$(sha256sum /mnt/${loaderdisk}2/rd.gz | awk '{print $1}')
updateuserconfigfield "general" "rdhash" "$rdhash"