-
Notifications
You must be signed in to change notification settings - Fork 0
/
.env
executable file
·672 lines (601 loc) · 28.9 KB
/
.env
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
PREFIX="/data/data/com.termux/files/usr"
detect_env() {
detect_arch() {
BIN_DIR=$(pwd)/bin ; i=$(uname -m)
case $i in
arm) export ARCH=arm ;; aarch64) export ARCH=arm64 ;;
x86) export ARCH=x86 ;; x86_64) export ARCH=x86_64 ;;
esac
}
load_binaries() {
BIN_EXEC="${BIN_DIR}/${ARCH}" ; i=$(uname -o)
case $i in Android) export OS=android ; BIN_EXEC="${BIN_DIR}/${ARCH}/${OS}" ;; esac
for cmd in $(ls -1 "$BIN_EXEC"); do [ -x "$BIN_EXEC/$cmd" ] && { chmod +x $BIN_EXEC/* ; export $cmd=$BIN_EXEC/$cmd ; } done
}
set_global_vars() {
MOUNTED_IMGS=$(sudo $busybox mount | grep /mounted/ | awk '{print $3}' | sed 's/.*\///')
SCRIPT_NAME="$(basename "$0" | sed 's|.*/||')"
LOG_FILE=".log" ; TMP_FILE1=".tmp.1" ; TMP_FILE2=".tmp.2"
silence() { "$@" >/dev/null 2>&1; }
}
root_check() {
if su -c "pgrep zygote >/dev/null"; then
echo "\nDevice is rooted.\n"
else
echo "\nDevice is not rooted.\n" && exit 1
fi
}
busybox_check() {
if su -c "ls /data/adb/magisk/busybox >/dev/null 2>&1"; then
echo "Busybox is installed."
else
echo "Busybox is not installed."
exit 1
fi
}
detect_arch ; load_binaries ; set_global_vars
}
chkrdtype() {
file="$1"
file_type=$(/system/bin/file -b "$file" | tr '[:upper:]' '[:lower:]')
[ "$file_type" = *"gzip"* ] && { echo "gzip" ; }
[ "$file_type" = *"xz"* ] && { echo "xz" ; }
[ "$file_type" = *"zst"* ] && { echo "zst" ; }
[ "$file_type" = *"cpio"* ] && { echo "cpio" ; } || echo "Unknown"
}
device_info() {
retail_name=$(getprop ro.product.model)
brand=$(getprop ro.product.brand)
device_name=$(getprop ro.product.device)
hw_sku=$(getprop ro.boot.hardware.sku)
android_version=$(getprop ro.build.version.release)
build_id=$(getprop ro.build.id)
build_version=$(getprop ro.build.version.incremental)
build_tags=$(getprop ro.build.tags)
build_type=$(getprop ro.build.type)
soc_manufacturer=$(getprop ro.soc.manufacturer)
soc_model=$(getprop ro.soc.model)
board=$(getprop ro.product.board)
securitypatch=$(getprop ro.build.version.security_patch)
kernel_ver=$(getprop ro.kernel.version)
encryption_state=$(getprop ro.crypto.state)
carrier=$(getprop ro.carrier)
printf "
Name: $retail_name
Brand: $brand
Device Name: $device_name
Hardware SKU: $hw_sku
Android Version: $android_version
Build: $build_id
Build Version: $build_version
Security Patch: $securitypatch
Build Tags: $build_tags
Build Type: $build_type
SoC Manufacturer: $soc_manufacturer
SoC Model: $soc_model
Board Name: $board
Kernel Version: $kernel_ver
Encryption State: $encryption_state
"
}
arch() { ARCH=$(uname -m) ; [ "$ARCH" = aarch64 ] && { ARCH="arm64" && echo $ARCH ;} ; }
busybox() { su -c "/data/adb/magisk/busybox $1" ; }
silence() { "$@" >/dev/null 2>&1; }
sha() { $sha256sum "$TMP"/"$1" | awk '{print substr($1, length($1) - 6)}' ; }
list_installed() { dpkg --get-selections | awk '{print $1}' | sed 's|/.*||' | tr '\n' ' ' | sed 's/ $/\n/' ; }
cmd_exists() { command -v "$1" >/dev/null 2>&1 ; }
termux_version() { sudo pm dump com.termux | grep "versionName=" | sed 's/^[^=]*=//' ; }
IS() { [ -d "$ROOTFS/$1" ] && { echo "+ [installed]" ; } || echo "- [not installed]" ; }
pdsh() { x="$1" ; pd sh "$OS" --shared-tmp --no-sysvipc -- env DISPLAY=:1 $x ; }
check() { [ -d "$PROOT" ] && return || pd i "$OS" && termux-reload-settings ; }
timezone() { [ -f "$PROOT/etc/timezone" ] && return || echo "$(getprop persist.sys.timezone)" > $PROOT/etc/timezone ; }
update_pkgs() { pdsh "apt update -y" && pdsh "apt upgrade -y" && pdsh "apt autoremove -y" ; }
list_partitions() { sudo find /dev/block/bootdevice/by-name -type l -printf "%p -> " -exec readlink -f {} \; | awk '{print $NF, $0}' | sort | cut -d' ' -f2- ; }
idc() { pdsh "id $user" >/dev/null 2>&1 ; }
logo() {
echo "
___ _ _ _
|_ | ___ _| |___ _ _ ___| |___ ___ _____ ___ ___| |_
_| |_| | . | -_| | | -_| | . | . | | -_| | _|
|_____|_|_|___|___|\_/|___|_|___| _|_|_|_|___|_|_| |
|_| |__|
"
}
ascii_box() {
ti="$1" ; mw=$((COLUMNS - 8)) ; bw=$mw ; b=$(printf '%*s' "$((bw-2))" | tr ' ' '=') ; pb="x${b}x" ; cw=$((bw - 6))
echo "\n$pb\n|$(printf '%*s' "$((bw-2))")|" ; l=""
for w in $ti; do
if [ $((${#l} + ${#w} + 1)) -le $cw ]; then
[ -n "$l" ] && l+=" " ; l+="$w"
else
p=$(( (bw - ${#l} - 2) / 2 ))
printf "|%*s%s%*s|\n" $p "" "$l" $((bw - p - ${#l} - 2)) ""
l="$w"
fi
done
[ -n "$l" ] && { p=$(( (bw - ${#l} - 2) / 2 )) ; printf "|%*s%s%*s|\n" $p "" "$l" $((bw - p - ${#l} - 2)) "" ; }
echo "|$(printf '%*s' "$((bw-2))")|\n$pb\n"
}
bcalc() {
i=$1 && s=$2
2kb() { echo "scale=2; $1 / (1024)" | bc; }
2mb() { echo "scale=2; $1 / (1024*1024)" | bc; }
2gb() { echo "scale=2; $1 / (1024*1024*1024)" | bc; }
case "$s" in *) r=$(2$s "$i"); echo "$r" ;; esac
}
b2kb() { bcalc "$1" kb; } && b2mb() { bcalc "$1" mb; } && b2gb() { bcalc "$1" gb; }
install_gles() {
echo "\nInstalling gl4es...\n"
sed -i "4i export LD_LIBRARY_PATH=/usr/lib/gl4es" "$PROOT/home/$user/.config/fish/config.fish"
{
cat << EOF
git clone https://github.com/ptitSeb/gl4es && cd gl4es
mkdir build; cd build && cmake -S ../../gl4es; make install
EOF
} >> "$PROOT/tmp/install_gles.sh"
chmod +x "$PROOT/tmp/install_gles.sh"
pdsh "/tmp/install_gles.sh"
}
install_ohmyzsh() {
echo ""
{
cat << EOF
#!/usr/bin/env bash
ohmyzsh="\$HOME/.oh-my-zsh"
if cmd_exists zsh; then
if [ -d "$ohmyzsh" ]; then
if [ -d "$ohmyzsh/custom/themes/powerlevel10k" ]; then
if [ -d "$ohmyzsh/custom/plugins/zsh-autosuggestions" ]; then
if [ -d "/usr/share/fonts/0xProto" ]; then
echo "\nOh-my-zsh & powerlevel10k has been successfully installed.\n"
else
rm -r /usr/share/fonts/0xProto >/dev/null 2>&1
wget https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/0xProto.zip -P /usr/share/fonts
unzip /usr/share/fonts/0xProto.zip -d /usr/share/fonts/0xProto/
rm /usr/share/fonts/0xProto.zip
install_ohmyzsh
fi
else
git clone https://github.com/zsh-users/zsh-autosuggestions "$ohmyzsh/custom/plugins/zsh-autosuggestions"
sed -i 's/plugins=(\(git\))/plugins=(\n \1\n zsh-autosuggestions\n)/' "\$HOME/.zshrc"
install_ohmyzsh
fi
else
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$ohmyzsh/custom/themes/powerlevel10k"
sed -i 's/^ZSH_THEME=.*$/ZSH_THEME="powerlevel10k\/powerlevel10k"/' "\$HOME/.zshrc"
echo "alias ls='lsd'" >> "\$HOME/.zshrc"
install_ohmyzsh
fi
else
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
install_ohmyzsh
fi
else
sudo apt update
sudo apt install zsh lsd
zsh=$(which zsh) && chsh -s "$zsh"
install_ohmyzsh
fi
EOF
} > $PREFIX/tmp/install_ohmyzsh.sh
chmod +x $PREFIX/tmp/install_ohmyzsh.sh
#pdsh "/tmp/install_ohmyzsh.sh"
}
generate_wine_installer() {
{
cat << EOF
#!/usr/bin/env bash
set -e
add_source() {
printf "Adding Box86 and Box64 repo in sources.list \n"
wget https://ryanfortner.github.io/box64-debs/box64.list -O /etc/apt/sources.list.d/box64.list
wget -qO- https://ryanfortner.github.io/box64-debs/KEY.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/box64-debs-archive-keyring.gpg
wget https://ryanfortner.github.io/box86-debs/box86.list -O /etc/apt/sources.list.d/box86.list
wget -qO- https://ryanfortner.github.io/box86-debs/KEY.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/box86-debs-archive-keyring.gpg
printf "Adding ARMHF arch for Box86 \n"
dpkg --add-architecture armhf
}
echo -n "Add Box86 and Box64 repo to sources.list? [y/n] " && read i
case "\$i" in
y) add_source ;; *) ;;
esac
install_box() {
printf "Installing Box86 and Box64 packages \n"
apt update -y
sudo apt install -y box64-android libc6 libc6:armhf box86-android:armhf gnutls-bin
printf "Installing more packages necessary for Box86_64 and Wine86_64 \n"
# sudo apt install -y cabextract libfreetype6 libfreetype6:armhf libfontconfig libfontconfig:armhf libxext6 libxext6:armhf libxinerama-dev libxinerama-dev:armhf libxxf86vm1 libxxf86vm1:armhf libxrender1 libxrender1:armhf libxcomposite1 libxcomposite1:armhf libxrandr2 libxrandr2:armhf libxi6 libxi6:armhf libxcursor1 libxcursor1:armhf libvulkan-dev libvulkan-dev:armhf libgnutls30 libgnutls30:armhf libasound2:armhf libglib2.0-0:armhf libgphoto2-6:armhf libgphoto2-port12:armhf libgstreamer-plugins-base1.0-0:armhf libgstreamer1.0-0:armhf libldap-common libldap-common:armhf libopenal1 libopenal1:armhf libpcap0.8:armhf libpulse0 libpulse0:armhf libsane1:armhf libudev1:armhf libusb-1.0-0:armhf libvkd3d1:armhf libx11-6:armhf libasound2-plugins:armhf ocl-icd-libopencl1:armhf libncurses6:armhf libcap2-bin:armhf libcups2:armhf libdbus-1-3:armhf libfontconfig1:armhf libglu1-mesa:armhf libglu1:armhf libgssapi-krb5-2:armhf libkrb5-3:armhf libodbc2 libodbc2:armhf libosmesa6:armhf libsdl2-2.0-0:armhf libv4l-0:armhf libxfixes3:armhf libxinerama1:armhf
}
echo -n "Install Box86 and Box64 from apt? [y/n] " && read i
case "\$i" in
y) install_box ;; *) ;;
esac
dl_wine() {
version=8.7
printf "Downloading Wine %s x86 and x64 from Wine-Builds \n" "\$version"
wget "https://github.com/Kron4ek/Wine-Builds/releases/download/\$version/wine-\$version-x86.tar.xz" -P \$HOME/wine
wget "https://github.com/Kron4ek/Wine-Builds/releases/download/\$version/wine-\$version-amd64.tar.xz" -P \$HOME/wine64
printf "Unpacking Wine %s x86 to ~/wine and x86 to ~/wine64" "\$version"
tar -xvf "\$HOME/wine/wine-\$version-x86.tar.xz" -C \$HOME/wine
mv \$HOME/wine/wine-\$version-x86/* \$HOME/wine && rm -rf \$HOME/wine/wine-\$version-x86.tar.xz \$HOME/wine/wine-\$version-x86
tar -xvf "\$HOME/wine64/wine-\$version-amd64.tar.xz" -C \$HOME/wine64
mv \$HOME/wine64/wine-\$version-amd64/* \$HOME/wine64 && rm -rf \$HOME/wine64/wine-\$version-amd64.tar.xz \$HOME/wine64/wine-\$version-amd64
}
echo -n "Download wine & install to ~/wine/ & ~/wine64/ ? [y/n] " && read i
case "\$i" in
y) dl_wine ;; *) ;;
esac
add_box_paths() {
printf "Adding necessary BOX paths inside ~/.bashrc \n"
sed -i "4i export BOX86_PATH=\$HOME/wine/bin/" "\$HOME/.bashrc"
sed -i "4i export BOX86_LD_LIBRARY_PATH=\$HOME/wine/lib/wine/i386-unix/:/lib/i386-linux-gnu/:/lib/aarch64-linux-gnu/:/lib/arm-linux-gnueabihf/:/usr/lib/aarch64-linux-gnu/:/usr/lib/arm-linux-gnueabihf/:/usr/lib/i386-linux-gnu/" "\$HOME/.bashrc"
sed -i "4i export BOX64_PATH=\$HOME/wine64/bin/" "\$HOME/.bashrc"
sed -i "4i export BOX64_LD_LIBRARY_PATH=\$HOME/wine64/lib/i386-unix/:\$HOME/wine64/lib/wine/x86_64-unix/:/lib/i386-linux-gnu/:/lib/x86_64-linux-gnu:/lib/aarch64-linux-gnu/:/lib/arm-linux-gnueabihf/:/usr/lib/aarch64-linux-gnu/:/usr/lib/arm-linux-gnueabihf/:/usr/lib/i386-linux-gnu/:/usr/lib/x86_64-linux-gnu" "\$HOME/.bashrc"
source \$HOME/.bashrc
}
echo -n "Add BOX paths to \$HOME/.bashrc ? [y/n] " && read i
case "\$i" in
y) add_box_paths ;; *) ;;
esac
create_wine_shortcuts() {
printf "Creating shortcuts for wine with box. \nYou can use Wine x86 using the 'wine' command and Wine x64 using the 'wine64' \n"
echo '#!/bin/bash
export WINEPREFIX=\$HOME/.wine32
box64 '\"\$HOME/wine64/bin/wine \" '"\$@"' > /usr/local/bin/wine
chmod +x /usr/local/bin/wine
echo '#!/bin/bash
export WINEPREFIX=\$HOME/.wine64
box64 '\"\$HOME/wine64/bin/wine64 \" '"\$@"' > /usr/local/bin/wine64
chmod +x /usr/local/bin/wine64
}
echo -n "Create wine shortcuts? [y/n] " && read i
case "\$i" in
y) create_wine_shortcuts ;; *) ;;
esac
create_wine_prefix() {
printf "Creating wine prefix for x86 and x64 version to ~/.wine32 and ~/.wine64 \n"
wine wineboot
wine64 wineboot
}
echo -n "Create wine prefixes? [y/n] " && read i
case "\$i" in
y) create_wine_prefix ;; *) ;;
esac
install_winetricks() {
printf "Installing winetricks \n"
wget https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks -P \$HOME/wine
chmod +x winetricks
mv winetricks /usr/local/bin/
}
echo -n "Install winetricks? [y/n] " && read i
case "\$i" in
y) install_winetricks ;; *) ;;
esac
create_winetricks_shortcuts() {
printf "Creating shortcuts for the winetricks \nYou can use Winetricks for Wine x86 by using the 'winetricks32' command and Winetricks for Wine x64 using the 'winetricks64' command. \n"
echo '#!/bin/bash
export BOX86_NOBANNER=1 WINE=wine WINEPREFIX=\$HOME/.wine32 WINESERVER=\$HOME/wine/bin/wineserver
wine '\"/usr/local/bin/winetricks \" '"\$@"' > /usr/local/bin/winetricks32
chmod +x /usr/local/bin/winetricks32
echo '#!/bin/bash
export BOX64_NOBANNER=1 WINE=wine64 WINEPREFIX=\$HOME/.wine64 WINESERVER=\$HOME/wine64/bin/wineserver
wine64 '\"/usr/local/bin/winetricks \" '"\$@"' > /usr/local/bin/winetricks64
chmod +x /usr/local/bin/winetricks64
}
echo -n "Create winetricks shortcuts? [y/n] " && read i
case "\$i" in
y) create_winetricks_shortcuts ;; *) ;;
esac
create_desktop_shortcuts() {
printf "Adding desktop shortcuts for wine \n"
echo '[Desktop Entry]
Name=Wine32 Explorer
Exec=bash -c \"wine explorer\"
Icon=wine
Type=Application' > \$HOME/Desktop/Wine32_Explorer.desktop
chmod +x \$HOME/Desktop/Wine32_Explorer.desktop
cp \$HOME/Desktop/Wine32_Explorer.desktop /usr/share/applications/
echo '[Desktop Entry]
Name=Wine64 Explorer
Exec=bash -c \"wine64 explorer\"
Icon=wine
Type=Application' > \$HOME/Desktop/Wine64_Explorer.desktop
chmod +x \$HOME/Desktop/Wine64_Explorer.desktop
cp \$HOME/Desktop/Wine64_Explorer.desktop /usr/share/applications/
echo '[Desktop Entry]
Name=Winetricks32 Explorer
Exec=bash -c \"winetricks32 --gui\"
Icon=wine
Type=Application' > \$HOME/Desktop/Winetricks32_gui.desktop
chmod +x \$HOME/Desktop/Winetricks32_gui.desktop
cp \$HOME/Desktop/Winetricks32_gui.desktop /usr/share/applications/
echo '[Desktop Entry]
Name=Winetricks64 Explorer
Exec=bash -c \"winetricks64 --gui\"
Icon=wine
Type=Application' > \$HOME/Desktop/Winetricks64_gui.desktop
chmod +x \$HOME/Desktop/Winetricks64_gui.desktop
cp \$HOME/Desktop/Winetricks64_gui.desktop /usr/share/applications/
echo '[Desktop Entry]
Name=GL2Mark software
Exec=bash -c \"env MESA_GL_VERSION_OVERRIDE=4.5COMPAT glmark2\"
Icon=gl2mark
Terminal=true
Type=Application' > \$HOME/Desktop/GL2Mark_llvmpipe.desktop
chmod +x \$HOME/Desktop/GL2Mark_llvmpipe.desktop
echo '[Desktop Entry]
Name=GL2Mark virpipe
Exec=bash -c \"env MESA_GL_VERSION_OVERRIDE=4.5COMPAT GALLIUM_DRIVER=virpipe glmark2\"
Icon=gl2mark
Terminal=true
Type=Application' > \$HOME/Desktop/GL2Mark_virpipe.desktop
chmod +x \$HOME/Desktop/GL2Mark_virpipe.desktop
}
echo -n "Create desktop shortcuts? [y/n] " && read i
case "\$i" in
y) create_desktop_shortcuts ;; *) ;;
esac
install_zenity() {
printf "Installing zenity\n"
sudo apt install -y zenity
}
echo -n "Install zenity? [y/n] " && read i
case "\$i" in
y) install_zenity ;; *) ;;
esac
exit 0
EOF
} > $PREFIX/tmp/install_wine.sh
chmod +x $PREFIX/tmp/install_wine.sh
# pdsh "/tmp/install_wine.sh"
}
metadata() {
refresh_sizes() { silence rm -f $TMP_FILE1 $LOG_FILE
find ./extracted -maxdepth 1 -name "*.img" -printf "%f %s\n" | sort -u >> $TMP_FILE1
supertotal=$(stat -c '%s' ./super.img)
imgtotal=$(find ./extracted -maxdepth 1 -name "*.img" -exec stat -c '%s' {} + | awk '{sum += $1} END {print sum}')
echo -e "\nTotal Image Size: $imgtotal\nOverall Super Size: $supertotal\n" >> $TMP_FILE1
$lpdump >> $TMP_FILE1
}
refresh_sizes
## functions that parse $TMP_FILE1 at certain coordinance for variable values
size() { x="$1" && stat -c '%s' "$x" ; }
parse() { x="$1"; y="$2" && echo "$x" | awk -v z="$y" '{print $z}' ; }
sanitize() { grep -v '^[-]*$' | sed 's/^ *//' | paste -sd ' ' - | sed -e 's/:$//' -e 's/^(/ /' ; }
attributes() { x="$1" && grep -e "Name: $x" -A2 "$TMP_FILE1" | sed -e '1,2d' -e 's/^ //' | awk '{print $2}' ; }
extents() { x="$1" && grep -e "Name: $x" -A4 "$TMP_FILE1" | sed -e '1,4d' -e 's/^ //' ; }
image_group() { x="$1" && grep -E "Partition table:" -A16 "$TMP_FILE1" | grep -e "Name: $x" -A4 ; }
group_info() { x="$1" && grep -E "Group table:" -A16 "$TMP_FILE1" | grep -e "Name: $x" -A2 | sanitize ; }
## Calculate total size of all partitions inside super.img including super
[ -f "./super.img" ] && {
SUPER_PARTITION_NAME=$(grep "Partition name:" $TMP_FILE1 | sed -e 's/^ //' | awk '{print $3}')
SUPER_SIZE=$(grep -e "Overall Super Size: " $TMP_FILE1 | awk '{print $4}')
SUPER_TOTAL_MB=$(b2mb "$SUPER_SIZE") ; SUPER_TOTAL_GB=$(b2gb "$SUPER_SIZE")
SUPER_LAYOUT=$(x="$1" && grep -e "super:" $TMP_FILE1 | sed 's/^super: //' | grep -e "$x")
IMAGE_SIZE_TOTAL=$(grep -e "Total Image Size: " $TMP_FILE1 | awk '{print $4}')
IMAGE_SIZE_TOTAL_MB=$(b2mb "$IMAGE_SIZE_TOTAL") ; IMAGE_SIZE_TOTAL_GB=$(b2gb "$IMAGE_SIZE_TOTAL")
METADATA_VERSION=$(grep -e "Metadata version: " $TMP_FILE1 | awk '{print $3}')
METADATA_SIZE=$(grep -e "Metadata size: " $TMP_FILE1 | awk '{print $3}')
METADATA_MAX_SIZE=$(grep -e "Metadata max size: " $TMP_FILE1 | awk '{print $4}')
METADATA_SLOT_COUNT=$(grep -e "Metadata slot count: " $TMP_FILE1 | awk '{print $4}')
HEADER_FLAGS=$(grep -e "Header flags: " $TMP_FILE1 | awk '{print $3}')
BLOCK_DEVICE_TABLE=$(grep -e "Block device table:" -A5 $TMP_FILE1 | sed '1,2d')
}
[ -f "./extracted/product_a.img" ] && {
PRODUCT_A_NAME="product_a"
PRODUCT_A_SIZE=$(size "./extracted/product_a.img" || echo "0")
PRODUCT_A_SIZE_MB=$(b2mb "$PRODUCT_A_SIZE") ; PRODUCT_A_SIZE_GB=$(b2gb "$PRODUCT_A_SIZE")
PRODUCT_A_ATTRIBUTES=$(a() { [ -z "$(attributes product_a)" ] && {echo "none"} ; } && a || echo "none") ; PRODUCT_A_EXTENTS=$(extents "product_a")
PRODUCT_A_LAYOUT=$(echo "$SUPER_LAYOUT" | grep "product_a" || echo "0")
PRODUCT_A_SECTOR_BEGIN=$(parse "$PRODUCT_A_LAYOUT" 1)
PRODUCT_A_SECTOR_FINISH=$(parse "$PRODUCT_A_LAYOUT" 3 | sanitize)
PRODUCT_A_SECTOR_SIZE=$(parse "$PRODUCT_A_LAYOUT" 5 | sanitize)
PRODUCT_A_GROUP_NAME=$(a() { [ -z "$(image_group product_a | sed '1d;3,5d' | awk '{print $2}')" ] && {echo "main_a"} ; } && a || echo "main_a")
PRODUCT_B_NAME="product_b"
PRODUCT_B_SIZE=$(size "./extracted/product_b.img" || echo "0")
PRODUCT_B_SIZE_MB=$(b2mb "$PRODUCT_B_SIZE") ; PRODUCT_B_SIZE_GB=$(b2gb "$PRODUCT_B_SIZE")
PRODUCT_B_ATTRIBUTES=$(a() { [ -z "$(attributes product_b)" ] && {echo "none"} ; } && a || echo "none") ; PRODUCT_B_EXTENTS=$(extents "product_b")
PRODUCT_B_LAYOUT=$(echo "$SUPER_LAYOUT" | grep "product_b" || echo "0")
PRODUCT_B_SECTOR_BEGIN=$(parse "$PRODUCT_B_LAYOUT" 1)
PRODUCT_B_SECTOR_FINISH=$(parse "$PRODUCT_B_LAYOUT" 3 | sanitize)
PRODUCT_B_SECTOR_SIZE=$(parse "$PRODUCT_B_LAYOUT" 5 | sanitize)
PRODUCT_B_GROUP_NAME=$(a() { [ -z "$(image_group product_b | sed '1d;3,5d' | awk '{print $2}')" ] && {echo "main_b"} ; } && a || echo "main_b")
PRODUCT_TOTAL_SIZE=$(echo "$PRODUCT_A_SIZE + $PRODUCT_B_SIZE" | bc)
PRODUCT_TOTAL_MB=$(b2mb "$PRODUCT_TOTAL_SIZE") ; PRODUCT_TOTAL_GB=$(b2gb "$PRODUCT_TOTAL_SIZE")
}
[ -f "./extracted/system_a.img" ] && {
SYSTEM_A_NAME="system_a"
SYSTEM_A_SIZE=$(size "./extracted/system_a.img" || echo "0")
SYSTEM_A_SIZE_MB=$(b2mb "$SYSTEM_A_SIZE") ; SYSTEM_A_SIZE_GB=$(b2gb "$SYSTEM_A_SIZE")
SYSTEM_A_ATTRIBUTES=$(a() { [ -z "$(attributes system_a)" ] && {echo "none"} ; } && a || echo "none") ; SYSTEM_A_EXTENTS=$(extents "system_a" || echo "0")
SYSTEM_A_LAYOUT=$(echo "$SUPER_LAYOUT" | grep "system_a" || echo "0")
SYSTEM_A_SECTOR_BEGIN=$(parse "$SYSTEM_A_LAYOUT" 1)
SYSTEM_A_SECTOR_FINISH=$(parse "$SYSTEM_A_LAYOUT" 3 | sanitize)
SYSTEM_A_SECTOR_SIZE=$(parse "$SYSTEM_A_LAYOUT" 5 | sanitize)
SYSTEM_A_GROUP_NAME=$(a() { [ -z "$(image_group system_a | sed '1d;3,5d' | awk '{print $2}')" ] && {echo "main_a"} ; } && a || echo "main_a")
SYSTEM_B_NAME="system_b"
SYSTEM_B_SIZE=$(size "./extracted/system_b.img" || echo "0")
SYSTEM_B_SIZE_MB=$(b2mb "$SYSTEM_B_SIZE") ; SYSTEM_B_SIZE_GB=$(b2gb "$SYSTEM_B_SIZE")
SYSTEM_B_ATTRIBUTES=$(a() { [ -z "$(attributes system_b)" ] && {echo "none"} ; } && a || echo "none") ; SYSTEM_B_EXTENTS=$(extents "system_b" || echo "0")
SYSTEM_B_LAYOUT=$(echo "$SUPER_LAYOUT" | grep "system_b" || echo "0")
SYSTEM_B_SECTOR_BEGIN=$(parse "$SYSTEM_B_LAYOUT" 1 )
SYSTEM_B_SECTOR_FINISH=$(parse "$SYSTEM_B_LAYOUT" 3 | sanitize)
SYSTEM_B_SECTOR_SIZE=$(parse "$SYSTEM_B_LAYOUT" 5 | sanitize)
SYSTEM_B_GROUP_NAME=$(a() { [ -z "$(image_group system_b | sed '1d;3,5d' | awk '{print $2}')" ] && {echo "main_b"} ; } && a || echo "main_b")
SYSTEM_TOTAL_SIZE=$(echo "$SYSTEM_A_SIZE + $SYSTEM_B_SIZE" | bc)
SYSTEM_TOTAL_MB=$(b2mb "$SYSTEM_TOTAL_SIZE") ; SYSTEM_TOTAL_GB=$(b2gb "$SYSTEM_TOTAL_SIZE")
}
[ -f "./extracted/vendor_a.img" ] && {
VENDOR_A_NAME="vendor_a"
VENDOR_A_SIZE=$(size "./extracted/vendor_a.img" || echo "0")
VENDOR_A_SIZE_MB=$(b2mb "$VENDOR_A_SIZE") ; VENDOR_A_SIZE_GB=$(b2gb "$VENDOR_A_SIZE")
VENDOR_A_ATTRIBUTES=$(a() { [ -z "$(attributes vendor_a)" ] && {echo "none"} ; } && a || echo "none") ; VENDOR_A_EXTENTS=$(extents "vendor_a" || echo "0")
VENDOR_A_LAYOUT=$(echo "$SUPER_LAYOUT" | grep "vendor_a" || echo "0")
VENDOR_A_SECTOR_BEGIN=$(parse "$VENDOR_A_LAYOUT" 1 )
VENDOR_A_SECTOR_FINISH=$(parse "$VENDOR_A_LAYOUT" 3 | sanitize)
VENDOR_A_SECTOR_SIZE=$(parse "$VENDOR_A_LAYOUT" 5 | sanitize)
VENDOR_A_GROUP_NAME=$(a() { [ -z "$(image_group vendor_a | sed '1d;3,5d' | awk '{print $2}')" ] && {echo "main_a"} ; } && a || echo "main_a")
VENDOR_B_NAME="vendor_b"
VENDOR_B_SIZE=$(size "./extracted/vendor_b.img" || echo "0")
VENDOR_B_SIZE_MB=$(b2mb "$VENDOR_B_SIZE") ; VENDOR_B_SIZE_GB=$(b2gb "$VENDOR_B_SIZE")
VENDOR_B_ATTRIBUTES=$(a() { [ -z "$(attributes vendor_b)" ] && {echo "none"} ; } && a || echo "none") ; VENDOR_B_EXTENTS=$(extents "vendor_b" || echo "0")
VENDOR_B_LAYOUT=$(echo "$SUPER_LAYOUT" | grep "vendor_b" || echo "0")
VENDOR_B_SECTOR_BEGIN=$(parse "$VENDOR_B_LAYOUT" 1)
VENDOR_B_SECTOR_FINISH=$(parse "$VENDOR_B_LAYOUT" 3 | sanitize)
VENDOR_B_SECTOR_SIZE=$(parse "$VENDOR_B_LAYOUT" 5 | sanitize)
VENDOR_B_GROUP_NAME=$(a() { [ -z "$(image_group vendor_b | sed '1d;3,5d' | awk '{print $2}')" ] && {echo "main_b"} ; } && a || echo "main_b")
VENDOR_TOTAL_SIZE=$(echo "$VENDOR_A_SIZE + $VENDOR_B_SIZE" | bc)
VENDOR_TOTAL_MB=$(b2mb "$VENDOR_TOTAL_SIZE") ; VENDOR_TOTAL_GB=$(b2gb "$VENDOR_TOTAL_SIZE")
}
[ -f "./extracted/product_a.img" ] && [ -f "./extracted/system_a.img" ] && [ -f "./extracted/vendor_a.img" ] && {
MAIN_A_TOTAL_SIZE=$(echo "$PRODUCT_A_SIZE + $SYSTEM_A_SIZE + $VENDOR_A_SIZE" | bc || echo "0")
MAIN_A_TOTAL_MB=$(b2mb "$MAIN_A_TOTAL_SIZE") ; MAIN_A_TOTAL_GB=$(b2gb "$MAIN_A_TOTAL_SIZE")
MAIN_A_MAX_SIZE=$(group_info "main_a" | awk '{print $5}') ; MAIN_A_MAX_MB=$(b2mb "$MAIN_A_MAX_SIZE")
MAIN_A_MAX_GB=$(b2gb "$MAIN_A_MAX_SIZE") ; MAIN_A_FLAGS=$(group_info "main_a" | awk '{print $8}')
MAIN_B_TOTAL_SIZE=$(echo "$PRODUCT_B_SIZE + $SYSTEM_B_SIZE + $VENDOR_B_SIZE" | bc || echo "0")
MAIN_B_TOTAL_MB=$(b2mb "$MAIN_B_TOTAL_SIZE") ; MAIN_B_TOTAL_GB=$(b2gb "$MAIN_B_TOTAL_SIZE")
MAIN_B_MAX_SIZE=$(group_info "main_b" | awk '{print $5}') ; MAIN_B_MAX_MB=$(b2mb "$MAIN_B_MAX_SIZE")
MAIN_B_MAX_GB=$(b2gb "$MAIN_B_MAX_SIZE") MAIN_B_FLAGS=$(group_info "main_b" | awk '{print $8}')
}
}
dump_log() {
silence metadata
silence rm -f $LOG_FILE
{
cat << EOF
$(ascii_box "Super Partition Table:")
* Name: $PRODUCT_A_NAME
Group: $PRODUCT_A_GROUP_NAME
Attributes: $PRODUCT_A_ATTRIBUTES
Size: $PRODUCT_A_SIZE B
$PRODUCT_A_SIZE_MB MB
$PRODUCT_A_SIZE_GB GB
Extents:
$PRODUCT_A_EXTENTS
* Name: $PRODUCT_B_NAME
Group: $PRODUCT_B_GROUP_NAME
Attributes: $PRODUCT_B_ATTRIBUTES
Size: $PRODUCT_B_SIZE B
$PRODUCT_B_SIZE_MB MB
$PRODUCT_B_SIZE_GB GB
Extents:
$PRODUCT_B_EXTENTS
* Product Total: $PRODUCT_TOTAL_SIZE B
$PRODUCT_TOTAL_MB MB
$PRODUCT_TOTAL_GB GB
* Name: $SYSTEM_A_NAME
Group: $SYSTEM_A_GROUP_NAME
Attributes: $SYSTEM_A_ATTRIBUTES
Size: $SYSTEM_A_SIZE B
$SYSTEM_A_SIZE_MB MB
$SYSTEM_A_SIZE_GB GB
Extents:
$SYSTEM_A_EXTENTS
* Name: $SYSTEM_B_NAME
Group: $SYSTEM_B_GROUP_NAME
Attributes: $SYSTEM_B_ATTRIBUTES
Size: $SYSTEM_B_SIZE B
$SYSTEM_B_SIZE_MB MB
$SYSTEM_B_SIZE_GB GB
Extents:
$SYSTEM_B_EXTENTS
* System Total: $SYSTEM_TOTAL_SIZE B
$SYSTEM_TOTAL_MB MB
$SYSTEM_TOTAL_GB GB
* Name: $VENDOR_A_NAME
Group: $VENDOR_A_GROUP_NAME
Attributes: $VENDOR_A_ATTRIBUTES
Size: $VENDOR_A_SIZE B
$VENDOR_A_SIZE_MB MB
$VENDOR_A_SIZE_GB GB
Extents:
$VENDOR_A_EXTENTS
* Name: $VENDOR_B_NAME
Group: $VENDOR_B_GROUP_NAME
Attributes: $VENDOR_B_ATTRIBUTES
Size: $VENDOR_B_SIZE B
$VENDOR_B_SIZE_MB MB
$VENDOR_B_SIZE_GB GB
Extents:
$VENDOR_B_EXTENTS
* Vendor Total: $VENDOR_TOTAL_SIZE B
$VENDOR_TOTAL_MB MB
$VENDOR_TOTAL_GB GB
$(ascii_box "Group Table Information:")
* Name: $GROUP_DEFAULT_NAME
Maximum size: $GROUP_DEFAULT_MAX_SIZE B
Flags: $GROUP_DEFAULT_FLAGS
* Name: main_a
Current size: $MAIN_A_TOTAL_SIZE B
Maximum size: $MAIN_A_MAX_SIZE B
Flags: $MAIN_A_FLAGS
* Name: main_b
Current size: $MAIN_B_TOTAL_SIZE B
Maximum size: $MAIN_B_MAX_SIZE B
Flags: $MAIN_B_FLAGS
$(ascii_box "Block device table:")
$BLOCK_DEVICE_TABLE
$(ascii_box "Super Layout:")
$SUPER_LAYOUT
$(ascii_box "Super Overview:")
$SUPER_PARTITION_NAME max size: $SUPER_SIZE B $SUPER_TOTAL_MB MB $SUPER_TOTAL_GB GB
Image sizes: $IMAGE_SIZE_TOTAL B $IMAGE_SIZE_TOTAL_MB MB $IMAGE_SIZE_TOTAL_GB GB
main_a: $MAIN_A_TOTAL_SIZE B $MAIN_A_TOTAL_MB MB $MAIN_A_TOTAL_GB GB
|
|_$PRODUCT_A_NAME: $PRODUCT_A_SIZE B $PRODUCT_A_SIZE_MB MB $PRODUCT_A_SIZE_GB GB
|_$SYSTEM_A_NAME: $SYSTEM_A_SIZE B $SYSTEM_A_SIZE_MB MB $SYSTEM_A_SIZE_GB GB
|_$VENDOR_A_NAME: $VENDOR_A_SIZE B $VENDOR_A_SIZE_MB MB $VENDOR_A_SIZE_GB GB
main_b: $MAIN_B_TOTAL_SIZE B $MAIN_B_TOTAL_MB MB $MAIN_B_TOTAL_GB GB
|
|_$PRODUCT_B_NAME: $PRODUCT_B_SIZE B $PRODUCT_B_SIZE_MB MB $PRODUCT_B_SIZE_GB GB
|_$SYSTEM_B_NAME: $SYSTEM_B_SIZE B $SYSTEM_B_SIZE_MB MB $SYSTEM_B_SIZE_GB GB
|_$VENDOR_B_NAME: $VENDOR_B_SIZE B $VENDOR_B_SIZE_MB MB $VENDOR_B_SIZE_GB GB
$(ascii_box "lpmake command")
lpmake \
--metadata-size $METADATA_MAX_SIZE \
--super-name=$SUPER_PARTITION_NAME \
--device-size=$SUPER_SIZE \
--metadata-slots=$METADATA_SLOT_COUNT \
--group=main_a:$MAIN_A_TOTAL_SIZE \
--group=main_b:$MAIN_B_TOTAL_SIZE \
--image=$PRODUCT_A_NAME=./extracted/$PRODUCT_A_NAME.img \
--partition=$PRODUCT_A_NAME:$PRODUCT_A_ATTRIBUTES:$PRODUCT_A_SIZE:$PRODUCT_A_GROUP_NAME \
--image=$PRODUCT_B_NAME=./extracted/$PRODUCT_B_NAME.img \
--partition=$PRODUCT_B_NAME:$PRODUCT_B_ATTRIBUTES:$PRODUCT_B_SIZE:$PRODUCT_B_GROUP_NAME \
--image=$SYSTEM_A_NAME=./extracted/$SYSTEM_A_NAME.img \
--partition=$SYSTEM_A_NAME:$SYSTEM_A_ATTRIBUTES:$SYSTEM_A_SIZE:$SYSTEM_A_GROUP_NAME \
--image=$SYSTEM_B_NAME=./extracted/$SYSTEM_B_NAME.img \
--partition=$SYSTEM_B_NAME:$SYSTEM_B_ATTRIBUTES:$SYSTEM_B_SIZE:$SYSTEM_B_GROUP_NAME \
--image=$VENDOR_A_NAME=./extracted/$VENDOR_A_NAME.img \
--partition=$VENDOR_A_NAME:$VENDOR_A_ATTRIBUTES:$VENDOR_A_SIZE:$VENDOR_A_GROUP_NAME \
--image=$VENDOR_B_NAME=./extracted/$VENDOR_B_NAME.img \
--partition=$VENDOR_B_NAME:$VENDOR_B_ATTRIBUTES:$VENDOR_B_SIZE:$VENDOR_B_GROUP_NAME \
--virtual-ab \
--sparse \
--output ./out/new_super$HASHSTAMP.img
EOF
} >> $LOG_FILE
return 0
}
dump_variables() {
dump_log && echo "$(ascii_box "Useful Variables")\n" >> $LOG_FILE
sed -n 's/[^ ]*=[^ ]*/\n&\n/gp' $SCRIPT_NAME | grep '=' | \
awk -F'=' '{gsub(/[^A-Z_]/, "", $1); if ($1 != "") print $1}' | \
sed 's/\($F\|NR\)//g' | sort -u | head -n -1 | \
sed -e '3d' -e '/^F$/d' -e '/^IFS/d' -e '/^LP/d' -e '/^L/d' >> $TMP_FILE2
while IFS= read -r var_name; do
[ -n "$var_name" ] && [ "${var_name#\#}" = "$var_name" ] && { var_value=$(eval echo "\$$var_name") ; output+="$var_name=$var_value\n" ; }
done < $TMP_FILE2
[ -n "$output" ] && { echo -e "$output" | grep -v "^_=" >> $LOG_FILE ; }
rm -f $TMP_FILE2 && cat $LOG_FILE && return 0
}
calculate_hash() {
compare_hashes() {
find_hash_file() { HASH_FILE=".previous_hash" ; [ -f "$HASH_FILE" ] && { previous_log=$(cat "$HASH_FILE") ; return 0 ; } || echo "\nNo previous hash found. This might be the first run." ; }
find_log_file() { [ ! -f "$LOG_FILE" ] && { echo "Generating hashes...\n" && touch "$LOG_FILE" ; return 0 ; } ; }
hash_changed() { DISPLAY_HASH=$(echo "Current hash: $current_hash | Previous hash: $previous_log") ; }
calculate_hash() { current_hash=$($sha256sum "$LOG_FILE" | awk '{print substr($1, 1, 7)}') ; [ "$current_hash" != "$previous_log" ] && { hash_changed ; return 0 ; } || DISPLAY_HASH=$(echo "Current hash: $current_hash | Previous hash: $previous_log") ; }
find_hash_file ; find_log_file ; calculate_hash
}
compare_hashes && echo "$current_hash" > "$HASH_FILE" && HASHSTAMP=$(echo _$current_hash)
}