-
Notifications
You must be signed in to change notification settings - Fork 117
/
setup-termux-desktop
executable file
·3341 lines (3079 loc) · 114 KB
/
setup-termux-desktop
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
#########################################################################
#
# Call First
#
#########################################################################
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')"
termux_desktop_path="$PREFIX/etc/termux-desktop"
config_file="$termux_desktop_path/configuration.conf"
cd $HOME
# create log
function debug() {
log_file="$HOME/termux-desktop.log"
exec > >(tee -a "$log_file") 2>&1
}
function banner() {
clear
printf "${C}############################################################\n"
printf "${C}# #\n"
printf "${C}# ▀█▀ █▀▀ █▀█ █▀▄▀█ █ █ ▀▄▀ █▀▄ █▀▀ █▀ █▄▀ ▀█▀ █▀█ █▀█ #\n"
printf "${C}# █ ██▄ █▀▄ █ █ █▄█ █ █ █▄▀ ██▄ ▄█ █ █ █ █▄█ █▀▀ #\n"
printf "${C}# #\n"
printf "${C}######################### Termux Gui #######################${W}\n"
echo " "
}
# check if the script is running on termux or not
function check_termux() {
if [[ $HOME != *termux* ]]; then
echo "${R}[${R}☓${R}]${R}${BOLD}Please run it inside termux"${W}
exit 0
fi
}
#########################################################################
#
# Shortcut Functions
#
#########################################################################
function check_and_create_directory() {
if [[ ! -d "$1" ]]; then
mkdir -p "$1"
fi
}
# first check then delete
function check_and_delete() {
local file
for files_folders in "$@"; do
for file in $files_folders; do
if [[ -e "$file" ]]; then
if [[ -d "$file" ]]; then
rm -rf "$file" >/dev/null 2>&1
elif [[ -f "$file" ]]; then
rm "$file" >/dev/null 2>&1
fi
fi
done
done
}
# first check then backup
function check_and_backup() {
local file
local files_folders
for files_folders in "$@"; do
for file in $files_folders; do
if [[ -e "$file" ]]; then
local date_str=$(date +"%d-%m-%Y")
local backup="${file}-${date_str}.bak"
if [[ -e "$backup" ]]; then
echo "${R}[${C}-${R}]${G}Backup file ${C}${backup} ${G}already exists"${W}
echo
fi
echo "${R}[${C}-${R}]${G}backing up file ${C}$file"${W}
mv "$1" "$backup"
fi
done
done
}
# find a backup file which end with a number pattern and restore it
function check_and_restore() {
local target_path="$1"
local dir
local base_name
dir=$(dirname "$target_path")
base_name=$(basename "$target_path")
local latest_backup
latest_backup=$(ls -1 "$dir/$base_name"-[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9].bak 2>/dev/null | sort | tail -n 1)
if [[ -z "$latest_backup" ]]; then
echo "${R}[${R}☓${R}]${R}No backup file found for ${target_path}.${W}"
echo
return 1
fi
if [[ -e "$target_path" ]]; then
echo "${R}[${R}☓${R}]${C}Original file or directory ${target_path} already exists.${W}"
echo
else
mv "$latest_backup" "$target_path"
echo "${R}[${G}✓${R}]${G}Restored ${latest_backup} to ${target_path}.${W}"
echo
fi
}
function detact_package_manager() {
source "/data/data/com.termux/files/usr/bin/termux-setup-package-manager"
if [[ "$TERMUX_APP_PACKAGE_MANAGER" == "apt" ]]; then
PACKAGE_MANAGER="apt"
elif [[ "$TERMUX_APP_PACKAGE_MANAGER" == "pacman" ]]; then
PACKAGE_MANAGER="pacman"
else
echo "${R}[${R}☓${R}]${C} Could not detact your package manager, Switching To ${C}pkg ${W}"
fi
}
# will check if the package is already installed or not, if it installed then it will reinstall it and at the end it will print success/failed message
function package_install_and_check() {
packs_list=($@)
for package_name in "${packs_list[@]}"; do
echo "${R}[${C}-${R}]${G}${BOLD} Processing package: ${C}$package_name ${W}"
if [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
if pacman -Qi "$package_name" >/dev/null 2>&1; then
echo "\"${package_name}\"=\"already_exist\"" >> "$config_file"
continue
fi
if [[ $package_name == *"*"* ]]; then
echo "${R}[${C}-${R}]${C} Processing wildcard pattern: $package_name ${W}"
packages=$(pacman -Ssq "${package_name%*}" 2>/dev/null)
for pkgs in $packages; do
echo "${R}[${C}-${R}]${G}${BOLD} Installing matched package: ${C}$pkgs ${W}"
pacman -Sy --noconfirm --overwrite '*' "$pkgs"
done
else
pacman -Sy --noconfirm --overwrite '*' "$package_name"
fi
else
if [[ $package_name == *"*"* ]]; then
echo "${R}[${C}-${R}]${C} Processing wildcard pattern: $package_name ${W}"
packages_by_name=$(apt-cache search "${package_name%*}" | awk "/^${package_name}/ {print \$1}")
packages_by_description=$(apt-cache search "${package_name%*}" | grep -Ei "\b${package_name%*}\b" | awk '{print $1}')
packages=$(echo -e "${packages_by_name}\n${packages_by_description}" | sort -u)
for pkgs in $packages; do
echo "${R}[${C}-${R}]${G}${BOLD} Installing matched package: ${C}$pkgs ${W}"
if dpkg -s "$pkgs" >/dev/null 2>&1; then
echo "\"${pkgs}\"=\"already_exist\"" >> "$config_file"
pkg reinstall "$pkgs" -y
else
pkg install "$pkgs" -y
fi
done
else
if dpkg -s "$package_name" >/dev/null 2>&1; then
echo "\"${package_name}\"=\"already_exist\"" >> "$config_file"
pkg reinstall "$package_name" -y
else
pkg install "$package_name" -y
fi
fi
fi
# Check installation success
if [ $? -ne 0 ]; then
echo "${R}[${C}-${R}]${G}${BOLD} Error detected during installation of: ${C}$package_name ${W}"
if [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
pacman -Sy --overwrite '*' "$package_name"
pacman -Sy --noconfirm "$package_name"
else
apt --fix-broken install -y
dpkg --configure -a
pkg install "$package_name" -y
fi
fi
# Final verification
if [[ $package_name != *"*"* ]]; then
if [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
if pacman -Qi "$package_name" >/dev/null 2>&1; then
echo "${R}[${G}✓${R}]${G} $package_name installed successfully ${W}"
else
echo "${R}[${R}☓${R}]${C} $package_name installation failed ${W}"
fi
else
if dpkg -s "$package_name" >/dev/null 2>&1; then
echo "${R}[${G}✓${R}]${G} $package_name installed successfully ${W}"
else
echo "${R}[${R}☓${R}]${C} $package_name installation failed ${W}"
fi
fi
fi
done
echo ""
}
# will check the package is installed or not then remove it
function package_check_and_remove() {
packs_list=($@)
for package_name in "${packs_list[@]}"; do
echo "${R}[${C}-${R}]${G}${BOLD} Processing package: ${C}$package_name ${W}"
if [[ $package_name == *"*"* ]]; then
echo "${R}[${C}-${R}]${C} Processing wildcard pattern: $package_name ${W}"
if [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
packages=$(pacman -Qq | grep -E "${package_name//\*/.*}")
else
packages=$(dpkg --get-selections | awk '{print $1}' | grep -E "${package_name//\*/.*}")
fi
for pkg in $packages; do
echo "${R}[${C}-${R}]${G}${BOLD} Removing matched package: ${C}$pkg ${W}"
if [[ "$pkg" != "already_exist" ]]; then
if [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
if pacman -Qi "$pkg" >/dev/null 2>&1; then
pacman -Rnds --noconfirm "$pkg"
if [ $? -eq 0 ]; then
echo "${R}[${G}✓${R}]${G} $pkg removed successfully ${W}"
else
echo "${R}[${R}☓${R}]${C} Failed to remove $pkg ${W}"
fi
fi
else
if dpkg -s "$pkg" >/dev/null 2>&1; then
apt autoremove "$pkg" -y
if [ $? -eq 0 ]; then
echo "${R}[${G}✓${R}]${G} $pkg removed successfully ${W}"
else
echo "${R}[${R}☓${R}]${C} Failed to remove $pkg ${W}"
fi
fi
fi
fi
done
else
if [[ "$package_name" != "already_exist" ]]; then
if [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
if pacman -Qi "$package_name" >/dev/null 2>&1; then
echo "${R}[${C}-${R}]${G}${BOLD} Removing package: ${C}$package_name ${W}"
pacman -Rnds --noconfirm "$package_name"
if [ $? -eq 0 ]; then
echo "${R}[${G}✓${R}]${G} $package_name removed successfully ${W}"
else
echo "${R}[${R}☓${R}]${C} Failed to remove $package_name ${W}"
fi
fi
else
if dpkg -s "$package_name" >/dev/null 2>&1; then
echo "${R}[${C}-${R}]${G}${BOLD} Removing package: ${C}$package_name ${W}"
apt autoremove "$package_name" -y
if [ $? -eq 0 ]; then
echo "${R}[${G}✓${R}]${G} $package_name removed successfully ${W}"
else
echo "${R}[${R}☓${R}]${C} Failed to remove $package_name ${W}"
fi
fi
fi
fi
fi
done
echo ""
}
function get_file_name_number() {
current_file=$(basename "$0")
folder_name="${current_file%.sh}"
theme_number=$(echo "$folder_name" | grep -oE '[1-9][0-9]*')
}
function extract_zip_with_progress() {
local archive="$1"
local target_dir="$2"
# Check if the archive file exists
if [[ ! -f "$archive" ]]; then
echo "${R}[${R}☓${R}]${R}$archive doesn't exist${W}"
return 1
fi
local total_files=$(unzip -l "$archive" | grep -E '^\s+[0-9]+' | wc -l)
if [[ "$total_files" -eq 0 ]]; then
echo "${R}[${R}☓${R}]${R}No files found in the archive${W}"
return 1
fi
echo "Total files to extract: $total_files"
local extracted_files=0
unzip -o "$archive" -d "$target_dir" | while read line; do
if [[ "$line" =~ inflating: ]]; then
((extracted_files++))
progress=$((extracted_files * 100 / total_files))
echo -ne "${G}Extracting: ${C}$progress% ($extracted_files/$total_files) \r"${W}
fi
done
echo "${R}[${G}✓${R}]${G}${archive} Extraction complete!"${W}
}
function extract_archive() {
local archive="$1"
if [[ ! -f "$archive" ]]; then
echo -e "${R}[☓]${R} $archive doesn't exist${W}"
return 1
fi
local total_size
total_size=$(stat -c '%s' "$archive")
case "$archive" in
*.tar.gz|*.tgz)
echo -e "${G}[✔] Extracting ${C}$archive${W}"
pv -s "$total_size" -p -r "$archive" | tar xzf - || { echo -e "${R}[☓] Failed to extract ${C}$archive${W}"; return 1; }
;;
*.tar.xz)
echo -e "${G}[✔] Extracting ${C}$archive${W}"
pv -s "$total_size" -p -r "$archive" | tar xJf - || { echo -e "${R}[☓] Failed to extract ${C}$archive${W}"; return 1; }
;;
*.tar.bz2|*.tbz2)
echo -e "${G}[✔] Extracting ${C}$archive${W}"
pv -s "$total_size" -p -r "$archive" | tar xjf - || { echo -e "${R}[☓] Failed to extract ${C}$archive${W}"; return 1; }
;;
*.tar)
echo -e "${G}[✔] Extracting ${C}$archive${W}"
pv -s "$total_size" -p -r "$archive" | tar xf - || { echo -e "${R}[☓] Failed to extract ${C}$archive${W}"; return 1; }
;;
*.bz2)
echo -e "${G}[✔] Extracting ${C}$archive${W}"
pv -s "$total_size" -p -r "$archive" | bunzip2 > "${archive%.bz2}" || { echo -e "${R}[☓] Failed to extract ${C}$archive${W}"; return 1; }
;;
*.gz)
echo -e "${G}[✔] Extracting ${C}$archive${W}"
pv -s "$total_size" -p -r "$archive" | gunzip > "${archive%.gz}" || { echo -e "${R}[☓] Failed to extract ${C}$archive${W}"; return 1; }
;;
*.7z)
echo -e "${G}[✔] Extracting ${C}$archive${W}"
pv -s "$total_size" -p -r "$archive" | 7z x -si -y > /dev/null || { echo -e "${R}[☓] Failed to extract ${C}$archive${W}"; return 1; }
;;
*.zip)
extract_zip_with_progress "${archive}"
;;
*.rar)
echo -e "${G}[✔] Extracting ${C}$archive${W}"
unrar x "$archive" || { echo -e "${R}[☓] Failed to extract ${C}$archive${W}"; return 1; }
;;
*)
echo -e "${R}[☓] Unsupported archive format: ${C}$archive${W}"
return 1
;;
esac
echo -e "${G}[✔] Successfully extracted ${C}$archive${W}"
}
# download a archive file and extract it in a folder
function download_and_extract() {
local url="$1"
local target_dir="$2"
local filename="${url##*/}"
# Notify user about downloading
echo "${R}[${C}-${R}]${C}${BOLD}Downloading ${G}${filename}...${W}"
sleep 1.5
# Change to the target directory
cd "$target_dir" || return 1
local attempt=1
local success=false
# Attempt to download the file with retries
while [[ $attempt -le 3 ]]; do
if curl -# -L "$url" -o "$filename"; then
success=true
break
else
echo "${R}[${R}☓${R}]${R}Failed to download ${C}${filename}${W}"
echo "${R}[${C}☓-{R}]${G}Retrying... Attempt ${C}$attempt${W}"
((attempt++))
sleep 1
fi
done
# If download is successful, extract and remove the archive
if [[ "$success" = true ]]; then
if [[ -f "$filename" ]]; then
echo
echo "${R}[${C}-${R}]${R}[${C}-${R}]${G} Extracting $filename${W}"
extract_archive "$filename"
rm "$filename"
fi
else
# Notify if download fails after all attempts
echo "${R}[${R}☓${R}]${R}Failed to download ${C}${filename}${W}"
echo "${R}[${C}-${R}]${C}Please check your internet connection${W}"
fi
}
# count the number subfolders inside a folder in my repo
function count_subfolders() {
local owner="$1"
local repo="$2"
local path="$3"
local url="https://api.github.com/repos/$owner/$repo/contents/$path"
local response=$(curl -s "$url")
local subfolder_count=$(echo "$response" | jq -r '.[] | select(.type == "dir") | .name' | wc -l)
if [[ -z "$subfolder_count" || "$subfolder_count" -eq 0 ]]; then
subfolder_count=0
fi
echo "$subfolder_count"
}
# create a yes / no confirmation prompt
function confirmation_y_or_n() {
while true; do
read -p "${R}[${C}-${R}]${Y}${BOLD} $1 ${Y}(y/n) "${W} response
response="${response:-y}"
eval "$2='$response'"
case $response in
[yY]* )
echo
echo "${R}[${G}✓${R}]${G} Continuing with answer: $response"${W}
echo
sleep 0.2
break;;
[nN]* )
echo
echo "${R}[${C}-${R}]${C} Skipping this setp"${W}
echo
sleep 0.2
break;;
* )
echo
echo "${R}[${R}☓${R}]${R} Invalid input. Please enter 'y' or 'n'."${W}
echo
;;
esac
done
}
# get the latest version from a github releases
# ex. latest_tag=$(get_latest_release "$repo_owner" "$repo_name")
function get_latest_release() {
local repo_woner="$1"
local repo_name="$2"
curl -s "https://api.github.com/repos/$repo_woner/$repo_name/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/'
}
function install_font_for_style() {
local style_number="$1"
echo "${R}[${C}-${R}]${G} Installing Fonts..."${W}
check_and_create_directory "$HOME/.fonts"
download_and_extract "https://raw.githubusercontent.com/sabamdarif/termux-desktop/main/patch/$de_name/look_${style_number}/font.tar.gz" "$HOME/.fonts"
fc-cache -f
cd
}
function download_github_action_artifact() {
# Parse arguments passed to the function
while [[ "$#" -gt 0 ]]; do
case "$1" in
--user)
GITHUB_USER="$2"
shift 2
;;
--repo)
REPO="$2"
shift 2
;;
--workflow-name)
WORKFLOW_NAME="$2" # The name of the CI workflow
shift 2
;;
--run-name)
RUN_NAME="$2" # Specific name/description of the workflow run
shift 2
;;
--artifact-name)
ARTIFACT_NAME="$2" # Artifact name prefix (can be modified as needed)
shift 2
;;
*)
echo "${R}[${R}☓${R}]Unknown option: $1"${W}
shift
;;
esac
done
# Get the workflow ID using the workflow name
WORKFLOW_ID=$(gh api repos/$GITHUB_USER/$REPO/actions/workflows --jq ".workflows[] | select(.name == \"$WORKFLOW_NAME\") | .id")
# Check if WORKFLOW_ID is found
if [ -z "$WORKFLOW_ID" ]; then
echo "${R}[${R}☓${R}]${R} Workflow '$WORKFLOW_NAME' not found."${W}
exit 1
fi
# Display the workflow ID
echo "${R}[${C}-${R}]${G} Workflow ID for ${W}'$WORKFLOW_NAME' ${G}is ${W}$WORKFLOW_ID"
# Get the latest workflow run ID with the specific display title
WORKFLOW_RUN_ID=$(gh api repos/$GITHUB_USER/$REPO/actions/workflows/$WORKFLOW_ID/runs --paginate --jq ".workflow_runs[] | select(.display_title == \"$RUN_NAME\") | .id" | head -n 1)
# Check if WORKFLOW_RUN_ID is obtained
if [ -z "$WORKFLOW_RUN_ID" ]; then
echo "${R}[${R}☓${R}]${R} No workflow run found with the name '$RUN_NAME' for workflow '$WORKFLOW_NAME'."${W}
exit 1
fi
# List artifacts for the found run
ARTIFACT_URL=$(gh api repos/$GITHUB_USER/$REPO/actions/runs/$WORKFLOW_RUN_ID/artifacts --jq ".artifacts[] | select(.name == \"$ARTIFACT_NAME\") | .archive_download_url")
# If no exact match, look for an artifact starting with ARTIFACT_NAME
if [ -z "$ARTIFACT_URL" ]; then
echo "${R}[${C}-${R}]${C} Artifact with the exact name '$ARTIFACT_NAME' not found. Looking for artifacts starting with '$ARTIFACT_NAME'..."${W}
ARTIFACT_URL=$(gh api repos/$GITHUB_USER/$REPO/actions/runs/$WORKFLOW_RUN_ID/artifacts --jq ".artifacts[] | select(.name | startswith(\"$ARTIFACT_NAME\")) | .archive_download_url" | head -n 1)
fi
# Check if ARTIFACT_URL is found
if [ -z "$ARTIFACT_URL" ]; then
echo "${R}[${R}☓${R}]${R} No artifact found starting with '$ARTIFACT_NAME'."${W}
exit 1
fi
# Download the artifact using the URL
echo "${R}[${G}✓${R}]${G} Downloading artifact from run '$RUN_NAME'..."${W}
curl -# -L -H "Authorization: Bearer $(gh auth token)" -o artifact.zip "$ARTIFACT_URL"
# Extract the artifact
extract_archive "artifact.zip"
}
function select_an_option() {
local max_options=$1
local default_option=${2:-1}
local response_var=$3
local response
while true; do
read -p "${Y}select an option (Default ${default_option}): ${W}" response
response=${response:-$default_option}
if [[ $response =~ ^[0-9]+$ ]] && ((response >= 1 && response <= max_options)); then
echo
echo "${R}[${G}✓${R}]${G} Continuing with answer: $response${W}"
sleep 0.2
eval "$response_var=$response"
break
else
echo
echo "${R}[${R}☓${R}]${R} Invalid input. Please enter a number between 1 and $max_options.${W}"
fi
done
}
# temp_config_file="$PREFIX/tmp/processed_config.conf"
# function preprocess_conf() {
# cp "$config_file" "$temp_config_file"
# # Preprocess configuration file:
# # 1. Replace all dashes in keys with underscores.
# # 2. Remove quotes from keys and values.
# sed -i -E 's/^([[:space:]]*[^#=]+)-/\1_/g; s/-/_/g; s/^([[:space:]]*[^#=]+)="([^"]*)"/\1=\2/g' "$temp_config_file"
# }
# function read_conf() {
# if [[ ! -f "$temp_config_file" ]]; then
# echo "Preprocessed configuration file not found."
# exit 1
# fi
# # Safely source the preprocessed configuration file
# while IFS='=' read -r key value; do
# # Trim whitespace from key and value
# key=$(echo "$key" | xargs)
# value=$(echo "$value" | xargs)
# # Skip comments and empty lines
# if [[ -z "$key" || "$key" =~ ^# ]]; then
# continue
# fi
# # Export the key-value pair as a variable
# export "$key"="$value"
# done < "$temp_config_file"
# }
function preprocess_conf() {
# Preprocess configuration file:
# 1. Remove lines where keys contain dashes (-).
# 2. Remove quotes from keys and values.
echo "${R}[${C}-${R}]${G} Prepering config file..."${W}
sed -i -E '/^[[:space:]]*[^#=]+-.*=/d; s/^([[:space:]]*[^#=]+)="([^"]*)"/\1=\2/g' "$config_file"
}
function read_conf() {
if [[ ! -f "$config_file" ]]; then
echo "${R}[${R}☓${R}]${R} Configuration file $config_file not found."${W}
exit 0
fi
# source "$config_file"
# Process each line of the file
while IFS='=' read -r key value; do
# Trim whitespace and surrounding quotes from key and value
key=$(echo "$key" | xargs | sed 's/"//g')
value=$(echo "$value" | xargs | sed 's/"//g')
# Skip empty lines and comments
if [[ -z "$key" || "$key" =~ ^# ]]; then
continue
fi
# Dynamically create variables
export "$key"="$value"
done < "$config_file"
echo "${R}[${C}✓${R}]${G} Configuration variables loaded."${W}
}
#########################################################################
#
# Ask Required Questions
#
#########################################################################
# check the avilable styles and create a list to type the corresponding number
# in the style readme file the name must use this'## number name :' pattern, like:- ## 1. Basic Style:
function questions_theme_select() {
local owner="sabamdarif"
local repo="termux-desktop"
local main_folder="patch/$de_name"
local subfolder_count_value=$(count_subfolders "$owner" "$repo" "$main_folder" 2>/dev/null)
cd $HOME
echo "${R}[${C}-${R}]${G} Downloading list...."${W}
wget -qO ${current_path}/styles.md https://raw.githubusercontent.com/sabamdarif/termux-desktop/main/${de_name}_styles.md
clear
banner
# Check if the subfolder count value is obtained
if [[ -n "$subfolder_count_value" ]]; then
echo "${R}[${C}-${R}]${G} Check the $de_name styles section in GitHub"${W}
echo
echo "${R}[${C}-${R}]${B} https://github.com/sabamdarif/termux-desktop/blob/main/${de_name}_styles.md"${W}
echo
echo "${R}[${C}-${R}]${G} Number of available custom styles for $de_name is: ${C}${subfolder_count_value}"${W}
echo
echo "${R}[${C}-${R}]${G} Available Styles:${W}"
echo
# Display available styles from the styles.md file
grep -oP '## \d+\..+?(?=(\n## \d+\.|\Z))' styles.md | while read -r style; do
echo "${Y}${style#### }${W}"
done
# Prompt user to select a style
while true; do
echo
read -p "${R}[${C}-${R}]${Y} Type number of the style: ${W}" style_answer
# Check if the input is empty
if [[ -z "$style_answer" ]]; then
echo
echo "${R}[${R}☓${R}]${R} Input cannot be empty. Please type a number."${W}
continue
fi
# Ensure the input is a valid number and within range
if [[ "$style_answer" =~ ^[0-9]+$ ]] && [[ "$style_answer" -ge 0 ]] && [[ "$style_answer" -le "$subfolder_count_value" ]]; then
style_name=$(grep -oP "^## $style_answer\..+?(?=(\n## \d+\.|\Z))" styles.md | sed -e "s/^## $style_answer\. //" -e "s/:$//")
break
else
echo
echo "${R}[${R}☓${R}]${R} The entered style number is incorrect."${W}
echo
if [[ "$subfolder_count_value" == "0" ]]; then
echo "${R}[${C}-${R}]${Y} Please enter 0 beacuse for $de_name only stock style is available"${W}
echo
else
echo "${R}[${C}-${R}]${Y} Please enter a number between 0 to ${subfolder_count_value}"${W}
echo
fi
echo "${R}[${C}-${R}]${G} Check the $de_name styles section in GitHub"${W}
echo
echo "${R}[${C}-${R}]${B} https://github.com/sabamdarif/termux-desktop/blob/main/${de_name}_styles.md"${W}
echo
fi
done
# Remove the styles.md file after use
rm ${current_path}/styles.md
else
echo "${R}[${R}☓${R}]${R} Failed to get total available styles value."${W}
fi
}
function questions() {
banner
echo "${R}[${C}-${R}]${G} Select Desktop Environment"${W}
echo " "
echo "${Y}1. XFCE"${W}
echo
echo "${Y}2. LXQT"${W}
echo
echo "${Y}3. OPENBOX WM"${W}
echo
echo "${Y}4. MATE (Unstable)"${W}
echo
select_an_option 4 1 desktop_answer
# set the variables based on chosen de
sys_icons_folder="$PREFIX/share/icons"
sys_themes_folder="$PREFIX/share/themes"
if [[ "$desktop_answer" == "1" ]]; then
de_name="xfce"
themes_folder="$HOME/.themes"
icons_folder="$HOME/.icons"
de_startup="xfce4-session"
elif [[ "$desktop_answer" == "2" ]]; then
de_name="lxqt"
themes_folder="$sys_themes_folder"
icons_folder="$sys_icons_folder"
de_startup="startlxqt"
elif [[ "$desktop_answer" == "3" ]]; then
de_name="openbox"
themes_folder="$sys_themes_folder"
icons_folder="$sys_icons_folder"
de_startup="openbox-session"
elif [[ "$desktop_answer" == "4" ]]; then
de_name="mate"
themes_folder="$HOME/.themes"
icons_folder="$HOME/.icons"
de_startup="mate-session"
fi
echo "de_startup=\"$de_startup\"" >> $config_file
echo "de_name=\"$de_name\"" >> $config_file
echo "themes_folder=\"$themes_folder\"" >> $config_file
echo "icons_folder=\"$icons_folder\"" >> $config_file
banner
questions_theme_select
echo
echo "${R}[${G}✓${R}]${G} Continuing with answer: ${style_answer}.$style_name"${W}
echo "style_answer=\"$style_answer\"" >> $config_file
echo "style_name=\"$style_name\"" >> $config_file
sleep 0.2
banner
echo "${R}[${C}-${R}]${G}${BOLD} Select browser you want to install"${W}
echo
echo "${Y}1. firefox"${W}
echo
echo "${Y}2. chromium"${W}
echo
echo "${Y}3. firefox & chromium (both)"${W}
echo
echo "${Y}4. Skip"${W}
echo
select_an_option 4 1 browser_answer
banner
echo "${R}[${C}-${R}]${G}${BOLD} Select IDE you want to install"${W}
echo
echo "${Y}1. VS Code"${W}
echo
echo "${Y}2. Geany (lightweight IDE)"${W}
echo
echo "${Y}3. VS Code & Geany (both)"${W}
echo
echo "${Y}4. Skip"${W}
echo
select_an_option 4 1 ide_answer
banner
echo "${R}[${C}-${R}]${G}${BOLD} Select Media Player you want to install"${W}
echo
echo "${Y}1. Vlc"${W}
echo
echo "${Y}2. Audacious"${W}
echo
echo "${Y}3. Vlc & Audacious (both)"${W}
echo
echo "${Y}4. Skip"${W}
echo
select_an_option 4 1 player_answer
banner
echo "${R}[${C}-${R}]${G}${BOLD} Select Photo Editor"${W}
echo
echo "${Y}1. Gimp"${W}
echo
echo "${Y}2. Inkscape"${W}
echo
echo "${Y}3. Gimp & Inkscape (both)"${W}
echo
echo "${Y}4. Skip"${W}
echo
select_an_option 4 1 photo_editor_answer
banner
echo "${R}[${C}-${R}]${G}${BOLD} Do you want to install wine in termux ${C}(without proot-distro)"${W}
echo
echo "${Y}1. Natively ${C}(can run only arm64 based exe)"${W}
echo
echo "${Y}2. Using Mobox ${C}"${W}
echo
echo "${R}[${C}-${R}]${B} Know More About Mobox:- https://github.com/olegos2/mobox/"${W}
echo
echo "${Y}3. Wine Hangover (Best)"${W}
echo
echo "${Y}4. Skip"${W}
echo
select_an_option 4 1 wine_answer
banner
confirmation_y_or_n "Do you want to install a graphical package manager [Synaptic]" synaptic_answer
banner
echo "${R}[${C}-${R}]${G} By Default it only add 4 - 5 wallpaper"${W}
echo
confirmation_y_or_n "Do you want to add some more wallpaper" ext_wall_answer
banner
confirmation_y_or_n "Do you want to Configuring Zsh" zsh_answer
banner
echo
echo "${R}[${C}-${R}]${B} Know More About Terminal Utility:- https://github.com/sabamdarif/termux-desktop/blob/main/see-more.md#hammer_and_wrenchlearn-about-terminal-utilities"${W}
echo
confirmation_y_or_n "Do you want install some terminal utility to make better terminal exprience" terminal_utility_setup_answer
banner
echo "${R}[${C}-${R}]${G}${BOLD} Select Gui Mode"${W}
echo
echo "${Y}1. Termux:x11"${W}
echo
echo "${Y}2. Vnc (Not Recommended | Some features might not work)"${W}
echo
echo "${Y}3. Both"${W}
echo
select_an_option 3 1 gui_mode
banner
confirmation_y_or_n "Do you want to start the desktop at Termux startup" de_on_startup
if [[ "$de_on_startup" == "y" && "$gui_mode" == "3" ]]; then
echo "${R}[${C}-${R}]${G} You chose both vnc and termux:x11 to access gui mode"${W}
echo
echo "${R}[${C}-${R}]${G} Which will be your default"${W}
echo
echo "${Y}1. Termux:x11"${W}
echo
echo "${Y}2. Vnc"${W}
echo
select_an_option 2 1 autostart_gui_mode
fi
banner
echo "${R}[${C}-${R}]${Y}${BOLD} Do you want to add a Linux container (proot distro)"${W}
echo
echo "${R}[${C}-${R}]${G} It will help you to install those app which are not avilable in termux"${W}
echo
echo "${R}[${C}-${R}]${C} You can launch those installed apps from termux like other apps"${W}
echo
confirmation_y_or_n "Do you want to continue" distro_add_answer
echo "distro_add_answer=\"$distro_add_answer\"" >> $config_file
clear
if ! type -p pacman >/dev/null 2>&1; then
echo "${R}[${C}-${R}]${R}${BOLD} Read This Carefully"${W}
echo -e "
In my tests, I achieved 1000+ FPS in vkmark on all my devices. I tried it on an
- Adreno 619 (everything work fine)
- Adreno 750 (good overall but with few issues)
- Mali G76 (similar issue like Adreno 750).
- Mali G57 everything work with this driver\n
Also if you have Adreno GPU then please select ubuntu or debian as Linux container so it can use ternip in the Linux container.\n
Sadly for other then adreno, GPU might / might not work on the Linux container./n
If you type 'n/N' then it will use the old virtualizing way to setup Hardware Acceleration./n
"
confirmation_y_or_n "Do you want to install the new mesa-vulkan-icd-wrapper Driver" confirmation_mesa_vulkan_icd_wrapper
echo "confirmation_mesa_vulkan_icd_wrapper=\"$confirmation_mesa_vulkan_icd_wrapper\"" >> $config_file
fi
}
# distro hardware accelrration related questions
function distro_hw_questions() {
if [[ "$distro_add_answer" == "y" ]]; then
echo
echo "${R}[${C}-${R}]${G}${BOLD} Select Hardware Acceleration Driver For Linux Container"${W}
echo
echo "${R}[${C}-${R}]${G} If You Are Not Sure So Skip It It Will Use The Previous One"${W}
echo
if [[ "$termux_hw_answer" == "virgl" ]] || [[ "$termux_hw_answer" == "virgl_vulkan" ]]; then
echo "${Y}1. OpenGL (VIRGL ANGLE)"${W}
echo
echo "${Y}2. Turnip (Adreno GPU Only)"${W}
echo
echo "${Y}3. Skip"${W}
echo
select_an_option 3 1 pd_hw_answer_num
# set gpu api
if [[ "$pd_hw_answer_num" == "1" ]]; then
pd_hw_answer="virgl"
elif [[ "$pd_hw_answer_num" == "2" ]]; then
pd_hw_answer="turnip"
fi
else
echo "${Y}1. Vulkan (ZINK)"${W}
echo
echo "${Y}2. OpenGL ES (ZINK VIRGL)"${W}
echo
echo "${Y}3. Turnip (Adreno GPU Only)"${W}
echo
echo "${Y}4. Skip"${W}
echo
select_an_option 4 1 pd_hw_answer_num
# set gpu api
if [[ "$pd_hw_answer_num" == "1" ]]; then
pd_hw_answer="zink"
elif [[ "$pd_hw_answer_num" == "2" ]]; then
pd_hw_answer="zink_virgl"
elif [[ "$pd_hw_answer_num" == "3" ]]; then
pd_hw_answer="turnip"
fi
fi
echo "pd_hw_answer_num=\"$pd_hw_answer_num\"" >> $config_file
echo "pd_hw_answer=\"$pd_hw_answer\"" >> $config_file
fi
}
# hardware accelrration related questions
function exp_termux_gl_hw_support() {
banner
echo "${R}[${C}-${R}]${G}${BOLD} First Read This"${W}
echo
echo "${R}[${C}-${R}]${B} This:- https://github.com/sabamdarif/termux-desktop/blob/main/hw-acceleration.md"${W}
echo
echo "${R}[${C}-${R}]${G}${BOLD} It will be used to enable opengl support"${W}
echo
echo "${Y}1. Vulkan (ZINK)"${W}
echo
echo "${Y}2. OpenGL (VIRGL ANGLE)"${W}
echo
echo "${Y}3. Vulkan (VIRGL ANGLE)"${W}
echo
echo "${Y}4. OpenGL ES (ZINK VIRGL)"${W}
echo
echo "${Y}5. The New Driver With Mesa"${W}
echo
echo "${Y}6. The New Driver With Mesa-Zink"${W}
echo
select_an_option 6 1 exp_termux_gl_hw_answer_num
echo "exp_termux_gl_hw_answer_num=\"$exp_termux_gl_hw_answer_num\"" >> $config_file
# set gpu api name
if [[ "$exp_termux_gl_hw_answer_num" == "1" ]]; then
exp_termux_gl_hw_answer="zink"
elif [[ "$exp_termux_gl_hw_answer_num" == "2" ]]; then
exp_termux_gl_hw_answer="virgl"
elif [[ "$exp_termux_gl_hw_answer_num" == "3" ]]; then
exp_termux_gl_hw_answer="virgl_vulkan"
elif [[ "$exp_termux_gl_hw_answer_num" == "4" ]]; then
exp_termux_gl_hw_answer="zink_virgl"
elif [[ "$exp_termux_gl_hw_answer_num" == "5" ]]; then
exp_termux_gl_hw_answer="zink_with_mesa"
elif [[ "$exp_termux_gl_hw_answer_num" == "6" ]]; then
exp_termux_gl_hw_answer="zink"
fi
echo "exp_termux_gl_hw_answer=\"$exp_termux_gl_hw_answer\"" >> $config_file
termux_hw_answer="${exp_termux_gl_hw_answer}"
echo "termux_hw_answer=\"$exp_termux_gl_hw_answer\"" >> $config_file
if [[ "$device_gpu_model_name" == "adreno" ]] && [[ "$distro_add_answer" == "y" ]]; then
if [[ "$distro_answer" == "1" || "$distro_answer" == "2" ]]; then
pd_hw_answer="turnip"
echo "pd_hw_answer=\"$pd_hw_answer\"" >> $config_file
fi
fi
if [[ "$distro_add_answer" == "y" ]]; then
case "$exp_termux_gl_hw_answer" in
"virgl"|"virgl_vulkan")
pd_hw_answer="virgl"
echo "pd_hw_answer=\"$pd_hw_answer\"" >> $config_file
;;
*)
distro_hw_questions
;;
esac
fi