-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathsetup-termux-desktop
executable file
·3868 lines (3536 loc) · 133 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')"
cd "$HOME" || exit
termux_desktop_path="$PREFIX/etc/termux-desktop"
config_file="$termux_desktop_path/configuration.conf"
log_file="$HOME/termux-desktop.log"
# create log
function debug() {
exec > >(tee -a "$log_file") 2>&1
}
function banner() {
clear
printf "%s############################################################\n" "$C"
printf "%s# #\n" "$C"
printf "%s# ▀█▀ █▀▀ █▀█ █▀▄▀█ █ █ ▀▄▀ █▀▄ █▀▀ █▀ █▄▀ ▀█▀ █▀█ █▀█ #\n" "$C"
printf "%s# █ ██▄ █▀▄ █ █ █▄█ █ █ █▄▀ ██▄ ▄█ █ █ █ █▄█ █▀▀ #\n" "$C"
printf "%s# #\n" "$C"
printf "%s######################### Termux Gui #######################%s\n" "$C" "$W"
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 print_log() {
local timestamp="$(date '+%Y-%m-%d %H:%M:%S')"
local log_level="${2:-INFO}" # Default log level is INFO
local call_stack=""
local line_number="${BASH_LINENO[0]}"
# Build call stack
for ((i = 1; i < ${#FUNCNAME[@]}; i++)); do
if [[ -n "${FUNCNAME[$i]}" ]]; then
call_stack+="${FUNCNAME[$i]}:${BASH_LINENO[$i-1]} -> "
fi
done
call_stack="${call_stack::-4}" # Remove trailing " -> "
# Format the log entry
{
echo "========== $timestamp =========="
echo "Level: $log_level"
echo "Function: ${FUNCNAME[1]:-main}"
echo "Line: $line_number"
echo "Call Stack: ${call_stack:-main}"
# Log arguments
echo "Details:"
if [[ $# -gt 1 ]]; then
# Skip the log level if it was provided
shift
for arg in "$@"; do
echo " $arg"
done
else
echo " $1"
fi
# Add command exit status if available
if [[ -n "$PIPESTATUS" ]]; then
echo "Last Command Status: ${PIPESTATUS[@]}"
fi
echo "========================================"
echo
} >> "$log_file"
}
# Helper functions for different log levels
function log_info() {
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "========================================" >> "$log_file"
echo "Time: $timestamp" >> "$log_file"
echo "Type: Info" >> "$log_file"
echo "Message: $1" >> "$log_file"
echo "Status: $?" >> "$log_file"
echo "========================================" >> "$log_file"
echo >> "$log_file"
}
function log_warn() {
print_log "$1" "WARNING" "${@:2}"
}
function log_error() {
print_log "$1" "ERROR" "${@:2}"
}
function log_debug() {
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "========================================" >> "$log_file"
echo "Time: $timestamp" >> "$log_file"
echo "Type: Debug" >> "$log_file"
echo "Message: $1" >> "$log_file"
echo "Status: $?" >> "$log_file"
echo "========================================" >> "$log_file"
echo >> "$log_file"
}
function print_success() {
local msg
msg="$1"
echo "${R}[${G}✓${R}]${G} $msg${W}"
print_log "$msg"
}
function print_failed() {
local msg
msg="$1"
echo "${R}[${R}☓${R}]${R} $msg${W}"
print_log "$msg"
}
function print_warn() {
local msg
msg="$1"
echo "${R}[${Y}!${R}]${Y} $msg${W}"
print_log "$msg"
}
function wait_for_keypress() {
read -n1 -s -r -p "${R}[${C}-${R}]${G} Press any key to continue...${W}"
echo
}
function check_and_create_directory() {
if [[ ! -d "$1" ]]; then
mkdir -p "$1"
print_log "$1"
fi
}
# first check then delete
function check_and_delete() {
local file
local files_folders
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
print_log "$file"
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_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"
print_log "$1 $backup"
fi
done
done
}
function download_file() {
local dest
local url
dest="$1"
url="$2"
print_log "$dest"
print_log "$url"
if [[ -z "$dest" ]]; then
wget --tries=5 --timeout=15 --retry-connrefused "$url"
else
wget --tries=5 --timeout=15 --retry-connrefused -O "$dest" "$url"
fi
# Check if the file was downloaded successfully
if [[ -f "$dest" || -f "$(basename "$url")" ]]; then
print_success "Successfully downloaded the file"
else
print_failed "Failed to download the file, retrying..."
if [[ -z "$dest" ]]; then
wget --tries=5 --timeout=15 --retry-connrefused "$url"
else
wget --tries=5 --timeout=15 --retry-connrefused -O "$dest" "$url"
fi
# Final check
if [[ -f "$dest" || -f "$(basename "$url")" ]]; then
print_success "Successfully downloaded the file after retry"
else
print_failed "Failed to download the file after retry"
exit 0
fi
fi
}
# 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=$(find "$dir" -maxdepth 1 -type f -name "$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
print_failed "No backup file found for ${target_path}."
echo
return 1
fi
if [[ -e "$target_path" ]]; then
print_failed "${C}Original file or directory ${target_path} already exists.${W}"
echo
else
mv "$latest_backup" "$target_path"
print_success "Restored ${latest_backup} to ${target_path}"
echo
fi
print_log "$target_path $dir $base_name $latest_backup"
}
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
print_failed "${C} Could not detact your package manager, Switching To ${C}pkg ${W}"
fi
print_log "$PACKAGE_MANAGER"
}
# 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() {
log_info "Starting package installation" "Packages: $*"
packs_list=($@)
for package_name in "${packs_list[@]}"; do
log_debug "Processing package" "Package: $package_name"
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
log_info "Package already installed" "Package: $package_name"
continue
fi
if [[ $package_name == *"*"* ]]; then
log_debug "Processing wildcard pattern" "Pattern: $package_name"
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
log_debug "Processing wildcard pattern" "Pattern: $package_name"
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
log_info "Package already installed" "Package: $pkgs"
pkg reinstall "$pkgs" -y
else
pkg install "$pkgs" -y
fi
done
else
if dpkg -s "$package_name" >/dev/null 2>&1; then
log_info "Package already installed" "Package: $package_name"
pkg reinstall "$package_name" -y
else
pkg install "$package_name" -y
fi
fi
fi
# Check installation success
if [ $? -ne 0 ]; then
log_error "Installation failed" "Package: $package_name" "Exit code: $?"
else
log_info "Installation successful" "Package: $package_name"
fi
done
echo ""
log_info "Package installation completed"
print_log "package list: $packs_list"
}
# 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}"
print_log "Processing wildcard pattern: $package_name"
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 [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
if pacman -Qi "$pkg" >/dev/null 2>&1; then
pacman -Rnds --noconfirm "$pkg"
if [ $? -eq 0 ]; then
print_success "$pkg removed successfully"
print_log "Processing wildcard pattern: $package_name"
else
print_failed "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
print_success "$pkg removed successfully"
else
print_failed "Failed to remove $pkg ${W}"
fi
fi
fi
done
else
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
print_success "$package_name removed successfully"
else
print_failed "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
print_success "$package_name removed successfully"
else
print_failed "Failed to remove $package_name ${W}"
fi
fi
fi
fi
done
echo ""
print_log "$package_name"
}
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]*')
print_log "$theme_number"
}
function extract_zip_with_progress() {
local archive="$1"
local target_dir="$2"
# Check if the archive file exists
if [[ ! -f "$archive" ]]; then
print_failed "$archive doesn't exist"
return 1
fi
local total_files
total_files=$(unzip -l "$archive" | grep -c -E '^\s+[0-9]+')
if [[ "$total_files" -eq 0 ]]; then
print_failed "No files found in the archive"
return 1
fi
echo "Total files to extract: $total_files"
local extracted_files=0
unzip -o "$archive" -d "$target_dir" | while read -r 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
print_success "${archive} Extraction complete!"
}
function extract_archive() {
local archive="$1"
if [[ ! -f "$archive" ]]; then
print_failed "$archive doesn't exist"
return 1
fi
local total_size
total_size=$(stat -c '%s' "$archive")
case "$archive" in
*.tar.gz|*.tgz)
print_success "Extracting ${C}$archive"
pv -s "$total_size" -p -r "$archive" | tar xzf - || { print_failed "Failed to extract ${C}$archive"; return 1; }
;;
*.tar.xz)
print_success "Extracting ${C}$archive"
pv -s "$total_size" -p -r "$archive" | tar xJf - || { print_failed "Failed to extract ${C}$archive"; return 1; }
;;
*.tar.bz2|*.tbz2)
print_success "Extracting ${C}$archive"
pv -s "$total_size" -p -r "$archive" | tar xjf - || { print_failed "Failed to extract ${C}$archive"; return 1; }
;;
*.tar)
print_success "Extracting ${C}$archive"
pv -s "$total_size" -p -r "$archive" | tar xf - || { print_failed "Failed to extract ${C}$archive"; return 1; }
;;
*.bz2)
print_success "Extracting ${C}$archive"
pv -s "$total_size" -p -r "$archive" | bunzip2 > "${archive%.bz2}" || { print_failed "Failed to extract ${C}$archive"; return 1; }
;;
*.gz)
print_success "Extracting ${C}$archive${W}"
pv -s "$total_size" -p -r "$archive" | gunzip > "${archive%.gz}" || { print_failed "Failed to extract ${C}$archive"; return 1; }
;;
*.7z)
print_success "Extracting ${C}$archive"
pv -s "$total_size" -p -r "$archive" | 7z x -si -y > /dev/null || { print_failed "Failed to extract ${C}$archive"; return 1; }
;;
*.zip)
extract_zip_with_progress "${archive}"
;;
*.rar)
print_success "Extracting ${C}$archive"
unrar x "$archive" || { print_failed "Failed to extract ${C}$archive"; return 1; }
;;
*)
print_failed "Unsupported archive format: ${C}$archive"
return 1
;;
esac
print_success "Successfully extracted ${C}$archive"
print_log "$archive"
}
# 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
print_failed "Failed to download ${C}${filename}"
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
print_failed "Failed to download ${C}${filename}"
echo "${R}[${C}-${R}]${C}Please check your internet connection${W}"
fi
print_log "$url $target_dir $filename"
}
# 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
response=$(curl -s "$url")
local subfolder_count
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"
print_log "$url $response $subfolder_count"
}
# create a yes / no confirmation prompt
function confirmation_y_or_n() {
while true; do
read -r -p "${R}[${C}-${R}]${Y}${BOLD} $1 ${Y}(y/n) ${W}" response
response="${response:-y}"
eval "$2='$response'"
case $response in
[yY]* )
echo
print_success "Continuing with answer: $response"
echo
sleep 0.2
break;;
[nN]* )
echo
echo "${R}[${C}-${R}]${C} Skipping this setp${W}"
echo
sleep 0.2
break;;
* )
echo
print_failed " Invalid input. Please enter 'y' or 'n'."
echo
;;
esac
done
print_log "$1 $response"
}
# get the latest version from a github releases
# ex. latest_tag=$(get_latest_release "$repo_owner" "$repo_name")
function get_latest_release() {
local repo_owner="$1"
local repo_name="$2"
curl -s "https://api.github.com/repos/$repo_owner/$repo_name/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"v?([^"]+)".*/\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/setup-files/$de_name/look_${style_number}/font.tar.gz" "$HOME/.fonts"
fc-cache -f
cd "$HOME" || return
}
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
print_failed " Workflow '$WORKFLOW_NAME' not found."
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
print_failed " No workflow run found with the name '$RUN_NAME' for workflow '$WORKFLOW_NAME'."
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
print_failed " No artifact found starting with '$ARTIFACT_NAME'."
exit 1
fi
# Download the artifact using the URL
print_success "Downloading artifact from run '$RUN_NAME'..."
curl -# -L -H "Authorization: Bearer $(gh auth token)" -o artifact.zip "$ARTIFACT_URL"
# Extract the artifact
extract_archive "artifact.zip"
}
function print_status() {
local status
status=$1
local message
message=$2
if [[ "$status" == "ok" ]]; then
print_success "$message"
elif [[ "$status" == "warn" ]]; then
print_warn "$message"
elif [[ "$status" == "error" ]]; then
print_failed "$message"
fi
}
function select_an_option() {
local max_options=$1
local default_option=${2:-1}
local response_var=$3
local response
while true; do
read -r -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
print_success "Continuing with answer: $response"
sleep 0.2
eval "$response_var=$response"
break
else
echo
print_failed " Invalid input, Please enter a number between 1 and $max_options"
fi
done
}
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
print_failed " Configuration file $config_file not found"
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"
print_success "Configuration variables loaded"
}
#########################################################################
#
# 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="setup-files/$de_name"
local subfolder_count_value
subfolder_count_value=$(count_subfolders "$owner" "$repo" "$main_folder" 2>/dev/null)
cd "$HOME" || return
echo "${R}[${C}-${R}]${G} Downloading list....${W}"
check_and_backup "${current_path}/styles.md"
download_file "${current_path}/styles.md" "https://raw.githubusercontent.com/sabamdarif/termux-desktop/main/${de_name}_styles.md"
clear
banner
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
grep -oP '## \d+\..+?(?=(\n## \d+\.|\Z))' styles.md | while read -r style; do
echo "${Y}${style#### }${W}"
done
while true; do
echo
read -r -p "${R}[${C}-${R}]${Y} Type number of the style: ${W}" style_answer
if [[ -z "$style_answer" ]]; then
echo
print_failed "Input cannot be empty. Please type a number"
continue
fi
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
print_failed "The entered style number is incorrect"
echo
if [[ "$subfolder_count_value" == "0" ]]; then
echo "${R}[${C}-${R}]${Y} Please enter 0 because 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
rm "${current_path}/styles.md"
else
print_failed "Failed to get total available styles value"
exit 0
fi
print_log "$style_answer $subfolder_count_value"
}
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
print_success "Continuing with answer: ${style_answer}.$style_name"
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
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
if [[ "$de_name" != "mate" ]]; then
banner
echo -e "
Typing 'Y' to this option will add a variety of options to your file manager's right-click menu. Using this, you can do a lot more things within the right-click menu than you ever imagined, such as:
- Most basic video/image-related tasks
- Audio/PDF-related tasks
- Archive-related tasks, file permissions, document handling, encryption, and hash checks
- And much more
In File Manager click on the scripts meanu to see them all
"
echo
confirmation_y_or_n "Do you want to Configuring File Manager Tools (Testing)" fm_tools
fi
banner
echo "${R}[${C}-${R}]${G}${BOLD} Select Gui Mode${W}"
echo
echo "${Y}1. Termux:x11${W}"
echo
echo "${Y}2. Both Termux:x11 and VNC${W}"
echo
select_an_option 2 1 gui_mode_num
# set gui_mode and display_number value
if [[ "$gui_mode_num" == "1" ]]; then
gui_mode="termux_x11"
display_number="0"
echo "display_number=\"$display_number\"" >> "$config_file"
elif [[ "$gui_mode_num" == "2" ]]; then
gui_mode="both"
display_number="0"
echo "display_number=\"$display_number\"" >> "$config_file"
fi
echo "gui_mode_num=\"$gui_mode_num\"" >> "$config_file"
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" == "both" ]]; 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_num
echo "autostart_gui_mode_num=\"$autostart_gui_mode_num\"" >> "$config_file"
if [[ "$autostart_gui_mode_num" == "1" ]]; then
autostart_gui_mode="termux_x11"