-
Notifications
You must be signed in to change notification settings - Fork 31
/
distro-container-setup
executable file
·1296 lines (1197 loc) · 47.5 KB
/
distro-container-setup
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
#!/data/data/com.termux/files/usr/bin/bash
function setup_distro() {
if [[ "$distro_answer" == "1" ]]; then
selected_distro="debian"
elif [[ "$distro_answer" == "2" ]]; then
selected_distro="ubuntu"
elif [[ "$distro_answer" == "3" ]]; then
selected_distro="archlinux"
elif [[ "$distro_answer" == "4" ]]; then
selected_distro="alpine"
elif [[ "$distro_answer" == "5" ]]; then
selected_distro="fedora"
else
selected_distro="debian"
fi
echo "selected_distro=\"$selected_distro\"" >> $config_file
banner
echo "${R}[${W}-${R}]${G}${BOLD}Installing ${C}proot-distro"${W}
echo
update_sys
package_install_and_check "proot-distro"
banner
echo "${R}[${W}-${R}]${G}${BOLD}Setup Selected Distro: ${C}${selected_distro}"${W}
echo
pd install $selected_distro
distro_path="$PREFIX/var/lib/proot-distro/installed-rootfs/$selected_distro"
}
#########################################################################
#
# Fix Sound Issue
#
#########################################################################
function distro_fix_sound_issue() {
banner
echo "${R}[${W}-${R}]${G}${BOLD}Fixing Proot Distro Sound Problem..."${W}
echo
echo "export PULSE_SERVER=127.0.0.1" >> "$distro_path/etc/profile"
cat <<EOF > "$HOME/.pd-sound-service"
pulseaudio --start --exit-idle-time=-1
pacmd load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1
EOF
}
#########################################################################
#
# Update Distro | Install Required Packages | Add User
#
#########################################################################
function pd_package_install_and_check() {
packs_list=($@)
#get distro id
if [ -f /etc/os-release ]; then
. /etc/os-release
fi
#instll package
for package_name in "${packs_list[@]}"; do
echo "${R}[${W}-${R}]${G}${BOLD} Installing package: ${C}$package_name ${W}"
if [[ "$ID" == "debian" ]] || [[ "$ID" == "ubuntu" ]]; then
sudo apt install "$package_name" -y
elif [[ "$ID" == arch* ]]; then
sudo pacman -Sy --noconfirm "$package_name"
elif [[ "$ID" == "alpine" ]]; then
sudo apk add "$package_name"
elif [[ "$ID" == "fedora" ]]; then
sudo dnf install "$package_name" -y
fi
#handel error in installation
if [ $? -ne 0 ]; then
echo "${R}[${W}-${R}]${G}${BOLD} Error detected during installation of: ${C}$package_name ${W}"
if [[ "$ID" == "debian" ]] || [[ "$ID" == "ubuntu" ]]; then
sudo apt --fix-broken install -y
sudo dpkg --configure -a
sudo apt install "$package_name" -y
elif [[ "$ID" == arch* ]]; then
sudo pacman -Syu --noconfirm
sudo pacman -Sy --noconfirm "$package_name"
elif [[ "$ID" == "alpine" ]]; then
sudo apk fix
sudo apk add "$package_name"
elif [[ "$ID" == "fedora" ]]; then
sudo dnf --refresh install -y
sudo rpm --rebuilddb
sudo dnf install "$package_name" -y
fi
fi
#reinstall
if [[ "$ID" == "debian" ]] || [[ "$ID" == "ubuntu" ]]; then
if ! dpkg -s "$package_name" >/dev/null 2>&1; then
sudo apt install "$package_name" -y
fi
elif [[ "$ID" == arch* ]]; then
if ! pacman -Qi "$package_name" >/dev/null 2>&1; then
sudo pacman -Sy --noconfirm "$package_name"
fi
elif [[ "$ID" == "alpine" ]]; then
if ! apk info -e "$package_name"; then
sudo apk add "$package_name"
fi
elif [[ "$ID" == "fedora" ]]; then
if ! rpm -q "$package_name" >/dev/null 2>&1; then
sudo dnf install "$package_name" -y
fi
fi
#check installation
if [[ "$ID" == "debian" ]] || [[ "$ID" == "ubuntu" ]]; then
if dpkg -s "$package_name" >/dev/null 2>&1; then
echo "${R}[${W}-${R}]${G} $package_name installed successfully ${W}"
else
if type -p "$package_name" &>/dev/null || [ -e "$PREFIX/bin/$package_name"* ] || [ -e "$PREFIX/bin/"*"$package_name" ]; then
echo "${R}[${W}-${R}]${C} $package_name ${G}installed successfully ${W}"
fi
fi
elif [[ "$ID" == arch* ]]; then
if pacman -Qi "$package_name" >/dev/null 2>&1; then
echo "${R}[${W}-${R}]${G} $package_name installed successfully ${W}"
else
if type -p "$package_name" &>/dev/null || [ -e "$PREFIX/bin/$package_name"* ] || [ -e "$PREFIX/bin/"*"$package_name" ]; then
echo "${R}[${W}-${R}]${C} $package_name ${G}installed successfully ${W}"
fi
fi
elif [[ "$ID" == "alpine" ]]; then
if apk info -e "$package_name"; then
echo "${R}[${W}-${R}]${G} $package_name installed successfully ${W}"
else
if type -p "$package_name" &>/dev/null || [ -e "$PREFIX/bin/$package_name"* ] || [ -e "$PREFIX/bin/"*"$package_name" ]; then
echo "${R}[${W}-${R}]${C} $package_name ${G}installed successfully ${W}"
fi
fi
elif [[ "$ID" == "fedora" ]]; then
if rpm -q "$package_name" >/dev/null 2>&1; then
echo "${R}[${W}-${R}]${G} $package_name installed successfully ${W}"
else
if type -p "$package_name" &>/dev/null || [ -e "$PREFIX/bin/$package_name"* ] || [ -e "$PREFIX/bin/"*"$package_name" ]; then
echo "${R}[${W}-${R}]${C} $package_name ${G}installed successfully ${W}"
fi
fi
fi
done
echo ""
}
function pd_root_package_install_and_check() {
packs_list=($@)
#get distro id
if [ -f /etc/os-release ]; then
. /etc/os-release
fi
#instll package
for package_name in "${packs_list[@]}"; do
echo "${R}[${W}-${R}]${G}${BOLD} Installing package: ${C}$package_name ${W}"
if [[ "$ID" == "debian" ]] || [[ "$ID" == "ubuntu" ]]; then
apt install "$package_name" -y
elif [[ "$ID" == arch* ]]; then
pacman -Sy --noconfirm "$package_name"
elif [[ "$ID" == "alpine" ]]; then
apk add "$package_name"
elif [[ "$ID" == "fedora" ]]; then
dnf install "$package_name" -y
fi
#handel error in installation
if [ $? -ne 0 ]; then
echo "${R}[${W}-${R}]${G}${BOLD} Error detected during installation of: ${C}$package_name ${W}"
if [[ "$ID" == "debian" ]] || [[ "$ID" == "ubuntu" ]]; then
apt --fix-broken install -y
dpkg --configure -a
apt install "$package_name" -y
elif [[ "$ID" == arch* ]]; then
pacman -Syu --noconfirm
pacman -Sy --noconfirm "$package_name"
elif [[ "$ID" == "alpine" ]]; then
apk fix
apk add "$package_name"
elif [[ "$ID" == "fedora" ]]; then
dnf --refresh install -y
rpm --rebuilddb
dnf install "$package_name" -y
fi
fi
#reinstall
if [[ "$ID" == "debian" ]] || [[ "$ID" == "ubuntu" ]]; then
if ! dpkg -s "$package_name" >/dev/null 2>&1; then
apt install "$package_name" -y
fi
elif [[ "$ID" == arch* ]]; then
if ! pacman -Qi "$package_name" >/dev/null 2>&1; then
pacman -Sy --noconfirm "$package_name"
fi
elif [[ "$ID" == "alpine" ]]; then
if ! apk info -e "$package_name"; then
apk add "$package_name"
fi
elif [[ "$ID" == "fedora" ]]; then
if ! rpm -q "$package_name" >/dev/null 2>&1; then
dnf install "$package_name" -y
fi
fi
#check installation
if [[ "$ID" == "debian" ]] || [[ "$ID" == "ubuntu" ]]; then
if dpkg -s "$package_name" >/dev/null 2>&1; then
echo "${R}[${W}-${R}]${G} $package_name installed successfully ${W}"
else
if type -p "$package_name" &>/dev/null || [ -e "$PREFIX/bin/$package_name"* ] || [ -e "$PREFIX/bin/"*"$package_name" ]; then
echo "${R}[${W}-${R}]${C} $package_name ${G}installed successfully ${W}"
fi
fi
elif [[ "$ID" == arch* ]]; then
if pacman -Qi "$package_name" >/dev/null 2>&1; then
echo "${R}[${W}-${R}]${G} $package_name installed successfully ${W}"
else
if type -p "$package_name" &>/dev/null || [ -e "$PREFIX/bin/$package_name"* ] || [ -e "$PREFIX/bin/"*"$package_name" ]; then
echo "${R}[${W}-${R}]${C} $package_name ${G}installed successfully ${W}"
fi
fi
elif [[ "$ID" == "alpine" ]]; then
if apk info -e "$package_name"; then
echo "${R}[${W}-${R}]${G} $package_name installed successfully ${W}"
else
if type -p "$package_name" &>/dev/null || [ -e "$PREFIX/bin/$package_name"* ] || [ -e "$PREFIX/bin/"*"$package_name" ]; then
echo "${R}[${W}-${R}]${C} $package_name ${G}installed successfully ${W}"
fi
fi
elif [[ "$ID" == "fedora" ]]; then
if rpm -q "$package_name" >/dev/null 2>&1; then
echo "${R}[${W}-${R}]${G} $package_name installed successfully ${W}"
else
if type -p "$package_name" &>/dev/null || [ -e "$PREFIX/bin/$package_name"* ] || [ -e "$PREFIX/bin/"*"$package_name" ]; then
echo "${R}[${W}-${R}]${C} $package_name ${G}installed successfully ${W}"
fi
fi
fi
done
echo ""
}
function distro_basic_task() {
banner
echo "${R}[${W}-${R}]${G}${BOLD}Updating ${C}$selected_distro ${G}And Installing Required Packages"${W}
echo
if [[ "$selected_distro" == "debian" ]] || [[ "$selected_distro" == "ubuntu" ]]; then
proot-distro login $selected_distro --shared-tmp -- env DISPLAY=:1.0 apt update
proot-distro login $selected_distro --shared-tmp -- env DISPLAY=:1.0 apt upgrade -y
elif [[ "$selected_distro" == "archlinux" ]]; then
proot-distro login $selected_distro --shared-tmp -- env DISPLAY=:1.0 pacman -Syu --noconfirm
elif [[ "$selected_distro" == "alpine" ]]; then
proot-distro login $selected_distro --shared-tmp -- env DISPLAY=:1.0 apk update
proot-distro login $selected_distro --shared-tmp -- env DISPLAY=:1.0 apk upgrade
elif [[ "$selected_distro" == "fedora" ]]; then
proot-distro login $selected_distro --shared-tmp -- env DISPLAY=:1.0 dnf update -y
proot-distro login $selected_distro --shared-tmp -- env DISPLAY=:1.0 dnf upgrade -y
chmod -R +w $distro_path/
fi
# Set proot timezone
timezone=$(getprop persist.sys.timezone)
proot-distro login $selected_distro --shared-tmp -- env DISPLAY=:1.0 rm /etc/localtime
proot-distro login $selected_distro --shared-tmp -- env DISPLAY=:1.0 cp /usr/share/zoneinfo/$timezone /etc/localtime
if [[ "$pd_audio_config_answer" == "y" ]]; then
distro_packs="sudo pulseaudio"
distro_fix_sound_issue
elif [[ "$pd_audio_config_answer" == "n" ]]; then
distro_packs="sudo"
fi
echo "pd_audio_config_answer=\"${pd_audio_config_answer}\"" >> $config_file
cat <<'EOF' > $distro_path/root/pd_basic_setup.sh
#!/bin/bash
R="$(printf '\033[1;31m')"
G="$(printf '\033[1;32m')"
Y="$(printf '\033[1;33m')"
B="$(printf '\033[1;34m')"
C="$(printf '\033[1;36m')"
W="$(printf '\033[0m')"
BOLD="$(printf '\033[1m')"
EOF
declare -f banner pd_root_package_install_and_check >> $distro_path/root/pd_basic_setup.sh
cat <<EOF >> $distro_path/root/pd_basic_setup.sh
banner
pd_root_package_install_and_check "${distro_packs}"
rm pd_basic_setup.sh
EOF
proot-distro login $selected_distro -- /bin/bash -c 'bash pd_basic_setup.sh'
if [[ "$pd_useradd_answer" == "n" ]]; then
final_user_name="root"
elif [[ "$pd_useradd_answer" == "y" ]]; then
final_user_name="${user_name}"
fi
echo "final_user_name=\"$final_user_name\"" >> $config_file
if [[ "$pd_pass_type" == "2" ]]; then
final_pass="${pass}"
else
final_pass="root"
fi
if [[ "$pd_useradd_answer" == "y" ]]; then
if [[ "$selected_distro" == "alpine" ]]; then
cat <<EOF > $distro_path/root/useradd.sh
#!/bin/bash
groupadd storage
groupadd wheel
mkdir -p /home/$final_user_name
adduser -h /home/$final_user_name -s \$(which bash) -G users -D $final_user_name
chown ${final_user_name}:users /home/$final_user_name
echo "${final_user_name}:${final_pass}" | chpasswd
rm useradd.sh
EOF
else
cat <<EOF > $distro_path/root/useradd.sh
#!/bin/bash
groupadd storage
groupadd wheel
useradd -m -g users -s \$(which bash) ${final_user_name}
usermod -aG wheel,polkitd,audio,video,storage ${final_user_name}
echo "${final_user_name}:${final_pass}" | chpasswd
rm useradd.sh
EOF
fi
proot-distro login $selected_distro -- /bin/sh -c 'bash useradd.sh'
if [[ "$pd_pass_type" == "1" ]];then
cat <<EOF > $distro_path/root/user_permission.sh
#!/bin/bash
chmod u+rw /etc/sudoers
echo "$final_user_name ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers > /dev/null 2>&1
chmod u-w /etc/sudoers
rm user_permission.sh
EOF
elif [[ "$pd_pass_type" == "2" ]];then
cat <<EOF > $distro_path/root/user_permission.sh
#!/bin/bash
chmod u+rw /etc/sudoers
echo "$final_user_name ALL=(ALL:ALL) ALL" | tee -a /etc/sudoers > /dev/null 2>&1
chmod u-w /etc/sudoers
rm user_permission.sh
EOF
fi
proot-distro login $selected_distro -- /bin/sh -c 'bash user_permission.sh'
proot-distro login $selected_distro -- /bin/sh -c 'sudo -k'
fi
}
#########################################################################
#
# Hardware Acceleration Setup
#
#########################################################################
# setup hardware acceleration, check if the enable-hw-acceleration already exist then then first check if it different from github , then ask user if they want to replace it or not, if not then continue with the lacal enable-hw-acceleration file
function hw_config() {
banner
echo "${R}[${W}-${R}]${G}${BOLD} Configuring Hardware Acceleration"${W}
echo
if [[ -f "${current_path}/enable-hw-acceleration" ]]; then
local current_script_hash=$(curl -sL https://raw.githubusercontent.com/sabamdarif/termux-desktop/main/enable-hw-acceleration | sha256sum | cut -d ' ' -f 1)
local local_script_hash=$(basename $(sha256sum ${current_path}/enable-hw-acceleration | cut -d ' ' -f 1))
if [[ "$local_script_hash" != "$current_script_hash" ]]; then
echo "${R}[${W}-${R}]${G} It look like you already have a different hw-acceleration installer in your current directory"${W}
echo
confirmation_y_or_n "Do you want to change it with the latest installer" change_old_hw_installer
if [[ "$change_old_hw_installer" == "y" ]]; then
check_and_backup "${current_path}/enable-hw-acceleration"
wget -O ${current_path}/enable-hw-acceleration https://raw.githubusercontent.com/sabamdarif/termux-desktop/main/enable-hw-acceleration && chmod +x ${current_path}/enable-hw-acceleration && . ${current_path}/enable-hw-acceleration
else
echo "${R}[${W}-${R}]${G} Using the local hardware acceleraion setup file"${W}
chmod +x ${current_path}/enable-hw-acceleration ; . ${current_path}/enable-hw-acceleration
fi
echo "change_old_hw_installer=\"$change_old_hw_installer\"" >> $config_file
else
echo "${R}[${W}-${R}]${G} Using the local hardware acceleraion setup file"${W}
chmod +x ${current_path}/enable-hw-acceleration ; . ${current_path}/enable-hw-acceleration
fi
else
wget -O ${current_path}/enable-hw-acceleration https://raw.githubusercontent.com/sabamdarif/termux-desktop/main/enable-hw-acceleration && chmod +x ${current_path}/enable-hw-acceleration && . ${current_path}/enable-hw-acceleration
rm ${current_path}/enable-hw-acceleration
fi
}
#########################################################################
#
# Setup Zsh And Terminal Utility
#
#########################################################################
function distro_zsh_answer() {
banner
if [[ "$pd_useradd_answer" == "y" ]]; then
save_path="$distro_path/home/$final_user_name"
elif [[ "$pd_useradd_answer" == "n" ]]; then
save_path="$distro_path/root"
fi
if [[ "$distro_zsh_answer" == "n" ]]; then
echo "${R}[${W}-${R}]${C}Canceling Distro Zsh Setup..."${W}
sleep 1.5
pd_shell_name="bash"
else
pd_shell_name="zsh"
echo "${R}[${W}-${R}]${G}${BOLD} Configuring Zsh for ${selected_distro}${G}.."${W}
echo
cat <<'EOF' > $distro_path/root/pd_zsh_install.sh
#!/bin/bash
R="$(printf '\033[1;31m')"
G="$(printf '\033[1;32m')"
Y="$(printf '\033[1;33m')"
B="$(printf '\033[1;34m')"
C="$(printf '\033[1;36m')"
W="$(printf '\033[0m')"
BOLD="$(printf '\033[1m')"
EOF
declare -f banner get_latest_release pd_root_package_install_and_check >> $distro_path/root/pd_zsh_install.sh
cat <<'EOF' >> $distro_path/root/pd_zsh_install.sh
banner
pd_root_package_install_and_check "git zsh wget"
wget https://raw.githubusercontent.com/sabamdarif/short-linux-scripts/main/install-zsh.sh && bash install-zsh.sh
clear
rm pd_zsh_install.sh
EOF
proot-distro login $selected_distro -- /bin/bash -c 'bash pd_zsh_install.sh'
cat <<'EOF' > $save_path/pd_zsh_setup.sh
#!/bin/bash
R="$(printf '\033[1;31m')"
G="$(printf '\033[1;32m')"
Y="$(printf '\033[1;33m')"
B="$(printf '\033[1;34m')"
C="$(printf '\033[1;36m')"
W="$(printf '\033[0m')"
BOLD="$(printf '\033[1m')"
EOF
cat <<'EOF' >> $save_path/pd_zsh_setup.sh
wget https://raw.githubusercontent.com/sabamdarif/short-linux-scripts/main/install-zsh.sh && bash install-zsh.sh
clear
rm pd_zsh_setup.sh
EOF
proot-distro login --user $final_user_name $selected_distro -- /bin/bash -c 'bash pd_zsh_setup.sh'
fi
echo "pd_shell_name=\"$pd_shell_name\"" >> $config_file
}
function distro_terminal_utility_setup() {
if [[ "$distro_terminal_utility_setup_answer" == "n" ]];then
banner
echo "${R}[${W}-${R}]${C}Skipping Terminal Utility Setup For ${selected_distro}..."${W}
echo
if [[ "$pd_useradd_answer" == "y" ]]; then
cp $distro_path/home/$final_user_name/.${pd_shell_name}rc $distro_path/home/$final_user_name/.${pd_shell_name}rc-2
check_and_backup "$distro_path/home/$final_user_name/.${pd_shell_name}rc"
mv $distro_path/home/$final_user_name/.${pd_shell_name}rc-2 $distro_path/home/$final_user_name/.${pd_shell_name}rc
cat <<'EOF' >> "$distro_path/home/$final_user_name/.${pd_shell_name}rc"
case $1 in
tx11start|tx11stop|vncstart|vncstop)
case $2 in
--help|-h|--nogpu|-f) ;;
esac
echo "please run it from termux, not inside proot distro."
;;
esac
EOF
fi
cp $distro_path/root/.${pd_shell_name}rc $distro_path/root/.${pd_shell_name}rc-2
check_and_backup "$distro_path/root/.${pd_shell_name}rc"
mv $distro_path/root/.${pd_shell_name}rc-2 $distro_path/root/.${pd_shell_name}rc
cat <<'EOF' >> "$distro_path/root/.${pd_shell_name}rc"
case $1 in
tx11start|tx11stop|vncstart|vncstop)
case $2 in
--help|-h|--nogpu|-f) ;;
esac
echo "please run it from termux, not inside proot distro."
;;
esac
EOF
elif [[ "$distro_terminal_utility_setup_answer" == "y" ]];then
banner
echo "${R}[${W}-${R}]${C}${BOLD}Configuring Terminal Utility For $selected_distro ..."${W}
echo
if [[ "$selected_distro" == "debian" ]] || [[ "$selected_distro" == "ubuntu" ]]; then
cat <<'EOF' > $distro_path/root/pd_setup.sh
#!/bin/bash
R="$(printf '\033[1;31m')"
G="$(printf '\033[1;32m')"
Y="$(printf '\033[1;33m')"
B="$(printf '\033[1;34m')"
C="$(printf '\033[1;36m')"
W="$(printf '\033[0m')"
BOLD="$(printf '\033[1m')"
EOF
declare -f banner get_latest_release pd_package_install_and_check >> $distro_path/root/pd_setup.sh
cat <<'EOF' >> $distro_path/root/pd_setup.sh
banner
pd_package_install_and_check "nala zoxide bat wget gpg"
device_arch=$(uname -m)
case "$device_arch" in
aarch64)
archtype="aarch64"
;;
arm)
archtype="armhf"
;;
amd64|x86_64)
archtype="amd64"
;;
i*86|x86)
archtype="i386"
;;
*)
echo "${R} unknown architecture"${W}
;;
esac
version=$(get_latest_release "fastfetch-cli" "fastfetch")
wget -O $distro_path/root/fastfetch.deb https://github.com/fastfetch-cli/fastfetch/releases/download/${version}/fastfetch-linux-${archtype}.deb
apt install ./fastfetch.deb -y
rm fastfetch.deb
mkdir -p /etc/apt/keyrings
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | sudo gpg --dearmor -o /etc/apt/keyrings/gierens.gpg
echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" | sudo tee /etc/apt/sources.list.d/gierens.list
chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list
apt update
pd_package_install_and_check "eza"
rm pd_setup.sh
EOF
else
cat <<'EOF' > $distro_path/root/pd_setup.sh
#!/bin/bash
R="$(printf '\033[1;31m')"
G="$(printf '\033[1;32m')"
Y="$(printf '\033[1;33m')"
B="$(printf '\033[1;34m')"
C="$(printf '\033[1;36m')"
W="$(printf '\033[0m')"
BOLD="$(printf '\033[1m')"
EOF
declare -f banner pd_package_install_and_check >> $distro_path/root/pd_setup.sh
cat <<'EOF' >> $distro_path/root/pd_setup.sh
pd_package_install_and_check "eza zoxide bat fastfetch"
EOF
fi
proot-distro login $selected_distro -- /bin/bash -c 'bash pd_setup.sh'
shell_rc_content=$(cat <<'EOF'
alias cat='bat $@'
alias ls='eza --icons $@'
alias mkdir='mkdir -p'
alias neofetch='fastfetch'
case $1 in
tx11start|tx11stop|vncstart|vncstop)
case $2 in
--help|-h|--nogpu|-f) ;;
esac
echo "please run it from termux, not inside proot distro."
;;
esac
#######################################################
# SPECIAL FUNCTIONS
#######################################################
# Extracts any archive(s) (if unp isn't installed)
extract() {
for archive in "$@"; do
if [ -f "$archive" ]; then
case $archive in
*.tar.bz2) tar xvjf $archive ;;
*.tar.xz) tar -xvf $archive ;;
*.tar.gz) tar -xzvf $archive ;;
*.bz2) bunzip2 $archive ;;
*.rar) rar x $archive ;;
*.tar) tar xvf $archive ;;
*.tbz2) tar xvjf $archive ;;
*.tgz) tar xvzf $archive ;;
*.zip) unzip $archive ;;
*.Z) uncompress $archive ;;
*.7z) 7z x $archive ;;
*) echo "don't know how to extract '$archive'..." ;;
esac
else
echo "'$archive' is not a valid file!"
fi
done
}
# Searches for text in all files in the current folder
ftext() {
# -i case-insensitive
# -I ignore binary files
# -H causes filename to be printed
# -r recursive search
# -n causes line number to be printed
# optional: -F treat search term as a literal, not a regular expression
# optional: -l only print filenames and not the matching lines ex. grep -irl "$1" *
grep -iIHrn --color=always "$1" . | less -r
}
# Copy and go to the directory
cpg() {
if [ -d "$2" ]; then
cp "$1" "$2" && cd "$2"
else
cp "$1" "$2"
fi
}
# Move and go to the directory
mvg() {
if [ -d "$2" ]; then
mv "$1" "$2" && cd "$2"
else
mv "$1" "$2"
fi
}
# Create and go to the directory
mkdirg() {
mkdir -p "$1"
cd "$1"
}
EOF
)
fi
if [[ "$distro_terminal_utility_setup_answer" == "y" ]];then
if [[ "$pd_useradd_answer" == "y" ]]; then
cp $distro_path/home/$final_user_name/.${pd_shell_name}rc $distro_path/home/$final_user_name/.${pd_shell_name}rc-2
check_and_backup "$distro_path/home/$final_user_name/.${pd_shell_name}rc"
mv $distro_path/home/$final_user_name/.${pd_shell_name}rc-2 $distro_path/home/$final_user_name/.${pd_shell_name}rc
echo "$shell_rc_content" >> "$distro_path/home/$final_user_name/.${pd_shell_name}rc"
fi
echo "$shell_rc_content" >> "$distro_path/root/.${pd_shell_name}rc"
if [[ "$pd_useradd_answer" == "y" ]]; then
cat <<EOF >> "$distro_path/home/$final_user_name/.${pd_shell_name}rc"
#set zoxide as cd
eval "\$(zoxide init --cmd cd ${pd_shell_name})"
EOF
fi
cat <<EOF >> "$distro_path/root/.${pd_shell_name}rc"
#set zoxide as cd
eval "\$(zoxide init --cmd cd ${pd_shell_name})"
EOF
if [[ "$selected_distro" == "debian" ]] || [[ "$selected_distro" == "ubuntu" ]]; then
if [[ "$pd_useradd_answer" == "y" ]]; then
cat <<'EOF' >> "$distro_path/home/$final_user_name/.${pd_shell_name}rc"
alias apt='sudo nala $@'
alias apt-get='sudo nala $@'
EOF
fi
cat <<'EOF' >> "$distro_path/root/.${pd_shell_name}rc"
alias apt='sudo nala $@'
alias apt-get='sudo nala $@'
EOF
fi
fi
}
#########################################################################
#
# Create App Installer Shortcut
#
#########################################################################
function handel_debian_based_app_installer() {
if [[ "$distro_terminal_utility_setup_answer" == "y" ]];then
local package_manager="nala"
else
local package_manager="apt"
fi
cat <<TOP_EOF > "$PREFIX/bin/$selected_distro"
#!/data/data/com.termux/files/usr/bin/bash
if [[ "\$#" -eq 0 ]]; then
proot-distro login --user $final_user_name $selected_distro --shared-tmp
elif [[ "\$1" = "install" ]]; then
if [[ ! -d "/data/data/com.termux/files/usr/share/applications/pd_added" ]]; then
mkdir -p "/data/data/com.termux/files/usr/share/applications/pd_added"
fi
proot-distro login --user $final_user_name $selected_distro --shared-tmp -- env DISPLAY=:1.0 sudo $package_manager install \${@:2}
cat <<EOF > "$save_root_path/packinstall.sh"
packages=(\${@:2})
EOF
cat <<'EOF' >> "$save_root_path/packinstall.sh"
for package_name in "\${packages[@]}"; do
desktop_files=\$(dpkg-query -W -f='\${binary:Package}\n' | grep "^\$package_name\(-.*\)\?\$" | xargs dpkg-query -L | grep "^/usr/share/applications/.*\.desktop\$")
if [ -z "\$desktop_files" ]; then
echo "${R}[${W}-${R}]${G} No .desktop files found for package ${C}'\$package_name' ${G}in/usr/share/applications."
else
for desktop_files_name in \$desktop_files; do
desktop_files_with_ext=\$(basename "\$desktop_files_name")
desktop_files_without_ext="\${desktop_files_with_ext%.desktop}"
echo "${R}[${W}-${R}]${G} Adding ${C}\${desktop_files_without_ext} ${G}To Termux Menu"
cp "/usr/share/applications/\${desktop_files_with_ext}" "/data/data/com.termux/files/usr/share/applications/pd_added/"
sed -i 's/Exec=/Exec=pdrun /g' "/data/data/com.termux/files/usr/share/applications/pd_added/\${desktop_files_with_ext}"
done
fi
done
rm packinstall.sh
EOF
proot-distro login $selected_distro -- /bin/bash -c 'bash packinstall.sh'
elif [[ "\$1" = "remove" ]] || [[ "\$1" = "autoremove" ]]; then
proot-distro login --user $final_user_name $selected_distro --shared-tmp -- env DISPLAY=:1.0 sudo $package_manager \$1 \${@:2}
cat <<EOF > "$save_root_path/packremove.sh"
packages=(\${@:2})
EOF
cat <<'EOF' >> "$save_root_path/packremove.sh"
for package_name in "\${packages[@]}"; do
desktop_files=\$(dpkg-query -W -f='\${binary:Package}\n' | grep "^\$package_name\(-.*\)\?\$" | xargs dpkg-query -L | grep "^/usr/share/applications/.*\.desktop\$")
if [ -z "\$desktop_files" ]; then
echo "${R}[${W}-${R}]${G} No .desktop files found for package ${C}'\$package_name' ${G}in/usr/share/applications."
else
for desktop_files_name in \$desktop_files; do
desktop_files_with_ext=\$(basename "\$desktop_files_name")
desktop_files_without_ext="\${desktop_files_with_ext%.desktop}"
echo "${R}[${W}-${R}]${G} Removing ${C}\${desktop_files_without_ext} ${G}From Termux Menu"
rm /data/data/com.termux/files/usr/share/applications/pd_added/\${desktop_files_with_ext}
done
fi
done
rm packremove.sh
EOF
proot-distro login $selected_distro -- /bin/bash -c 'bash packremove.sh'
elif [[ "\$1" = "update" ]]; then
proot-distro login --user $final_user_name $selected_distro --shared-tmp -- env DISPLAY=:1.0 sudo $package_manager update
fi
if [[ \$1 = "install" ]] || [[ \$1 = "remove" ]] || [[ \$1 = "autoremove" ]]; then
gtk-update-icon-cache
update-desktop-database -q "$PREFIX/share/applications/pd_added"
fi
TOP_EOF
}
function handel_arch_based_app_installer() {
cat <<TOP_EOF > "$PREFIX/bin/$selected_distro"
#!/data/data/com.termux/files/usr/bin/bash
if [[ "\$#" -eq 0 ]]; then
proot-distro login --user $final_user_name $selected_distro --shared-tmp
elif [[ "\$1" = "install" ]]; then
if [[ ! -d "/data/data/com.termux/files/usr/share/applications/pd_added" ]]; then
mkdir -p "/data/data/com.termux/files/usr/share/applications/pd_added"
fi
proot-distro login --user $final_user_name $selected_distro --shared-tmp -- env DISPLAY=:1.0 sudo pacman -S --noconfirm "\${@:2}"
cat <<EOF > "$save_root_path/packinstall.sh"
packages=("\${@:2}")
EOF
cat <<'EOF' >> "$save_root_path/packinstall.sh"
for package_name in "\${packages[@]}"; do
desktop_files=\$(pacman -Ql \$package_name | grep -oP "/usr/share/applications/.*\.desktop$")
if [ -z "\$desktop_files" ]; then
echo "${R}[${W}-${R}]${G} No .desktop files found for package ${C}'\$package_name' ${G}in /usr/share/applications."
else
for desktop_files_name in \$desktop_files; do
desktop_files_with_ext=\$(basename "\$desktop_files_name")
desktop_files_without_ext="\${desktop_files_with_ext%.desktop}"
echo "${R}[${W}-${R}]${G} Adding ${C}\${desktop_files_without_ext} ${G}To Termux Menu"
cp "/usr/share/applications/\${desktop_files_with_ext}" "/data/data/com.termux/files/usr/share/applications/pd_added/"
sed -i 's/Exec=/Exec=pdrun /g' "/data/data/com.termux/files/usr/share/applications/pd_added/\${desktop_files_with_ext}"
done
fi
done
rm packinstall.sh
EOF
proot-distro login $selected_distro -- /bin/bash -c 'bash packinstall.sh'
elif [[ "\$1" = "remove" ]]; then
proot-distro login --user $final_user_name $selected_distro --shared-tmp -- env DISPLAY=:1.0 sudo pacman -R --noconfirm "\${@:2}"
cat <<EOF > "$save_root_path/packremove.sh"
packages=("\${@:2}")
EOF
cat <<'EOF' >> "$save_root_path/packremove.sh"
for package_name in "\${packages[@]}"; do
desktop_files=\$(pacman -Ql \$package_name | grep -oP "/usr/share/applications/.*\.desktop$")
if [ -z "\$desktop_files" ]; then
echo "${R}[${W}-${R}]${G} No .desktop files found for package ${C}'\$package_name' ${G}in /usr/share/applications."
else
for desktop_files_name in \$desktop_files; do
desktop_files_with_ext=\$(basename "\$desktop_files_name")
desktop_files_without_ext="\${desktop_files_with_ext%.desktop}"
echo "${R}[${W}-${R}]${G} Removing ${C}\${desktop_files_without_ext} ${G}From Termux Menu"
rm /data/data/com.termux/files/usr/share/applications/pd_added/\${desktop_files_with_ext}
done
fi
done
rm packremove.sh
EOF
proot-distro login $selected_distro -- /bin/bash -c 'bash packremove.sh'
elif [[ "\$1" = "update" ]]; then
proot-distro login --user $final_user_name $selected_distro --shared-tmp -- env DISPLAY=:1.0 sudo pacman -Su
fi
if [[ \$1 = "install" ]] || [[ \$1 = "remove" ]]; then
gtk-update-icon-cache
update-desktop-database -q "$PREFIX/share/applications/pd_added"
fi
TOP_EOF
}
function handel_alpine_based_app_installer() {
cat <<TOP_EOF > "$PREFIX/bin/$selected_distro"
#!/data/data/com.termux/files/usr/bin/bash
if [[ "\$#" -eq 0 ]]; then
proot-distro login --user $final_user_name $selected_distro --shared-tmp
elif [[ "\$1" = "install" ]]; then
if [[ ! -d "/data/data/com.termux/files/usr/share/applications/pd_added" ]]; then
mkdir -p "/data/data/com.termux/files/usr/share/applications/pd_added"
fi
proot-distro login --user $final_user_name $selected_distro --shared-tmp -- env DISPLAY=:1.0 sudo apk add "\${@:2}"
cat <<EOF > "$save_root_path/packinstall.sh"
packages=("\${@:2}")
EOF
cat <<'EOF' >> "$save_root_path/packinstall.sh"
for package_name in "\${packages[@]}"; do
desktop_files=\$(ls /usr/share/applications/ | grep "\$package_name.*\.desktop$")
if [ -z "\$desktop_files" ]; then
echo "${R}[${W}-${R}]${G} No .desktop files found for package ${C}'\$package_name' ${G}in /usr/share/applications."
else
for desktop_files_name in \$desktop_files; do
desktop_files_without_ext="\${desktop_files_with_ext%.desktop}"
echo "${R}[${W}-${R}]${G} Adding ${C}\${desktop_files_without_ext} ${G}To Termux Menu"
sudo cp "/usr/share/applications/\${desktop_files_name}" "/data/data/com.termux/files/usr/share/applications/pd_added/"
sudo sed -i 's/Exec=/Exec=pdrun /g' "/data/data/com.termux/files/usr/share/applications/pd_added/\${desktop_files_name}"
done
fi
done
rm packinstall.sh
EOF
proot-distro login $selected_distro -- /bin/bash -c 'bash packinstall.sh'
elif [[ "\$1" = "remove" ]] || [[ "\$1" = "remove" ]]; then
proot-distro login --user $final_user_name $selected_distro --shared-tmp -- env DISPLAY=:1.0 sudo apk del "\${@:2}"
cat <<EOF > "$save_root_path/packremove.sh"
packages=("\${@:2}")
EOF
cat <<'EOF' >> "$save_root_path/packremove.sh"
for package_name in "\${packages[@]}"; do
desktop_files=\$(ls /usr/share/applications/ | grep "\$package_name.*\.desktop$")
if [ -z "\$desktop_files" ]; then
echo "${R}[${W}-${R}]${G} No .desktop files found for package ${C}'\$package_name' ${G}in /usr/share/applications."
else
for desktop_files_name in \$desktop_files; do
desktop_files_without_ext="\${desktop_files_with_ext%.desktop}"
echo "${R}[${W}-${R}]${G} Removing ${C}\${desktop_files_without_ext} ${G}From Termux Menu"
sudo rm /data/data/com.termux/files/usr/share/applications/pd_added/\${desktop_files_name}
done
fi
done
rm packremove.sh
EOF
proot-distro login $selected_distro -- /bin/bash -c 'bash packremove.sh'
elif [[ "\$1" = "update" ]]; then
proot-distro login --user $final_user_name $selected_distro --shared-tmp -- env DISPLAY=:1.0 sudo apk update
fi
if [[ \$1 = "install" ]] || [[ \$1 = "remove" ]]; then
gtk-update-icon-cache
update-desktop-database -q "$PREFIX/share/applications/pd_added"
fi
TOP_EOF
}
function handel_fedora_based_app_installer() {
cat <<TOP_EOF > "$PREFIX/bin/$selected_distro"
#!/data/data/com.termux/files/usr/bin/bash
if [[ "\$#" -eq 0 ]]; then
proot-distro login --user $final_user_name $selected_distro --shared-tmp
elif [[ "\$1" = "install" ]]; then
if [[ ! -d "/data/data/com.termux/files/usr/share/applications/pd_added" ]]; then
mkdir -p "/data/data/com.termux/files/usr/share/applications/pd_added"
fi
proot-distro login --user $final_user_name $selected_distro --shared-tmp -- env DISPLAY=:1.0 sudo dnf install \${@:2}
cat <<EOF > "$save_root_path/packinstall.sh"
packages=(\${@:2})
EOF
cat <<'EOF' >> "$save_root_path/packinstall.sh"
for package_name in "\${packages[@]}"; do
package_query=\$(rpm -q "\$package_name" | sed 's/-[0-9].*//')
desktop_files=\$(\$package_query | grep "^/usr/share/applications/.*\.desktop\$")
if [ -z "\$desktop_files" ]; then
echo "${R}[${W}-${R}]${G} No .desktop files found for package ${C}'\$package_name' ${G}in /usr/share/applications."
else
for desktop_files_name in \$desktop_files; do
desktop_files_with_ext=\$(basename "\$desktop_files_name")
desktop_files_without_ext="\${desktop_files_with_ext%.desktop}"
echo "${R}[${W}-${R}]${G} Adding ${C}\${desktop_files_without_ext} ${G}To Termux Menu"
cp "/usr/share/applications/\${desktop_files_with_ext}" "/data/data/com.termux/files/usr/share/applications/pd_added/"
sed -i 's/Exec=/Exec=pdrun /g' "/data/data/com.termux/files/usr/share/applications/pd_added/\${desktop_files_with_ext}"
done
fi
done
rm packinstall.sh
EOF
proot-distro login $selected_distro -- /bin/bash -c 'bash packinstall.sh'
elif [[ "\$1" = "remove" ]]; then
proot-distro login --user $final_user_name $selected_distro --shared-tmp -- env DISPLAY=:1.0 sudo dnf remove \${@:2}
cat <<EOF > "$save_root_path/packremove.sh"
packages=(\${@:2})
EOF
cat <<'EOF' >> "$save_root_path/packremove.sh"
for package_name in "\${packages[@]}"; do
desktop_files=\$(rpm -q "\$package_name" | grep "^/usr/share/applications/.*\.desktop\$")
if [ -z "\$desktop_files" ]; then
echo "${R}[${W}-${R}]${G} No .desktop files found for package ${C}'\$package_name' ${G}in /usr/share/applications."
else
for desktop_files_name in \$desktop_files; do
desktop_files_with_ext=\$(basename "\$desktop_files_name")
desktop_files_without_ext="\${desktop_files_with_ext%.desktop}"
echo "${R}[${W}-${R}]${G} Removing ${C}\${desktop_files_without_ext} ${G}From Termux Menu"
rm /data/data/com.termux/files/usr/share/applications/pd_added/\${desktop_files_with_ext}
done
fi
done
rm packremove.sh
EOF
proot-distro login $selected_distro -- /bin/bash -c 'bash packremove.sh'
else
echo "sudo dnf \$@
rm else.sh
" > $save_root_path/else.sh
proot-distro login $selected_distro -- /bin/sh -c 'bash else.sh'
fi
if [[ \$1 = "install" ]] || [[ \$1 = "remove" ]] || [[ \$1 = "autoremove" ]]; then
gtk-update-icon-cache
update-desktop-database -q "$PREFIX/share/applications/pd_added"
fi
TOP_EOF
}
function distro_create_app_installer() {
banner
echo "${R}[${W}-${R}]${G}${BOLD}Creating App Launcher"${W}
if [[ "$pd_useradd_answer" == "y" ]]; then
save_user_path="$distro_path/home/$final_user_name"
fi
save_root_path="$distro_path/root"
if [[ "$selected_distro" == "debian" ]] || [[ "$selected_distro" == "ubuntu" ]]; then
handel_debian_based_app_installer
elif [[ "$selected_distro" == "archlinux" ]]; then
handel_arch_based_app_installer
elif [[ "$selected_distro" == "alpine" ]]; then
handel_alpine_based_app_installer
elif [[ "$selected_distro" == "fedora" ]]; then
handel_fedora_based_app_installer
fi
cat <<EOF >> "$PREFIX/bin/$selected_distro"
function remove_distro_container() {
while true; do
read -p "${R}[${W}-${R}]${Y}${BOLD} Do you want to remove the distro${R}(it can't be undone) ${Y}(y/n) ${W}" ans_remove_distro
case \$ans_remove_distro in
[yY]* )
echo "${R}[${W}-${R}]${G}Continuing with answer: \$ans_remove_distro${W}"
sleep 0.2
if [[ -d $distro_path ]]; then
proot-distro remove $selected_distro
distro_file_list=(
"$PREFIX/bin/pdrun"
"$PREFIX/share/applications/pd_added"
"$PREFIX/bin/add2menu"
"$PREFIX/share/applications/add2menu.desktop"
"$PREFIX/bin/$selected_distro"
)
for distro_file in "${distro_file_list[@]}"; do
if [[ -e "$distro_file" ]]; then
if [[ -d "$distro_file" ]]; then
rm -rf $distro_file
else
rm $distro_file
fi
else
echo "${R}File does not exist: $distro_file"${W}
fi
done
echo "${G}$$selected_distro removed successfully"${W}
echo "distro_add_answer=\"n\"" >> $config_file
else
echo "${R}$selected_distro does not exist"
fi