-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
builder.sh
executable file
·1482 lines (1411 loc) · 59.5 KB
/
builder.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
#
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
echo "Super-patch"
echo "v. 0.9.3 - devel_git"
echo ""
echo "Usage:"
echo " When on Linux Desktop ENV, even WSL:"
echo " sudo ./builder.sh [arg1]"
echo ""
echo " When on Termux Android:"
echo " ./builder.sh [arg1]"
echo ""
echo "Usage:"
echo "--help -h Shows Help Page"
echo "--clear Clear any cached files generated"
echo " by this script."
echo " Note that you need to run this on"
echo " Root if you are using a desktop"
echo " Environment"
echo "--inst_archlinux Install dependencies for archlinux"
echo " Dont run it alongside with sudo, as"
echo " paru requires the user to not run itself"
echo " as sudo"
echo ""
echo "If you have issues, visit https://t.me/a12schat"
exit
fi
if [ "$1" == "--inst_archlinux" ]; then
if [ $EUID != 0 ]; then
chmod +x libs/archlinux/init
bash libs/archlinux/init
echo "OK"
exit
else
echo "Dont run as root for this argument"
exit 1
fi
fi
if [ "$1" == "--clear" ] ; then
case $(uname -m) in
x86_64)
if [ $EUID != 0 ]; then
echo "[ERROR] You need root to run this"
exit 1
else
echo "Wiping cache"
TMP="$HOME/cached_sp"
rm -rf "$TMP"
echo ""Done
exit
fi
;;
aarch64)
echo "Wiping cache"
TMP="$HOME/cached_sp"
rm -rf "$TMP"
echo ""Done
exit
;;
*)
echo "Could not determine your cpu"
exit 1
;;
esac
fi
# GLOBAL VARIABLES (FOR INFO AND EYECANDY)
VERSION_ID="0.9.3-hfx"
STATUS="devel_git_release_candidate"
if [ "$(pwd)" == "$(pwd | grep -a super-patch)" ]; then
echo "Init Good!"
else
echo "Please run this script inside super-patch directory"
exit 1
fi
case $(uname -m) in
aarch64)
echo "[OK!] CPU is: aarch64"
;;
x86_64)
if [ $EUID != 0 ]; then
echo "[ERROR] Please Run this as root"
exit 1
fi
echo "[OK!] CPU is: x86_64"
;;
*)
echo "[ERROR] Unsupported CPU: $(uname -m)"
exit 1
;;
esac
function debian() {
dialog --backtitle "Debian/Ubuntu Env Confirmation" --title "[?] Are you sure?" \
--yes-label "I am sure" --no-label "Back" \
--yesno "Are you sure that you are running on Debian/Ubuntu Environment?\n\nWe will look for these packages: \n- APT\n- dpkg \n\nIf you don't have these in your system, then this session will crash and then you would have to relaunch again to continue" 0 0
flag=$?
case $flag in
0)
aptc=$(command -v apt 2>/dev/null)
dpkgc=$(command -v dpkg 2>/dev/null)
if [ -n "$aptc" ] && [ -n "$dpkgc" ]; then
echo "Apt and Dpkg is OK"
echo "Installing necessary packages..."
sudo apt update
sudo apt install --fix-missing -y
sudo apt install android-sdk-libsparse-utils p7zip-full lz4 -y
sudo apt update --fix-missing -y
sudo apt install --fix-missing -y
extbin --generic
touch "$TMP/pass"
else
echo "APT and Dpkg failed to see, not a Debian/Ubuntu Distro"
exit 1
fi
;;
1)
distro_select
;;
esac
}
function arch_linux() {
# This strictly requires paru to be installed
# NOTE: I realized that paru hates root
clear
echo "Check the --help option as this option is now no longer available"
echo "due to paru hating to start as root and the installation would fail..."
echo "Otherwise, ignore the message"
extbin --generic
touch "$TMP/pass"
# dialog --backtitle "Arch Linux Env Confirmation" --title "[?] Are you sure?" \
# --yes-label "I am sure" --no-label "Back" \
# --yesno "Are you sure that you are running on Arch Linux Environment?\n\nWe will look for these packages: \n- pacman \n- paru\n\nIf you don't have these in your system, then this session will crash and then you would have to relaunch again to continue\n\nyay is no longer needed as if it breaks, it would spam to the server and causing you to be in blacklist temporarily, 24 hours..." 0 0
# flag=$?
# case $flag in
# 0)
# pacmanc=$(command -v pacman 2>/dev/null)
# paruc=$(command -v paru 2>/dev/null)
# if [ -n "$pacmanc" ] && [ -n "$paruc" ]; then
# echo "Pacman and paru is OK"
# echo "Installing necessary packages..."
# sudo pacman -Syu
# sudo pacman -Sy lz4 p7zip
# paru -Syu
# paru -Sy android-sdk-platform-tools
# paru -Sy android-sdk
# extbin --generic
# touch "$TMP/pass"
# else
# echo "Pacman and Paru failed to spot, not an Arch Linux Distro"
# exit 1
# fi
# ;;
# 1)
# distro_select
# ;;
# esac
}
function android() {
dialog --backtitle "Termux Android Env Confirmation" --title "[?] Are you sure?" \
--yes-label "I am sure" --no-label "Back" \
--yesno "Are you sure that you are running on Termux Android Environment?\n\nWe will look for these packages: \n- APT\n- dpkg \n\nIf you don't have these in your system, then this session will crash and then you would have to relaunch again to continue" 0 0
flag=$?
case $flag in
0)
aptc=$(command -v apt 2>/dev/null)
dpkgc=$(command -v dpkg 2>/dev/null)
if [ -n "$aptc" ] && [ -n "$dpkgc" ]; then
echo "Apt and Dpkg is OK"
echo "Installing necessary packages..."
apt update
apt install --fix-missing -y
apt install lz4 -y
apt update --fix-missing -y
apt install --fix-missing -y
extbin --android
touch "$TMP/pass"
else
echo "APT and Dpkg failed to see, not running Termux on Android..."
exit 1
fi
;;
1)
distro_select
;;
esac
}
function wsa() {
if [[ ! "$(wsainfo >/dev/null)" ]]; then
dialog --backtitle "Debian WSA Env Confirmation" --title "[?] Are you sure?" \
--yes-label "I am sure" --no-label "Back" \
--yesno "Are you sure that you are running on Debian on a Windows Subsystem for Android Environment?\n\nWe will look for these packages: \n- APT\n- dpkg \n\nIf you don't have these in your system, then this session will crash and then you would have to relaunch again to continue" 0 0
flag=$?
case $flag in
0)
aptc=$(command -v apt 2>/dev/null)
dpkgc=$(command -v dpkg 2>/dev/null)
if [ -n "$aptc" ] && [ -n "$dpkgc" ]; then
echo "Apt and Dpkg is OK"
echo "Installing necessary packages..."
sudo apt update
sudo apt install --fix-missing -y
sudo apt install android-sdk-libsparse-utils p7zip-full lz4 -y
sudo apt update --fix-missing -y
sudo apt install --fix-missing -y
touch "$TMP/pass"
extbin --generic
else
echo "APT and Dpkg failed to see, not running Debian WSA"
exit 1
fi
;;
1)
distro_select
;;
esac
else
distro_select
fi
}
function none_e() {
clear
echo "Sorry, you cant use this script on an unsupported script"
exit 1
}
function distro_select() {
distromenu=$(dialog --backtitle "I want to know this environment" \
--title "What linux this is?" \
--menu "This script wants to know what linux this is, so it can try calling out the package manager of the current env" 0 0 0 \
"Debian/Ubuntu" "Debian & Ubuntu Latest, NOT WSA" \
"Arch Linux" "Arch Linux Latest, NOT WSA" \
"Termux Android" "Android has linux so that counts??" \
"WSA Debian" "Windows subsystem for Linux (Debian ONLY)" \
"None" "None of the above" \
2>&1 > /dev/tty)
fetch=$?
case $fetch in
1)
clear
exit 1
;;
255)
exit 255
;;
9)
exit 9
;;
esac
case "$distromenu" in
"Debian/Ubuntu")
debian
;;
"Arch Linux")
arch_linux
;;
"Termux Android")
android
;;
"WSA Debian")
wsa
;;
"None")
none_e
;;
esac
}
function extbin() {
case $1 in
"--android")
if [ ! -f "$TMP/pass" ]; then
apt install ./packages/termux-arm64/*
# distro_select
else
echo "No need to set up"
fi
;;
"--generic")
if [ ! -f "$TMP/pass" ]; then
sudo cp -rf packages/amd64/* /usr/bin/
add_tools=("lpadd" "lpdump" "lpmake" "lpunpack")
for util in "${add_tools[@]}" ; do
chmod +x /usr/bin/$util
done
# distro_select
else
echo "No need to set up"
fi
;;
*)
echo "[ERROR] Can't Understand: $1"
echo "Abruptly exiting..."
exit 1 # Literally exit for failsafes
;;
esac
}
function linux () {
if [ "$(uname -m)" == "x86_64" ]; then
if [ $EUID != 0 ]; then
echo "You need root to proceed..."
fi
fi
clear
echo "Linux Confirmed"
echo "Setting variables..."
LAB="$(pwd)/image_build"
TMP="$HOME/cached_sp"
if [ $EUID != 0 ]; then
IS_SUDO="0"
else
IS_SUDO="1"
fi
CLEAR_UP="0"
mkdir "$LAB"
mkdir "$TMP"
# Realized this line of code will not work on android, check policy
# This will be implemented separately
# if [ ! -f "$TMP/pass" ]; then
# sudo cp -rf packages/amd64/* /bin
# add_tools=("lpadd" "lpdump" "lpmake" "lpunpack")
# for util in "${add_tools[@]}" ; do
# chmod +x /usr/bin/$util
# done
# distro_select
# else
# echo "No need to set up"
# fi
if [ ! -e $TMP/pass ]; then
distro_select
fi
echo "Variables set, and components are ready to go..."
echo "Starting on 5 seconds"
sleep 5
}
# This area is in rework
# # ANOTHER GLOBAL VARIABLES (THAT ARE MUTABLE IF CONFIGED, NEXT VERSION)
# case $(uname -m) in
# "x86_64")
# if [ $EUID != 0 ]; then
# echo "Please Run this as root"
# exit 1
# fi
# if [[ "$(wsainfo > /dev/null)" ]]; then
# echo "WSL detected"
# LAB="$(pwd)/image_build"
# TMP="$HOME/cached_sp"
# IS_SUDO="1"
# CLEAR_UP="0"
# mkdir "$TMP"
# mkdir "$LAB"
# if [ ! -f "$TMP/pass" ]; then
# sudo cp -rf packages/amd64/* /bin
# addmod=("lpadd" "lpdump" "lpmake" "lpunpack")
# for elevate in "${addmod[@]}"; do
# chmod +x /usr/bin/$elevate
# done
# sudo apt install android-sdk-libsparse-utils -y
# sudo apt update --fix-missing -y
# sudo apt install --fix-missing -y
# sudo apt install android-sdk-libsparse-utils -y
# sudo apt install p7zip-full lz4 -y
# touch "$TMP/pass"
# fi
# echo "Since you are running this in desktop, the process will be happening inside the super-patch folder"
# echo "Dir: $LAB"
# echo "So please move the files there"
# echo "If you are using WSA, you can check it on File Explorer, but we recommend you to run the Environment at WSL 2 for the tools to get working properly"
# echo ""
# echo ""
# echo "Starting in 5 seconds..."
# sleep 5
# else
# echo "Real Debian Confirmed"
# LAB="$(pwd)/image_build"
# TMP="$HOME/cached_sp"
# IS_SUDO="1"
# CLEAR_UP="0"
# mkdir "$TMP"
# mkdir "$LAB"
# if [ ! -f "$TMP/pass" ]; then
# sudo cp -rf packages/amd64/* /bin
# addmod=("lpadd" "lpdump" "lpmake" "lpunpack")
# for elevate in "${addmod[@]}"; do
# chmod +x /usr/bin/$elevate
# done
# sudo apt install android-sdk-libsparse-utils -y
# sudo apt update --fix-missing -y
# sudo apt install --fix-missing -y
# sudo apt install android-sdk-libsparse-utils -y
# sudo apt install p7zip-full lz4 -y
# touch "$TMP/pass"
# fi
# clear
# echo "Real Debian Moment Here!"
# echo "The Environment the building will take place at:"
# echo "$LAB"
# echo "And the TMP will be at:"
# echo "$TMP"
# echo -ne "\n\nRemeber that..."
# echo -ne "\nStarting in 5 seconds\n"
# sleep 5
# fi
# ;;
# "aarch64")
# if [ "$EUID" == 0 ]; then
# echo "Dont use Root Please"
# exit 1
# fi
# termux-setup-storage
# ed=$?
# if [ "$ed" == 0 ]; then
# dpkg -i packages/termux-arm64/*
# LAB="$HOME/storage/shared/image_build"
# TMP="$HOME/cached_sp"
# CLEAR_UP="0"
# IS_SUDO="0"
# mkdir "$LAB"
# mkdir "$TMP"
# else
# echo "Setup can't continue if termux-setup-storage isnt working, also if youre running this other than termux, please download termux."
# echo "If you're running this on WSA Arm, uhhh sorry, script dont support that"
# echo "https://github.com/termux/termux-app"
# exit 1
# fi
# dpkg -i packages/termux-arm64/*
# ;;
# *)
# echo "Your Device isnt supported: $(uname -m)"
# echo "This script only supports ARM64, and x86_64/AMD64"
# exit 1
# ;;
# esac
#TMP="$HOME/cached_sp"
# Trap Functions
function cleanup_waste {
if [[ "$CLEAR_UP" == 1 ]]; then
bar
msg "Cleaning Up TMP Directories.."
rm -rf "${TMP/*}"
msg "Done"
bar
exit
else
msg "cleanup_waste: FLAG CLEAR_UP was set to 0, will not clean the tmpfiles"
exit
fi
}
trap 'cleanup_waste' 0 1
# CORE FUNCTIONS
function msg {
echo "$1"
}
function bar {
msg ""
msg "==============================================="
msg ""
}
function datetime {
M_D_Y=$(date +%m-%d-%y)
SECOND_TMER=$(date +%T)
msg "$M_D_Y - $SECOND_TMER<s>"
}
function check_files {
#obsolete
bar
msg "Analyzing Files"
msg "The files will also be installed"
bar
}
function msgbox {
dialog --backtitle "SAMSUNG GSI TO SUPER - $VERSION_ID - $STATUS" --title "$1" --msgbox "$2" 0 0
}
# function linkerer {
# # OBSOLETE
# ln -s "~/builder.sh" "$PREFIX/bin"
# }
function mdt {
#MSG with Datetime
msg "$(datetime) - $1"
}
function yesno () {
clear
dialog --backtitle "SAMSUNG GSI TO SUPER - $VERSION_ID - $STATUS" --title "Confirm" --yes-label "Sure" --no-label "Cancel" --yesno "$1" 0 0
}
# Inner workings
function extract_ap {
# Extracts AP, and super
msg "$(datetime) - Checking if files are present"
if [ -e $LAB/AP_*.tar.md5 ]; then # Shellcheck Linter tryna telling me wrong for wildcarding if -e rn, i wish i wanna fking bit that sht
msg "$(datetime) - AP File Found... Extracting"
if [ "$IS_SUDO" == "0" ]; then
7z e $LAB/AP_*.tar.md5 -o$LAB/
else
sudo 7z e $LAB/AP_*.tar.md5 -o$LAB/
fi
#E1
msg "$(datetime) - Looking for the Super"
if [ -e "$LAB/super.img.lz4" ]; then
msg "$(datetime) Super.img.lz4 Found"
#mv -f $LAB/AP/super.img.lz4" "$LAB/super.img.lz4
mdt "CLEANUP!"
TARGET_RM=("recovery.img.lz4" "boot.img.lz4" "dtbo.img.lz4" "userdata.img.lz4" "misc.bin.lz4" "vbmeta.img.lz4" "vbmeta_system.img.lz4" "meta-data" "metadata.img.lz4" "fota.zip")
for KILL in "${TARGET_RM[@]}"; do
if [ "$IS_SUDO" == "0" ]; then
rm -rf $LAB/$KILL
mdt "$KILL removed as it's useless"
else
sudo rm -rf $LAB/$KILL
mdt "$KILL removed as it's useless"
fi
done
mdt "Useless Files Removed"
sleep 1
menu_ap_super
else
mdt "No LZ4 Version of Super.img was found after extraction, checking if theres super.img"
if [ -e "$LAB/super.img" ]; then
mdt "Super.img found, moving"
mdt "CLEANUP!"
TARGET_RM=("recovery.img" "boot.img" "dtbo.img" "userdata.img" "misc.bin" "vbmeta.img" "vbmeta_system.img" "meta-data" "metadata.img" "fota.zip")
for KILL in "${TARGET_RM[@]}"; do
if [ "$IS_SUDO" == "0" ]; then
rm -rf "${LAB/$KILL:?}"
mdt "$KILL removed as it's useless"
else
sudo rm -rf $LAB/$KILL
mdt "$KILL removed as it's useless"
fi
done
mdt "Useless Files Removed"
mdt "Going back"
sleep 5
menu_ap_super
else
mdt "Cannot find super.img or super.img.lz4, make sure thats the right AP that you selected or make sure the device is treble supported"
sleep 5
menu_man "Error: super.img not found - AP_no_super"
fi
fi
else
mdt "Cannot Find AP Image, if you have already extracted it, then try to go to Extract Super instead"
sleep 5
menu_man "Error: Can't locate AP"
fi
}
function extract_super_img {
mdt "Extracting Super IMG File"
mdt "Checking if super was compressed"
if [ -e "$LAB/super.img.lz4" ] ; then
mdt "Super was compressed, decompressing"
unlz4 --rm $LAB/super.img.lz4
mdt "Super was reported to be uncompressed now by unlz4, confirming"
if [ -e "$LAB/super.img" ]; then
mdt "Super was indeed Uncompressed"
if [ -e "$LAB/super.img" ]; then
mdt "Now, converting it"
simg2img $LAB/super.img $LAB/super_raw.img
mdt "Simg2img process stopped, checking if super_raw exists..."
if [ -e "$LAB/super_raw.img" ]; then
mdt "super_raw.img exists, checking the file"
if [ "$(ls -nl "$LAB/super_raw.img" | awk '{print $5}')" -lt 100000 ]; then
mdt "Super raw seems abnormally tiny (below 100MB)"
mdt "Removing Super_raw since it may be obsolete"
mdt "Instead using super instead"
rm -rf $LAB/super_raw.img
mdt "Dumping super.img"
lpdump $LAB/super.img > $TMP/super_map.txt
mdt "Dumping Done"
mdt "Calling printf to do something..."
printf "$(<$TMP/super_map.txt)" | grep -e "Size:" | awk '{print $2}' > $TMP/super_size.txt
printf "$(<$TMP/super_map.txt)" | grep -e "Maximum size:" | awk '{print $3}' | sed '2!d' > $TMP/super_main.txt
mdt "printf process done"
mdt "Packing"
lpunpack $LAB/super.img $LAB/
mdt "Done"
gsi_select
else
mdt "Removing Super.img since we have super_raw"
rm -rf $LAB/super.img
mdt "Super.img removed"
mdt "Dumping super_raw.img"
lpdump $LAB/super_raw.img > $TMP/super_map.txt
mdt "Dumping Done"
mdt "Calling printf to do something..."
printf "$(<$TMP/super_map.txt)" | grep -e "Size:" | awk '{print $2}' > $TMP/super_size.txt
printf "$(<$TMP/super_map.txt)" | grep -e "Maximum size:" | awk '{print $3}' | sed '2!d' > $TMP/super_main.txt
mdt "printf process done"
mdt "Packing"
lpunpack $LAB/super_raw.img $LAB/
gsi_picker
fi
else
mdt "Cannot proceed because super_raw is not present, it also proves the fact that super.img could be corrupted"
sleep 3
menu_man "Error: super_img_corrupt"
fi
else
mdt "Could not find super.img"
mdt "Try checking Terminal permissions"
sleep 3
menu_man "Error: cant locate super.img?"
fi
else
mdt "Super was not uncompressed"
mdt "It seems theres an internal error."
mdt "Report this: extract_super_lz4_error_8"
sleep 5
menu_man "Error: Special: extract_super_lz4_error_8"
fi
else
mdt "It seems that super.img.lz4 is not present, could it be the user had already extracted it?"
mdt "Checking for the super.img in the directory build"
if [ -e "$LAB/super.img" ]; then
mdt "Yes, confirmed super.img was extracted already by external interference..."
mdt "Now, converting it"
simg2img $LAB/super.img $LAB/super_raw.img
mdt "Simg2img process stopped, checking if super_raw exists..."
if [ -e "$LAB/super_raw.img" ]; then
mdt "super_raw.img exists, checking the file"
if [ "$(ls -nl "$LAB/super_raw.img" | awk '{print $5}')" -lt 100000 ]; then
mdt "Super raw seems abnormally tiny (below 100MB)"
mdt "Removing Super_raw since it may be obsolete"
mdt "Instead using super instead"
rm -rf $LAB/super_raw.img
mdt "Dumping super.img"
lpdump $LAB/super.img > $TMP/super_map.txt
mdt "Dumping Done"
mdt "Calling printf to do something..."
printf "$(<$TMP/super_map.txt)" | grep -e "Size:" | awk '{print $2}' > $TMP/super_size.txt
printf "$(<$TMP/super_map.txt)" | grep -e "Maximum size:" | awk '{print $3}' | sed '2!d' > $TMP/super_main.txt
mdt "printf process done"
mdt "Packing"
lpunpack $LAB/super.img $LAB/
mdt "Done"
gsi_select
else
mdt "Removing Super.img since we have super_raw"
rm -rf $LAB/super.img
mdt "Super.img removed"
mdt "Dumping super_raw.img"
lpdump $LAB/super_raw.img > $TMP/super_map.txt
mdt "Dumping Done"
mdt "Calling printf to do something..."
printf "$(<$TMP/super_map.txt)" | grep -e "Size:" | awk '{print $2}' > $TMP/super_size.txt
printf "$(<$TMP/super_map.txt)" | grep -e "Maximum size:" | awk '{print $3}' | sed '2!d' > $TMP/super_main.txt
mdt "printf process done"
mdt "Packing"
lpunpack $LAB/super_raw.img $LAB/
gsi_picker
fi
else
mdt "Cannot proceed because super_raw is not present, it also proves the fact that super.img could be corrupted"
sleep 3
menu_man "Error: super_img_corrupt"
fi
else
mdt "Could not find super.img"
mdt "Try checking Terminal permissions"
sleep 3
menu_man "Error: cant locate super.img?"
fi
fi
}
function super_info {
#This is a descriptor
# Only Intended for dialog env
msg "\n\nSuper Image Size: $(ls -nl "$LAB/super.img" | awk '{print $5}')"
msg "\nSystem Image Size: $(ls -nl "$LAB/system.img" | awk '{print $5}')"
msg "\nVendor Image Size: $(ls -nl "$LAB/vendor.img" | awk '{print $5}')"
msg "\nProduct Image Size: $(ls -nl "$LAB/product.img" | awk '{print $5}')"
msg "\nSystem EXT Image Size: $(ls -nl "$LAB/system-ext.img" | awk '{print $5}')"
msg "\nODM Image Size: $(ls -nl "$LAB/odm.img" | awk '{print $5}')"
}
function wipe_cache_tmp_clut {
rm -rf $TMP/*
msgbox "Done" "Files Cleaned"
menu_man
}
function menu_ap_super {
menu_page=$(dialog \
--backtitle "SAMSUNG GSI TO SUPER - $VERSION_ID - $STATUS" \
--title "Extract AP/Super" \
--menu "Select what you want to do in the menu\n\nReports by super_info:$(super_info)\n\nIf these values are empty, it means you didnt do the process or something.\nAsk us at the Telegram Group" 0 0 0 \
"Extract AP" "Extract AP File (Stock AP)" \
"Extract Magisked AP" "Extract Magisked AP" \
"Extract Super" "Extract Super File instead" \
"Pick GSI" "Pick GSI" \
2>&1 >/dev/tty)
local ervar=$?
case $ervar in
1)
clear
menu_man
;;
esac
case $menu_page in
"Extract AP")
yesno "Are you sure that you want to extract the AP? Make sure it is present in your dir: $LAB"
fetch=$?
case $fetch in
0)
clear
mdt "Process now in verbose mode for stable processing"
mdt "Starting in 5 seconds"
sleep 5
extract_ap
;;
1)
menu_ap_super
;;
esac
;;
"Extract Super")
yesno "Are you sure you want to extract the Super? Make sure that you already extracted it in this Dir: $LAB\n\nAlready extracted super.img works too."
fetch=$?
case $fetch in
0)
clear
mdt "Process now in verbose mode for stable processing"
mdt "Starting in 5 seconds"
sleep 5
extract_super_img
;;
1)
menu_ap_super
;;
esac
;;
"Pick GSI")
gsi_picker
;;
"Extract Magisked AP")
yesno "Are you sure you want to pick 'Extract Magisked AP'?"
fetch=$?
case $fetch in
0)
magisk_pick_ap
;;
1)
menu_ap_super
;;
esac
;;
*)
clear
mdt "Something went wrong and the process needed to end abruptly"
mdt "Please report this: E-mapsu-cl=$menu_page"
exit 9
;;
esac
}
function magisk_pick_ap {
# This is painful to implement
PCX=$(dialog \
--backtitle "SAMSUNG GSI TO SUPER - $VERSION_ID - $STATUS" \
--title "Pick Patched AP by Magisk" \
--ok-label "Pick the AP File" \
--cancel-label "Back" \
--fselect "$LAB" 0 0 \
2>&1 >/dev/tty)
local exvar=$?
case $exvar in
1)
menu_ap_super
;;
0)
if [ -z $PCX ]; then
mdt "Checking if the file is present..."
export DIALOGRC="libs/dialog-rc/error.thm"
msgbox "ERROR" "The variable is null!"
unset DIALOGRC
menu_man "Empty Entry from: magisk_pick_ap"
else
mdt "Checking if $PCX is present and has the right size"
if [ -e $PCX ] && [ $(ls -nl $PCX | awk '{print $5}') -gt 2000000000 ]; then
mdt "Correct file"
mdt "Moving file: $PCX to $LAB/MAP"
mkdir $LAB/MAP
cp -r $PCX $LAB/MAP/magisked.tar
if [ -e "$LAB/MAP/magisked.tar" ]; then
mdt "File Done Copied"
mdt "Extracting..."
7z e $LAB/MAP/magisked.tar -o$LAB/MAP/
mdt "p7zip reports that the process is done"
mdt "Looking for super"
if [ -e "$LAB/MAP/super.img.lz4" ]; then
mdt "File found"
mdt "Removing waste"
TARGET_RM=("recovery.img.lz4" "boot.img.lz4" "dtbo.img.lz4" "userdata.img.lz4" "misc.bin.lz4" "vbmeta.img.lz4" "vbmeta_system.img.lz4" "meta-data" "metadata.img.lz4" "fota.zip")
for KILL in "${TARGET_RM[@]}"; do
if [ "$IS_SUDO" == "0" ]; then
rm -rf $LAB/MAP/$KILL
mdt "$KILL removed as it's useless"
else
sudo rm -rf $LAB/MAP/$KILL
mdt "$KILL removed as it's useless"
fi
done
mdt "Done"
mv $LAB/MAP/super.img.lz4 $LAB/
mdt "Revert back to Extract AP/Super then try to extract super to continue"
msg ""
read -n 1 -t 100 -p "PRESS ANY KEY TO END" fdk
if [[ -n $FDK ]]; then
menu_man
else
menu_man
fi
else
export DIALOGRC="libs/dialog-rc/error.thm"
msgbox "ERROR, CANNOT FIND SUPER!" "The script cant find the super.img.lz4 from selected $PCX!"
unset DIALOGRC
menu_man "Empty file loc: magisked_ap_file"
fi
else
export DIALOGRC="libs/dialog-rc/error.thm"
msgbox "ERROR! CANNOT FIND magisked.tar!" "Uh oh, it seems that the script can't find where the magisked tar is? please check the build location please!"
unset DIALOGRC
menu_man "magisk_pick_ap: No such file found after transfer"
fi
else
export DIALOGRC="libs/dialog-rc/error.thm"
msgbox "ERROR, NOT ENOUGH SIZE" "Are you sure thats the correct size for a Patched AP? it may be smaller than that or you used official magisk to patch.\n\nWe recommend you to use Magisk Delta or Magisk Kitsune instead since it only works on Samsung\n\nDebug:\nFile Size Reported: $(ls -nl "$PCX" | awk '{print $5}') \n Which it violates the 2GB limit"
unset DIALOGRC
menu_man "Error:\nEstimation file wasnt exact"
fi
fi
;;
esac
}
function build_super {
menu_page=$(dialog \
--backtitle "SAMSUNG GSI TO SUPER - $VERSION_ID - $STATUS" \
--title "Build Super" \
--menu "$(datetime) <s> Super Info Report: $(super_info) \n\nIf all values are empty then you didn't extract the files properly, go back on Extract option\n\n\nSelection:\n Build (.tar) - Build the Super with tar format" 0 0 0 \
"Build" "Build with Tar Only Compression" \
"Build with xz" "Build with tar.xz compression" \
"Build with 7z" "Build with 7z Compression" \
2>&1 >/dev/tty)
local ervar=$?
case $ervar in
1)
menu_man
;;
esac
case $menu_page in
"Build")
yesno "Are you sure to start building? with tar only compression?"
local ercon=$?
case $ercon in
0)
build_normal_cmp
;;
1)
build_super
;;
esac
;;
"Build with xz")
yesno "Are you sure to start building with xz compression?"
local ercon=$?
case $ercon in
0)
build_xz_cmp
;;
1)
build_super
;;
esac
;;
"Build with 7z")
yesno "Are you sure to start building with 7z compression?"
local ercon=$?
case $ercon in
0)
build_7z_cmp
;;
1)
build_super
;;
esac
;;
esac
}
function build_file {
clear
if [ "$(find $LAB/system.img -type f ! -size 0 -printf '%S\n' | sed 's/.\.[0-9]*//')" == 1 ]; then
mdt "Processing..."
else
mdt "Something needs to be taken care of... Please Wait..."
simg2img $LAB/system.img $LAB/system.raw.img
fi
if [ -e "$LAB/odm.img" ]; then
if [ -e "$LAB/product.img" ]; then
mdt "Product already present"
#mdt "Warning: If the patching didn't work, you can ask the group for help"
if [ "$(ls -nl $LAB/product.img | awk '{print $5}')" -gt 6000 ]; then
mdt "Replacing Product.img as it identifies to be a potential stock Product, with universal product.img"
cp -rf fake-props/product.img $LAB/product.img
else
mdt "Confirmed to be a potential universal product.img detected..."
fi
else
mdt "Product does not exist, probably external interference or old AP device..."
mdt "Replacing it with Universal Product.img"
cp -rf fake-props/product.img $LAB/product.img
mdt "Done"
fi
mdt "Starting Building"
mdt "You may see header errors, but that just mean that its doing something right..."
lpmake --metadata-size 65536 --super-name super --metadata-slots 2 --device super:$(<$TMP/super_size.txt) --group main:$(<$TMP/super_main.txt) --partition system:readonly:$(ls -nl $LAB/system.img | awk '{print $5}'):main --image system=$LAB/system.img --partition vendor:readonly:$(ls -nl $LAB/vendor.img | awk '{print $5}'):main --image vendor=$LAB/vendor.img --partition product:readonly:$(ls -nl $LAB/product.img | awk '{print $5}'):main --image product=$LAB/product.img --partition odm:readonly:$(ls -nl $LAB/odm.img | awk '{print $5}'):main --image odm=$LAB/odm.img --sparse --output $LAB/super.img
mdt "OK!"
else
if [ -e "$LAB/product.img" ]; then
mdt "Product already Present"
#mdt "If patching didn't work, then you can ask the group for help"
if [ "$(ls -nl $LAB/product.img | awk '{print $5}')" -gt 6000 ]; then
mdt "Replacing Product.img as it identifies to be a potential stock Product, with universal product.img"
cp -rf fake-props/product.img $LAB/product.img
else
mdt "Confirmed to be a potential universal product.img detected..."
fi
else
mdt "Product does not exist, probably external interference or old AP device..."
mdt "Replacing it with Universal Product.img"
cp -rf fake-props/product.img $LAB/product.img
mdt "Done"
fi
if [ -e "$LAB/system_ext.img" ]; then
mdt "System_ext already present, so fake system_ext is no longer needed."
else
mdt "System_ext is not present, it could be an external interference"
mdt "Trying to add Universal System_ext"
cp -rf fake-props/system_ext.img $LAB/product.img
mdt "Done"
fi
mdt "Starting Building"
mdt "You may see header errors, but that's just mean that its doing something right"
lpmake --metadata-size 65536 --super-name super --metadata-slots 2 --device super:$(<$TMP/super_size.txt) --group main:$(<$TMP/super_main.txt) --partition system:readonly:$(ls -nl $LAB/system.img | awk '{print $5}'):main --image system=$LAB/system.img --partition vendor:readonly:$(ls -nl $LAB/vendor.img | awk '{print $5}'):main --image vendor=$LAB/vendor.img --partition product:readonly:$(ls -nl $LAB/product.img | awk '{print $5}'):main --image product=$LAB/product.img --partition system_ext:readonly:$(ls -nl $LAB/system_ext.img | awk '{print $5}'):main --image system_ext=$LAB/system_ext.img --sparse --output $LAB/super.img
fi
}
function build_normal_cmp {
mdt "Starting process..."
mdt "Starting : build_file"
build_file
mdt "It seems process : build_file has completed the task"
mdt "Proceeding..."
sleep 5
file_name=$(dialog --backtitle "SAMSUNG GSI TO SUPER - $VERSION_ID - $STATUS" --title "Name-a-file" --inputbox "Enter what you want to name this file: \n\nREMEBER: NO SPACES, FILE EXTENSIONS AND SLASHES AND IF IT BREAKS ITS YOUR FAULT! \nGoing back resets to default name\n\nDefault:" 0 0 "exported_super" 2>&1 >/dev/tty)
if [ -z "$file_name" ]; then
mdt "No value detected, using default name"
file_name="exported_super"