-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall.sh
2024 lines (1820 loc) · 73 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#------------------------------------------------------------------------------
# GLOBAL VARIABLES
#------------------------------------------------------------------------------
# Interactive interface with gum
USE_GUM=false
# Initial configuration
EXECUTE_INITIAL_CONFIG=true
# Detailed output
VERBOSE=false
# Variables for Debian PRoot
PROOT_USERNAME=""
PROOT_PASSWORD=""
#------------------------------------------------------------------------------
# SELECTORS OF MODULES
#------------------------------------------------------------------------------
# Shell selection
SHELL_CHOICE=false
# Additional packages installation
PACKAGES_CHOICE=false
# Custom fonts installation
FONT_CHOICE=false
# XFCE environment installation
XFCE_CHOICE=false
# Debian Proot installation
PROOT_CHOICE=false
# Termux-X11 installation
X11_CHOICE=false
# Full installation without interactions
FULL_INSTALL=false
# Use gum for interactions
ONLY_GUM=true
#------------------------------------------------------------------------------
# CONFIGURATION FILES
#------------------------------------------------------------------------------
BASHRC="$HOME/.bashrc"
ZSHRC="$HOME/.zshrc"
FISHRC="$HOME/.config/fish/config.fish"
#------------------------------------------------------------------------------
# DISPLAY COLORS
#------------------------------------------------------------------------------
COLOR_BLUE='\033[38;5;33m' # Information
COLOR_GREEN='\033[38;5;82m' # Success
COLOR_GOLD='\033[38;5;220m' # Warning
COLOR_RED='\033[38;5;196m' # Error
COLOR_RESET='\033[0m' # Reset
#------------------------------------------------------------------------------
# REDIRECTION
#------------------------------------------------------------------------------
if [ "$VERBOSE" = false ]; then
REDIRECT="> /dev/null 2>&1"
else
REDIRECT=""
fi
#------------------------------------------------------------------------------
# DISPLAY HELP
#------------------------------------------------------------------------------
show_help() {
clear
echo "Help OhMyTermux"
echo
echo "Usage: $0 [OPTIONS] [username] [password]"
echo "Options:"
echo " --gum | -g Use gum for the user interface"
echo " --verbose | -v Display detailed outputs"
echo " --shell | -sh Install shell module"
echo " --package | -pk Install packages module"
echo " --font | -f Install font module"
echo " --xfce | -x Install XFCE module"
echo " --proot | -pr Install Debian PRoot module"
echo " --x11 Install Termux-X11 module"
echo " --skip Ignore initial configuration"
echo " --uninstall Uninstall Debian Proot"
echo " --full Install all modules without confirmation"
echo " --help | -h Display this help message"
echo
echo "Examples:"
echo " $0 --gum # Installation interactive with gum"
echo " $0 --full user pass # Installation complete with identifiers"
}
#------------------------------------------------------------------------------
# ARGUMENTS MANAGEMENT
#------------------------------------------------------------------------------
for ARG in "$@"; do
case $ARG in
--gum|-g)
USE_GUM=true
shift
;;
--shell|-sh)
SHELL_CHOICE=true
ONLY_GUM=false
shift
;;
--package|-pk)
PACKAGES_CHOICE=true
ONLY_GUM=false
shift
;;
--font|-f)
FONT_CHOICE=true
ONLY_GUM=false
shift
;;
--xfce|-x)
XFCE_CHOICE=true
ONLY_GUM=false
shift
;;
--proot|-pr)
PROOT_CHOICE=true
ONLY_GUM=false
shift
;;
--x11)
X11_CHOICE=true
ONLY_GUM=false
shift
;;
--skip)
EXECUTE_INITIAL_CONFIG=false
shift
;;
--uninstall)
uninstall_proot
exit 0
;;
--verbose|-v)
VERBOSE=true
REDIRECT=""
shift
;;
--full)
FULL_INSTALL=true
SHELL_CHOICE=true
PACKAGES_CHOICE=true
FONT_CHOICE=true
XFCE_CHOICE=true
PROOT_CHOICE=true
X11_CHOICE=true
SCRIPT_CHOICE=true
ONLY_GUM=false
shift
;;
--help|-h)
show_help
exit 0
;;
*)
# Get the username and password if provided
if [ -z "$PROOT_USERNAME" ]; then
PROOT_USERNAME="$ARG"
shift
elif [ -z "$PROOT_PASSWORD" ]; then
PROOT_PASSWORD="$ARG"
shift
else
break
fi
;;
esac
done
# If in FULL_INSTALL mode and identifiers are not provided, ask for them
if $FULL_INSTALL; then
if [ -z "$PROOT_USERNAME" ]; then
if $USE_GUM; then
PROOT_USERNAME=$(gum input --placeholder "Enter the username for Debian PRoot")
else
printf "${COLOR_BLUE}Enter the username for Debian PRoot : ${COLOR_RESET}"
read -r PROOT_USERNAME
fi
fi
if [ -z "$PROOT_PASSWORD" ]; then
while true; do
if $USE_GUM; then
PROOT_PASSWORD=$(gum input --password --prompt "Password: " --placeholder "Enter a password")
PASSWORD_CONFIRM=$(gum input --password --prompt "Confirm password: " --placeholder "Confirm the password")
else
printf "${COLOR_BLUE}Enter a password: ${COLOR_RESET}"
read -r -s PROOT_PASSWORD
echo
printf "${COLOR_BLUE}Confirm the password: ${COLOR_RESET}"
read -r -s PASSWORD_CONFIRM
echo
fi
if [ "$PROOT_PASSWORD" = "$PASSWORD_CONFIRM" ]; then
break
else
if $USE_GUM; then
gum style --foreground 196 "The passwords do not match. Please try again."
else
echo -e "${COLOR_RED}The passwords do not match. Please try again.${COLOR_RESET}"
fi
fi
done
fi
fi
# Activate all modules if --gum is the only argument
if $ONLY_GUM; then
SHELL_CHOICE=true
PACKAGES_CHOICE=true
FONT_CHOICE=true
XFCE_CHOICE=true
PROOT_CHOICE=true
X11_CHOICE=true
SCRIPT_CHOICE=true
fi
#------------------------------------------------------------------------------
# INFORMATION MESSAGES
#------------------------------------------------------------------------------
info_msg() {
if $USE_GUM; then
gum style "${1//$'\n'/ }" --foreground 33
else
echo -e "${COLOR_BLUE}$1${COLOR_RESET}"
fi
}
#------------------------------------------------------------------------------
# SUCCESS MESSAGES
#------------------------------------------------------------------------------
success_msg() {
if $USE_GUM; then
gum style "${1//$'\n'/ }" --foreground 82
else
echo -e "${COLOR_GREEN}$1${COLOR_RESET}"
fi
}
#------------------------------------------------------------------------------
# ERROR MESSAGES
#------------------------------------------------------------------------------
error_msg() {
if $USE_GUM; then
gum style "${1//$'\n'/ }" --foreground 196
else
echo -e "${COLOR_RED}$1${COLOR_RESET}"
fi
}
#------------------------------------------------------------------------------
# TITLE MESSAGES
#------------------------------------------------------------------------------
title_msg() {
if $USE_GUM; then
gum style "${1//$'\n'/ }" --foreground 220 --bold
else
echo -e "\n${COLOR_GOLD}\033[1m$1\033[0m${COLOR_RESET}"
fi
}
#------------------------------------------------------------------------------
# SUBTITLE MESSAGES
#------------------------------------------------------------------------------
subtitle_msg() {
if $USE_GUM; then
gum style "${1//$'\n'/ }" --foreground 33 --bold
else
echo -e "\n${COLOR_BLUE}\033[1m$1\033[0m${COLOR_RESET}"
fi
}
#------------------------------------------------------------------------------
# ERROR LOGGING
#------------------------------------------------------------------------------
log_error() {
local ERROR_MSG="$1"
local USERNAME=$(whoami)
local HOSTNAME=$(hostname)
local CWD=$(pwd)
echo "[$(date +'%d/%m/%Y %H:%M:%S')] ERREUR: $ERROR_MSG | Utilisateur: $USERNAME | Machine: $HOSTNAME | Répertoire: $CWD" >> "$HOME/.config/OhMyTermux/install.log"
}
#------------------------------------------------------------------------------
# DYNAMIC DISPLAY OF COMMAND RESULTS
#------------------------------------------------------------------------------
execute_command() {
local COMMAND="$1"
local INFO_MSG="$2"
local SUCCESS_MSG="✓ $INFO_MSG"
local ERROR_MSG="✗ $INFO_MSG"
local ERROR_DETAILS
if $USE_GUM; then
if gum spin --spinner.foreground="33" --title.foreground="33" --spinner dot --title "$INFO_MSG" -- bash -c "$COMMAND $REDIRECT"; then
gum style "$SUCCESS_MSG" --foreground 82
else
ERROR_DETAILS="Command: $COMMAND, Redirect: $REDIRECT, Time: $(date +'%d/%m/%Y %H:%M:%S')"
gum style "$ERROR_MSG" --foreground 196
log_error "$ERROR_DETAILS"
return 1
fi
else
tput sc
info_msg "$INFO_MSG"
if eval "$COMMAND $REDIRECT"; then
tput rc
tput el
success_msg "$SUCCESS_MSG"
else
tput rc
tput el
ERROR_DETAILS="Command: $COMMAND, Redirect: $REDIRECT, Time: $(date +'%d/%m/%Y %H:%M:%S')"
error_msg "$ERROR_MSG"
log_error "$ERROR_DETAILS"
return 1
fi
fi
}
#------------------------------------------------------------------------------
# GUM CONFIRMATION
#------------------------------------------------------------------------------
gum_confirm() {
local PROMPT="$1"
if $FULL_INSTALL; then
return 0
else
gum confirm --affirmative "Oui" --negative "Non" --prompt.foreground="33" --selected.background="33" --selected.foreground="0" "$PROMPT"
fi
}
#------------------------------------------------------------------------------
# GUM UNIQUE SELECTION
#------------------------------------------------------------------------------
gum_choose() {
local PROMPT="$1"
shift
local SELECTED=""
local OPTIONS=()
local HEIGHT=10
while [[ $# -gt 0 ]]; do
case $1 in
--selected=*)
SELECTED="${1#*=}"
;;
--height=*)
HEIGHT="${1#*=}"
;;
*)
OPTIONS+=("$1")
;;
esac
shift
done
if $FULL_INSTALL; then
if [ -n "$SELECTED" ]; then
echo "$SELECTED"
else
# Return the first option by default
echo "${OPTIONS[0]}"
fi
else
gum choose --selected.foreground="33" --header.foreground="33" --cursor.foreground="33" --height="$HEIGHT" --header="$PROMPT" --selected="$SELECTED" "${OPTIONS[@]}"
fi
}
#------------------------------------------------------------------------------
# GUM MULTIPLE SELECTION
#------------------------------------------------------------------------------
gum_choose_multi() {
local PROMPT="$1"
shift
local SELECTED=""
local OPTIONS=()
local HEIGHT=10
while [[ $# -gt 0 ]]; do
case $1 in
--selected=*)
SELECTED="${1#*=}"
;;
--height=*)
HEIGHT="${1#*=}"
;;
*)
OPTIONS+=("$1")
;;
esac
shift
done
if $FULL_INSTALL; then
if [ -n "$SELECTED" ]; then
echo "$SELECTED"
else
echo "${OPTIONS[@]}"
fi
else
gum choose --no-limit --selected.foreground="33" --header.foreground="33" --cursor.foreground="33" --height="$HEIGHT" --header="$PROMPT" --selected="$SELECTED" "${OPTIONS[@]}"
fi
}
#------------------------------------------------------------------------------
# TEXT MODE BANNER
#------------------------------------------------------------------------------
bash_banner() {
clear
local BANNER="
╔════════════════════════════════════════╗
║ ║
║ OHMYTERMUX ║
║ ║
╚════════════════════════════════════════╝"
echo -e "${COLOR_BLUE}${BANNER}${COLOR_RESET}\n"
}
#------------------------------------------------------------------------------
# GUM INSTALLATION
#------------------------------------------------------------------------------
check_and_install_gum() {
if $USE_GUM && ! command -v gum &> /dev/null; then
bash_banner
echo -e "${COLOR_BLUE}Installation de gum...${COLOR_RESET}"
pkg update -y > /dev/null 2>&1 && pkg install gum -y > /dev/null 2>&1
fi
}
check_and_install_gum
#------------------------------------------------------------------------------
# ERROR MANAGEMENT
#------------------------------------------------------------------------------
finish() {
local RET=$?
if [ ${RET} -ne 0 ] && [ ${RET} -ne 130 ]; then
echo
if $USE_GUM; then
gum style --foreground 196 "ERREUR: Installation de OhMyTermux impossible."
else
echo -e "${COLOR_RED}ERREUR: Installation de OhMyTermux impossible.${COLOR_RESET}"
fi
echo -e "${COLOR_BLUE}Veuillez vous référer au(x) message(s) d'erreur ci-dessus.${COLOR_RESET}"
fi
}
trap finish EXIT
#------------------------------------------------------------------------------
# GRAPHIC BANNER
#------------------------------------------------------------------------------
show_banner() {
clear
if $USE_GUM; then
gum style \
--foreground 33 \
--border-foreground 33 \
--border double \
--align center \
--width 42 \
--margin "1 1 1 0" \
"" "OHMYTERMUX" ""
else
bash_banner
fi
}
#------------------------------------------------------------------------------
# FILE BACKUP
#------------------------------------------------------------------------------
create_backups() {
local BACKUP_DIR="$HOME/.config/OhMyTermux/backups"
# Create the backup directory
execute_command "mkdir -p \"$BACKUP_DIR\"" "Create the backup directory"
# List of files to backup
local FILES_TO_BACKUP=(
"$HOME/.bashrc"
"$HOME/.termux/colors.properties"
"$HOME/.termux/termux.properties"
"$HOME/.termux/font.ttf"
#"$0"
)
# Copy files to backup directory
for FILE in "${FILES_TO_BACKUP[@]}"; do
if [ -f "$FILE" ]; then
execute_command "cp \"$FILE\" \"$BACKUP_DIR/\"" "Backup of $(basename "$FILE")"
fi
done
}
#------------------------------------------------------------------------------
# COMMON ALIAS CONFIGURATION
#------------------------------------------------------------------------------
common_alias() {
# Create the centralized alias file
if [ ! -d "$HOME/.config/OhMyTermux" ]; then
execute_command "mkdir -p \"$HOME/.config/OhMyTermux\"" "Create the configuration folder"
fi
ALIASES_FILE="$HOME/.config/OhMyTermux/aliases"
cat > "$ALIASES_FILE" << 'EOL'
# Navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
# Base commands
alias h="history"
alias q="exit"
alias c="clear"
alias md="mkdir"
alias rm="rm -rf"
alias s="source"
alias n="nano"
alias cm="chmod +x"
# Configuration
alias bashrc="nano $HOME/.bashrc"
alias zshrc="nano $HOME/.zshrc"
alias aliases="nano $HOME/.config/OhMyTermux/aliases"
alias help="cat $HOME/.config/OhMyTermux/help.md"
# Git
alias g="git"
alias gs="git status"
alias ga="git add"
alias gc="git commit -m"
alias gp="git push"
alias gl="git pull"
alias gd="git diff"
alias gb="git branch"
alias gco="git checkout"
alias gcl="git clone"
alias push="git pull && git add . && git commit -m 'mobile push' && git push"
# Termux
alias termux="termux-reload-settings"
alias storage="termux-setup-storage"
alias share="termux-share"
alias open="termux-open"
alias url="termux-open-url"
alias clip="termux-clipboard-set"
alias notification="termux-notification"
alias vibrate="termux-vibrate"
alias battery="termux-battery-status"
alias torch="termux-torch"
alias volume="termux-volume"
alias wifi="termux-wifi-connectioninfo"
alias tts="termux-tts-speak"
alias call="termux-telephony-call"
alias contact="termux-contact-list"
alias sms="termux-sms-send"
alias location="termux-location"
EOL
# Add the sourcing .bashrc
echo -e "\n# Source of custom aliases\n[ -f \"$ALIASES_FILE\" ] && . \"$ALIASES_FILE\"" >> "$BASHRC"
# The sourcing .zshrc is done in update_zshrc()
}
#------------------------------------------------------------------------------
# DOWNLOAD AND EXECUTE FUNCTION
#------------------------------------------------------------------------------
download_and_execute() {
local URL="$1"
local SCRIPT_NAME=$(basename "$URL")
local DESCRIPTION="${2:-$SCRIPT_NAME}"
shift 2
local EXEC_ARGS="$@"
# Check if the file already exists and delete it
[ -f "$SCRIPT_NAME" ] && rm "$SCRIPT_NAME"
# Download with curl in silent mode but with progress bar
#if ! curl -L --progress-bar -o "$SCRIPT_NAME" "$URL"; then
if ! curl -L -o "$SCRIPT_NAME" "$URL" 2>/dev/null; then
error_msg "Impossible de télécharger le script $DESCRIPTION"
return 1
fi
# Check if the file has been downloaded
if [ ! -f "$SCRIPT_NAME" ]; then
error_msg "The file $SCRIPT_NAME has not been created"
return 1
fi
# Make the script executable
if ! chmod +x "$SCRIPT_NAME"; then
error_msg "Impossible to make the script $DESCRIPTION executable"
return 1
fi
# Execute the script with the arguments
if ! ./"$SCRIPT_NAME" $EXEC_ARGS; then
error_msg "Error during the execution of the script $DESCRIPTION"
return 1
fi
return 0
}
#------------------------------------------------------------------------------
# REPOSITORY CHANGE
#------------------------------------------------------------------------------
change_repo() {
show_banner
if $USE_GUM; then
if gum_confirm "Change the repository mirror ?"; then
termux-change-repo
fi
else
printf "${COLOR_BLUE}Change the repository mirror ? (O/n) : ${COLOR_RESET}"
read -r -e -p "" -i "o" CHOICE
[[ "$CHOICE" =~ ^[oO]$ ]] && termux-change-repo
fi
}
#------------------------------------------------------------------------------
# STORAGE CONFIGURATION
#------------------------------------------------------------------------------
setup_storage() {
if [ ! -d "$HOME/storage" ]; then
show_banner
if $USE_GUM; then
if gum_confirm "Allow access to storage ?"; then
termux-setup-storage
fi
else
printf "${COLOR_BLUE}Allow access to storage ? (O/n) : ${COLOR_RESET}"
read -r -e -p "" -i "n" CHOICE
[[ "$CHOICE" =~ ^[oO]$ ]] && termux-setup-storage
fi
fi
}
#------------------------------------------------------------------------------
# TERMUX CONFIGURATION
#------------------------------------------------------------------------------
configure_termux() {
title_msg "❯ Termux configuration"
# Backup existing files
create_backups
TERMUX_DIR="$HOME/.termux"
# Colors.properties configuration
FILE_PATH="$TERMUX_DIR/colors.properties"
if [ ! -f "$FILE_PATH" ]; then
mkdir -p "$TERMUX_DIR"
cat > "$FILE_PATH" << 'EOL'
# https://github.com/Mayccoll/Gogh/blob/master/themes/argonaut.sh
background=#0e1019
foreground=#fffaf4
cursor=#fffaf4
color0=#232323
color1=#ff000f
color2=#8ce10b
color3=#ffb900
color4=#008df8
color5=#6d43a6
color6=#00d8eb
color7=#ffffff
color8=#444444
color9=#ff2740
color10=#abe15b
color11=#ffd242
color12=#0092ff
color13=#9a5feb
color14=#67fff0
color15=#ffffff
EOL
success_msg "✓ Argonaut theme installed"
fi
# Common alias configuration
common_alias
# Termux.properties configuration
FILE_PATH="$TERMUX_DIR/termux.properties"
if [ ! -f "$FILE_PATH" ]; then
execute_command "cat > \"$FILE_PATH\" << 'EOL'
allow-external-apps = true
use-black-ui = true
bell-character = ignore
fullscreen = true
EOL" "Termux.properties configuration"
else
execute_command "sed -i 's/^# allow-external-apps = true/allow-external-apps = true/' \"$FILE_PATH\" && \
sed -i 's/^# use-black-ui = true/use-black-ui = true/' \"$FILE_PATH\" && \
sed -i 's/^# bell-character = ignore/bell-character = ignore/' \"$FILE_PATH\" && \
sed -i 's/^# fullscreen = true/fullscreen = true/' \"$FILE_PATH\"" "Termux configuration"
fi
# Suppression of the login banner
execute_command "touch $HOME/.hushlogin" "Suppression of the login banner"
}
#------------------------------------------------------------------------------
# INITIAL CONFIGURATION
#------------------------------------------------------------------------------
initial_config() {
# Si on est en mode FULL_INSTALL, demander les identifiants au début
if $FULL_INSTALL; then
title_msg "❯ Debian PRoot configuration"
if [ -z "$PROOT_USERNAME" ]; then
if $USE_GUM; then
PROOT_USERNAME=$(gum input --placeholder "Enter the username for Debian PRoot")
PROOT_PASSWORD=$(gum input --password --placeholder "Enter the password for Debian PRoot")
else
printf "${COLOR_BLUE}Enter the username for Debian PRoot : ${COLOR_RESET}"
read -r PROOT_USERNAME
printf "${COLOR_BLUE}Enter the password for Debian PRoot : ${COLOR_RESET}"
read -r -s PROOT_PASSWORD
echo
fi
fi
fi
change_repo
# Update and upgrade packages preserving existing configurations
clear
show_banner
execute_command "pkg update -y -o Dpkg::Options::=\"--force-confold\"" "Update repositories"
execute_command "pkg upgrade -y -o Dpkg::Options::=\"--force-confold\"" "Upgrade packages"
setup_storage
if $USE_GUM; then
show_banner
if gum_confirm "Activate the recommended configuration ?"; then
configure_termux
fi
else
show_banner
printf "${COLOR_BLUE}Activate the recommended configuration ? (O/n) : ${COLOR_RESET}"
read -r -e -p "" -i "o" CHOICE
# Clear the previous line
tput cuu1 # Move up one line
tput el # Clear to the end of the line
[[ "$CHOICE" =~ ^[oO]$ ]] && configure_termux
fi
}
#------------------------------------------------------------------------------
# INSTALLATION OF THE SHELL
#------------------------------------------------------------------------------
install_shell() {
if $SHELL_CHOICE; then
title_msg "❯ Shell configuration"
if $USE_GUM; then
SHELL_CHOICE=$(gum_choose "Choose the shell to install :" --selected="zsh" --height=5 "bash" "zsh" "fish")
else
echo -e "${COLOR_BLUE}Choose the shell to install :${COLOR_RESET}"
echo
echo -e "${COLOR_BLUE}1) bash${COLOR_RESET}"
echo -e "${COLOR_BLUE}2) zsh${COLOR_RESET}"
echo -e "${COLOR_BLUE}3) fish${COLOR_RESET}"
echo
printf "${COLOR_GOLD}Enter your choice (1/2/3) : ${COLOR_RESET}"
tput setaf 3
read -r -e -p "" -i "2" CHOICE
tput sgr0
# Clear the selection menu
tput cuu 7 # Move up 7 lines
tput ed # Clear to the end of the screen
case $CHOICE in
1) SHELL_CHOICE="bash" ;;
2) SHELL_CHOICE="zsh" ;;
3) SHELL_CHOICE="fish" ;;
*) SHELL_CHOICE="bash" ;;
esac
fi
case $SHELL_CHOICE in
"bash")
success_msg "✓ Bash selected"
install_prompt
;;
"zsh")
if ! command -v zsh &> /dev/null; then
execute_command "pkg install -y zsh" "ZSH installation"
else
success_msg "✓ Zsh already installed"
fi
# Installation de Oh My Zsh et autres configurations ZSH
title_msg "❯ ZSH configuration"
if [ ! -d "$HOME/.oh-my-zsh" ]; then
if $USE_GUM; then
if gum_confirm "Install Oh-My-Zsh ?"; then
execute_command "pkg install -y wget curl git unzip" "Dependencies installation"
execute_command "git clone https://github.com/ohmyzsh/ohmyzsh.git \"$HOME/.oh-my-zsh\"" "Oh-My-Zsh installation"
cp "$HOME/.oh-my-zsh/templates/zshrc.zsh-template" "$ZSHRC"
fi
else
printf "${COLOR_BLUE}Installer Oh-My-Zsh ? (O/n) : ${COLOR_RESET}"
read -r -e -p "" -i "o" CHOICE
tput cuu1
tput el
if [[ "$CHOICE" =~ ^[oO]$ ]]; then
execute_command "pkg install -y wget curl git unzip" "Dependencies installation"
execute_command "git clone https://github.com/ohmyzsh/ohmyzsh.git \"$HOME/.oh-my-zsh\"" "Oh-My-Zsh installation"
cp "$HOME/.oh-my-zsh/templates/zshrc.zsh-template" "$ZSHRC"
fi
fi
else
success_msg "✓ Oh-My-Zsh already installed"
fi
execute_command "curl -fLo \"$ZSHRC\" https://raw.githubusercontent.com/GiGiDKR/OhMyTermux/dev/src/zshrc" "Default configuration" || error_msg "Default configuration impossible"
if command -v zsh &> /dev/null; then
install_zsh_plugins
install_prompt
else
echo -e "${COLOR_RED}ZSH is not installed. Impossible to install plugins.${COLOR_RESET}"
fi
chsh -s zsh
;;
"fish")
title_msg "❯ Fish configuration"
execute_command "pkg install -y fish" "Fish installation"
execute_command "mkdir -p $HOME/.config/fish/functions" "Create the fish directory"
# Installation of Fisher in non-interactive mode
execute_command "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish -o $HOME/.config/fish/functions/fisher.fish" "Download Fisher"
# Installation of Tide via Fisher in non-interactive mode
execute_command "fish -c 'source $HOME/.config/fish/functions/fisher.fish && fisher install IlanCosman/tide@v5'" "Tide installation"
chsh -s fish
;;
esac
fi
}
#------------------------------------------------------------------------------
# INSTALLATION OF THE PROMPT
#------------------------------------------------------------------------------
install_prompt() {
local PROMPT_CHOICE
local CURRENT_SHELL="${SHELL_CHOICE:-zsh}"
if [ "$CURRENT_SHELL" = "bash" ]; then
if $USE_GUM; then
PROMPT_CHOICE=$(gum_choose "Choose the prompt to install :" --height=4 --selected="Oh-My-Posh" "Oh-My-Posh" "Starship")
else
echo -e "${COLOR_BLUE}Choose the prompt to install :${COLOR_RESET}"
echo
echo -e "${COLOR_BLUE}1) Oh-My-Posh${COLOR_RESET}"
echo -e "${COLOR_BLUE}2) Starship${COLOR_RESET}"
echo
printf "${COLOR_GOLD}Enter your choice (1/2) : ${COLOR_RESET}"
tput setaf 3
read -r -e -p "" -i "1" CHOICE
tput sgr0
tput cuu 5
tput ed
case $CHOICE in
1) PROMPT_CHOICE="Oh-My-Posh" ;;
2) PROMPT_CHOICE="Starship" ;;
*) PROMPT_CHOICE="Oh-My-Posh" ;;
esac
fi
else
if $USE_GUM; then
PROMPT_CHOICE=$(gum_choose "Choose the prompt to install :" --height=5 --selected="PowerLevel10k" "PowerLevel10k" "Oh-My-Posh" "Starship")
else
echo -e "${COLOR_BLUE}Choose the prompt to install :${COLOR_RESET}"
echo
echo -e "${COLOR_BLUE}1) PowerLevel10k${COLOR_RESET}"
echo -e "${COLOR_BLUE}2) Oh-My-Posh${COLOR_RESET}"
echo -e "${COLOR_BLUE}3) Starship${COLOR_RESET}"
echo
printf "${COLOR_GOLD}Enter your choice (1/2/3) : ${COLOR_RESET}"
tput setaf 3
read -r -e -p "" -i "1" CHOICE
tput sgr0
tput cuu 7
tput ed
case $CHOICE in
1) PROMPT_CHOICE="PowerLevel10k" ;;
2) PROMPT_CHOICE="Oh-My-Posh" ;;
3) PROMPT_CHOICE="Starship" ;;
*) PROMPT_CHOICE="PowerLevel10k" ;;
esac
fi
fi
case $PROMPT_CHOICE in
"PowerLevel10k")
if $USE_GUM; then
if gum_confirm "Install PowerLevel10k ?"; then
execute_command "git clone --depth=1 https://github.com/romkatv/powerlevel10k.git \"$HOME/.oh-my-zsh/custom/themes/powerlevel10k\" || true" "Installation de PowerLevel10k"
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="powerlevel10k\/powerlevel10k"/' "$ZSHRC"
if gum_confirm "Install the custom prompt ?"; then
execute_command "curl -fLo \"$HOME/.p10k.zsh\" https://raw.githubusercontent.com/GiGiDKR/OhMyTermux/1.0.0/src/p10k.zsh" "Installation of the custom prompt" || error_msg "Impossible to install the custom prompt"
echo -e "\n# To customize the prompt, run \`p10k configure\` or edit ~/.p10k.zsh." >> "$ZSHRC"
echo "[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh" >> "$ZSHRC"
else
echo -e "${COLOR_BLUE}You can customize the prompt by running 'p10k configure'.${COLOR_RESET}"
fi
fi
else
printf "${COLOR_BLUE}Install PowerLevel10k ? (O/n) : ${COLOR_RESET}"
read -r -e -p "" -i "o" CHOICE
tput cuu1
tput el
if [[ "$CHOICE" =~ ^[oO]$ ]]; then
execute_command "git clone --depth=1 https://github.com/romkatv/powerlevel10k.git \"$HOME/.oh-my-zsh/custom/themes/powerlevel10k\" > /dev/null 2>&1 || true" "Installation de PowerLevel10k"
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="powerlevel10k\/powerlevel10k"/' "$ZSHRC"
printf "${COLOR_BLUE}Install the custom prompt ? (O/n) : ${COLOR_RESET}"
read -r -e -p "" -i "o" CHOICE
tput cuu1
tput el
if [[ "$CHOICE" =~ ^[oO]$ ]]; then
execute_command "curl -fLo \"$HOME/.p10k.zsh\" https://raw.githubusercontent.com/GiGiDKR/OhMyTermux/1.0.0/src/p10k.zsh" "Installation of the custom prompt" || error_msg "Impossible to install the custom prompt"
echo -e "\n# To customize the prompt, run \`p10k configure\` or edit ~/.p10k.zsh." >> "$ZSHRC"
echo "[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh" >> "$ZSHRC"
else
echo -e "${COLOR_BLUE}You can customize the prompt by running 'p10k configure'.${COLOR_RESET}"
fi
fi
fi
;;
"Oh-My-Posh")
execute_command "pkg install -y oh-my-posh" "Installation of Oh-My-Posh"
# Optional installation of a Nerd font
if [ ! -f "$HOME/.termux/font.ttf" ]; then
execute_command "curl -fLo \"$HOME/.termux/font.ttf\" --create-dirs https://raw.githubusercontent.com/termux/termux-styling/master/app/src/main/assets/fonts/DejaVu-Sans-Mono.ttf" "Installation of the Nerd font"
fi
# Retrieving the complete list of themes
THEMES_DIR="/data/data/com.termux/files/usr/share/oh-my-posh/themes"
if [ -d "$THEMES_DIR" ]; then
# Creating an array with all available themes
mapfile -t AVAILABLE_THEMES < <(find "$THEMES_DIR" -name "*.omp.json" -exec basename {} .omp.json \; | sort)
else
error_msg "Oh-My-Posh themes directory not found"
return 1
fi
# Theme selection
if $USE_GUM; then
THEME=$(printf '%s\n' "${AVAILABLE_THEMES[@]}" | gum_choose \
"Choose an Oh-My-Posh theme :" \
--height=25)
else
# Displaying the numbered list of themes
echo -e "${COLOR_BLUE}Choose an Oh-My-Posh theme :${COLOR_RESET}"
echo
for i in "${!AVAILABLE_THEMES[@]}"; do
# Formatting the number for alignment (3 characters)
NUM=$(printf "%3d" $((i+1)))
if [ "${AVAILABLE_THEMES[$i]}" = "jandedobbeleer" ]; then
echo -e "${COLOR_BLUE}${NUM}) ${AVAILABLE_THEMES[$i]} (default)${COLOR_RESET}"
else
echo -e "${COLOR_BLUE}${NUM}) ${AVAILABLE_THEMES[$i]}${COLOR_RESET}"
fi
done
echo
# Calculating the number of lines to clear (number of themes + 3 lines for additional text)
LINES_TO_CLEAR=$((${#AVAILABLE_THEMES[@]}+3))
printf "${COLOR_GOLD}Enter your choice (1/2/3) : ${COLOR_RESET}"
tput setaf 3
read -r -e -p "" -i "1" CHOICE
tput sgr0
# Clearing the menu
tput cuu $LINES_TO_CLEAR
tput ed
# Validating the choice
if [[ "$CHOICE" =~ ^[0-9]+$ ]] && [ "$CHOICE" -ge 1 ] && [ "$CHOICE" -le "${#AVAILABLE_THEMES[@]}" ]; then
THEME="${AVAILABLE_THEMES[$((CHOICE-1))]}"
else