Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
2548 lines (2280 loc) · 95.3 KB
/
Copy pathinstall.sh
File metadata and controls
2548 lines (2280 loc) · 95.3 KB
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
#------------------------------------------------------------------------------
# INTERNATIONALIZATION SYSTEM
#------------------------------------------------------------------------------
# Determine the script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
#------------------------------------------------------------------------------
# GLOBAL VARIABLES
#------------------------------------------------------------------------------
# GitHub branch for downloads
BRANCH="main"
# 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
# Desktop environment installation
DESKTOP_CHOICE=false
DESKTOP_ENV=""
# Debian Proot installation
PROOT_CHOICE=false
# Termux-X11 installation
X11_CHOICE=false
# AI Tools installation
AI_TOOLS_CHOICE=false
# Full installation without interactions
FULL_INSTALL=false
# Preset name argument
PRESET_NAME_ARG=""
# Use gum for interactions
ONLY_GUM=true
#------------------------------------------------------------------------------
# CONFIGURATION FILES
#------------------------------------------------------------------------------
BASHRC="$HOME/.bashrc"
ZSHRC="$HOME/.zshrc"
FISHRC="$HOME/.config/fish/config.fish"
#------------------------------------------------------------------------------
# BOOTSTRAP - Load i18n and lib systems
#------------------------------------------------------------------------------
OHMYTERMUX_REPO_URL="${OHMYTERMUX_REPO_URL:-https://raw.githubusercontent.com/devohmycode/OhMyTermux}"
_loader_url="$OHMYTERMUX_REPO_URL/$BRANCH/lib/i18n_loader.sh"
mkdir -p "$SCRIPT_DIR/lib"
# Always try to refresh i18n_loader.sh; fall back to cached version if download fails
_loader_tmp=$(mktemp 2>/dev/null || echo "$SCRIPT_DIR/lib/i18n_loader.sh.tmp")
if curl -fL -s -o "$_loader_tmp" "$_loader_url" 2>/dev/null && head -1 "$_loader_tmp" 2>/dev/null | grep -q "^#!/bin/bash"; then
mv "$_loader_tmp" "$SCRIPT_DIR/lib/i18n_loader.sh"
else
rm -f "$_loader_tmp" 2>/dev/null
if [ ! -f "$SCRIPT_DIR/lib/i18n_loader.sh" ]; then
echo "Warning: Could not download i18n_loader.sh and no cached version available" >&2
fi
fi
I18N_DEFER_INIT=true
source "$SCRIPT_DIR/lib/i18n_loader.sh"
# Configure error handler keys for this script
ERROR_MSG_KEY="MSG_ERROR_INSTALL"
ERROR_REFER_KEY="MSG_ERROR_REFER_MESSAGES"
# Download presets if not available locally
if [ ! -d "$SCRIPT_DIR/presets" ] || [ -z "$(ls "$SCRIPT_DIR/presets/"*.sh 2>/dev/null)" ]; then
type download_presets &>/dev/null && download_presets
fi
# Initialize plugin system (discover manifests, resolve order)
type init_plugin_system &>/dev/null && init_plugin_system
# Configure banner title (uses i18n key)
BANNER_TITLE="" # Will be set after i18n init via t()
#------------------------------------------------------------------------------
# UNINSTALL PROOT
#------------------------------------------------------------------------------
uninstall_proot() {
if [ "$MESSAGES_LOADED" != "true" ]; then
init_i18n "$OVERRIDE_LANG" >/dev/null 2>&1
fi
if ! command -v proot-distro &>/dev/null; then
echo "proot-distro is not installed." >&2
exit 1
fi
if [ ! -d "$PROOT_DEBIAN_ROOT" ]; then
echo "Debian PRoot is not installed." >&2
exit 1
fi
echo "This will remove the Debian PRoot installation and all its data."
printf "Are you sure? (y/N): "
read -r CONFIRM
if [[ ! "$CONFIRM" =~ ^[yYoO]$ ]]; then
echo "Uninstall cancelled."
exit 0
fi
# Remove proot-distro installation
proot-distro remove debian || {
echo "Error: Failed to remove Debian PRoot." >&2
exit 1
}
# Remove helper scripts
for CMD in prun zrun zrunhud cp2menu; do
rm -f "$PREFIX/bin/$CMD"
done
# Remove related desktop files
rm -f "$PREFIX/share/applications/cp2menu.desktop"
rm -f "$PREFIX/share/applications/kill_termux_x11.desktop"
echo "Debian PRoot has been successfully uninstalled."
}
#------------------------------------------------------------------------------
# DISPLAY HELP
#------------------------------------------------------------------------------
show_help() {
# Initialiser le système i18n si pas encore fait
if [ "$MESSAGES_LOADED" != "true" ]; then
init_i18n "$OVERRIDE_LANG" >/dev/null 2>&1
fi
clear
echo "$(t MSG_HELP_TITLE)"
echo
echo "$(t MSG_HELP_USAGE)"
echo "$(t MSG_HELP_OPTIONS)"
echo " --gum | -g $(t MSG_OPT_GUM)"
echo " --verbose | -v $(t MSG_OPT_VERBOSE)"
echo " --lang | -l $(t MSG_OPT_LANG)"
echo " --shell | -sh $(t MSG_OPT_SHELL)"
echo " --package | -pk $(t MSG_OPT_PACKAGE)"
echo " --ai | -ai $(t MSG_OPT_AI)"
echo " --font | -f $(t MSG_OPT_FONT)"
echo " --xfce | -x $(t MSG_OPT_XFCE)"
echo " --desktop | -de $(t MSG_OPT_DESKTOP)"
echo " --proot | -pr $(t MSG_OPT_PROOT)"
echo " --x11 $(t MSG_OPT_X11)"
echo " --preset | -ps $(t MSG_OPT_PRESET)"
echo " --skip $(t MSG_OPT_SKIP)"
echo " --uninstall $(t MSG_OPT_UNINSTALL)"
echo " --full $(t MSG_OPT_FULL)"
echo " --help | -h $(t MSG_OPT_HELP)"
echo
echo "$(t MSG_HELP_EXAMPLES)"
echo " $(t MSG_EXAMPLE_GUM)"
echo " $(t MSG_EXAMPLE_FULL)"
type show_plugin_help &>/dev/null && show_plugin_help
}
#------------------------------------------------------------------------------
# ARGUMENTS MANAGEMENT
#------------------------------------------------------------------------------
# Pre-parse plugin CLI flags
if type parse_plugin_args &>/dev/null; then
parse_plugin_args "$@"
set -- "${REMAINING_ARGS[@]}"
fi
while [[ $# -gt 0 ]]; do
case $1 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
;;
--ai|-ai)
AI_TOOLS_CHOICE=true
ONLY_GUM=false
shift
;;
--font|-f)
FONT_CHOICE=true
ONLY_GUM=false
shift
;;
--xfce|-x)
DESKTOP_CHOICE=true
DESKTOP_ENV="xfce"
ONLY_GUM=false
shift
;;
--desktop|-de)
DESKTOP_CHOICE=true
ONLY_GUM=false
shift
if [ -n "$1" ] && [[ "$1" =~ ^(xfce|lxqt|mate)$ ]]; then
DESKTOP_ENV="$1"
shift
fi
;;
--proot|-pr)
PROOT_CHOICE=true
ONLY_GUM=false
shift
;;
--x11)
X11_CHOICE=true
ONLY_GUM=false
shift
;;
--preset|-ps)
shift
if [ -n "$1" ]; then
PRESET_NAME_ARG="$1"
PACKAGES_CHOICE=true
ONLY_GUM=false
shift
else
echo "$(t MSG_ERROR_PRESET_ARGUMENT)" >&2
exit 1
fi
;;
--skip)
EXECUTE_INITIAL_CONFIG=false
shift
;;
--uninstall)
uninstall_proot
exit 0
;;
--verbose|-v)
VERBOSE=true
REDIRECT=""
shift
;;
--lang|-l)
shift
if [ -n "$1" ]; then
OVERRIDE_LANG="$1"
shift
else
echo "$(t MSG_ERROR_LANG_ARGUMENT)" >&2
exit 1
fi
;;
--full)
FULL_INSTALL=true
SHELL_CHOICE=true
PACKAGES_CHOICE=true
AI_TOOLS_CHOICE=true
FONT_CHOICE=true
DESKTOP_CHOICE=true
DESKTOP_ENV="xfce"
PROOT_CHOICE=true
X11_CHOICE=true
SCRIPT_CHOICE=true
ONLY_GUM=false
type enable_all_plugins &>/dev/null && enable_all_plugins
shift
;;
--help|-h)
show_help
exit 0
;;
*)
# Get the username and password if provided
if [ -z "$PROOT_USERNAME" ]; then
PROOT_USERNAME="$1"
elif [ -z "$PROOT_PASSWORD" ]; then
PROOT_PASSWORD="$1"
else
break
fi
shift
;;
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 "$(t MSG_INFO_ENTER_USERNAME_PROOT)")
else
printf "${COLOR_BLUE}$(t MSG_INFO_ENTER_USERNAME_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 "$(t MSG_INFO_PASSWORD)")
PASSWORD_CONFIRM=$(gum input --password --prompt "Confirm password: " --placeholder "$(t MSG_INFO_CONFIRM_PASSWORD)")
else
printf "${COLOR_BLUE}$(t MSG_INFO_PASSWORD) ${COLOR_RESET}"
read -r -s PROOT_PASSWORD
echo
printf "${COLOR_BLUE}$(t MSG_INFO_CONFIRM_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 "$(t MSG_ERROR_PASSWORD_MISMATCH)"
else
echo -e "${COLOR_RED}$(t MSG_ERROR_PASSWORD_MISMATCH)${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
AI_TOOLS_CHOICE=true
FONT_CHOICE=true
DESKTOP_CHOICE=true
PROOT_CHOICE=true
X11_CHOICE=true
SCRIPT_CHOICE=true
fi
# Initialisation du système d'internationalisation
if ! init_i18n "$OVERRIDE_LANG"; then
echo "Warning: Problem during i18n system initialization. Using default messages." >&2
fi
# Fallback: force-load messages if i18n system failed
if [ "$MESSAGES_LOADED" != "true" ]; then
for _msg_path in "$SCRIPT_DIR/i18n/messages" "$(dirname "${BASH_SOURCE[0]}")/i18n/messages"; do
if [ -f "$_msg_path/en.sh" ]; then
source "$_msg_path/en.sh"
MESSAGES_LOADED=true
CURRENT_LANGUAGE="en"
break
fi
done
# Redefine t() to use indirect variable lookup if the fallback t() is active
if [ "$MESSAGES_LOADED" = "true" ]; then
t() {
local key="$1"
local default="$2"
local val="${!key}"
echo "${val:-${default:-$key}}"
}
fi
fi
# Set banner title now that i18n is initialized
BANNER_TITLE="$(t MSG_BANNER_TITLE)"
# Load plugin translations and resolve dependencies
type load_all_plugin_i18n &>/dev/null && load_all_plugin_i18n
type check_plugin_dependencies &>/dev/null && check_plugin_dependencies
#------------------------------------------------------------------------------
# GUM INSTALLATION
#------------------------------------------------------------------------------
check_and_install_gum() {
if $USE_GUM && ! command -v gum &> /dev/null; then
bash_banner
echo -e "${COLOR_BLUE}$(t MSG_INSTALL_GUM)${COLOR_RESET}"
pkg update -y > /dev/null 2>&1 && pkg install gum -y > /dev/null 2>&1
fi
}
check_and_install_gum
trap finish EXIT
# Show interactive plugin selection if no plugin was pre-selected via CLI
if ! $FULL_INSTALL; then
type show_plugin_selection_gum &>/dev/null && show_plugin_selection_gum
fi
#------------------------------------------------------------------------------
# GRAPHIC BANNER (override for install.sh - uses i18n title)
#------------------------------------------------------------------------------
show_banner() {
# Initialiser le système i18n si pas encore fait
if [ "$MESSAGES_LOADED" != "true" ]; then
init_i18n "$OVERRIDE_LANG" >/dev/null 2>&1
fi
clear
if $USE_GUM; then
gum style \
--foreground 33 \
--border-foreground 33 \
--border double \
--align center \
--width 42 \
--margin "1 1 1 0" \
"" "$(t MSG_BANNER_TITLE)" ""
else
bash_banner
fi
}
#------------------------------------------------------------------------------
# FILE BACKUP
#------------------------------------------------------------------------------
create_backups() {
local BACKUP_DIR="$OHMYTERMUX_CONFIG_DIR/backups"
# Create the backup directory
execute_command "mkdir -p \"$BACKUP_DIR\"" "$(t MSG_PROGRESS_CREATE_BACKUP_DIR)"
# 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/\"" "$(t MSG_PROGRESS_BACKUP_FILE) $(basename "$FILE")"
fi
done
}
#------------------------------------------------------------------------------
# COMMON ALIAS CONFIGURATION
#------------------------------------------------------------------------------
common_alias() {
# Create the centralized alias file
if [ ! -d "$OHMYTERMUX_CONFIG_DIR" ]; then
execute_command "mkdir -p \"$OHMYTERMUX_CONFIG_DIR\"" "$(t MSG_PROGRESS_CREATE_CONFIG_FOLDER)"
fi
ALIASES_FILE="$OHMYTERMUX_CONFIG_DIR/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 $OHMYTERMUX_CONFIG_DIR/aliases"
alias help="cat $OHMYTERMUX_CONFIG_DIR/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="$@"
# Use local file if available in SCRIPT_DIR, otherwise download
if [ -f "$SCRIPT_DIR/$SCRIPT_NAME" ] && head -1 "$SCRIPT_DIR/$SCRIPT_NAME" 2>/dev/null | grep -q "^#!/bin/bash"; then
cp "$SCRIPT_DIR/$SCRIPT_NAME" "$SCRIPT_NAME"
else
# Check if the file already exists and delete it
[ -f "$SCRIPT_NAME" ] && rm "$SCRIPT_NAME"
# Download with curl in silent mode
if ! curl -fL -o "$SCRIPT_NAME" "$URL" 2>/dev/null; then
error_msg "$(t MSG_ERROR_DOWNLOAD_SCRIPT) $DESCRIPTION"
return 1
fi
fi
# Check if the file has been downloaded
if [ ! -f "$SCRIPT_NAME" ]; then
error_msg "$(t MSG_ERROR_FILE_NOT_CREATED_GENERIC) $SCRIPT_NAME"
return 1
fi
# Make the script executable
if ! chmod +x "$SCRIPT_NAME"; then
error_msg "$(t MSG_ERROR_MAKE_EXECUTABLE) $DESCRIPTION"
return 1
fi
# Execute the script with the arguments, passing --lang if set
local LANG_ARG=""
if [ -n "$OVERRIDE_LANG" ]; then
LANG_ARG="--lang $OVERRIDE_LANG"
fi
if ! ./"$SCRIPT_NAME" $LANG_ARG $EXEC_ARGS; then
error_msg "$(t MSG_ERROR_SCRIPT_EXECUTION) $DESCRIPTION"
return 1
fi
return 0
}
#------------------------------------------------------------------------------
# REPOSITORY CHANGE
#------------------------------------------------------------------------------
change_repo() {
show_banner
if $USE_GUM; then
if gum_confirm "$(t MSG_CONFIRM_CHANGE_REPO)"; then
termux-change-repo
fi
else
read -r -e -p "$(rl_prompt "${COLOR_BLUE}" "$(t MSG_CONFIRM_CHANGE_REPO) (O/n) : ")" -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 "$(t MSG_CONFIRM_ALLOW_STORAGE)"; then
termux-setup-storage
fi
else
read -r -e -p "$(rl_prompt "${COLOR_BLUE}" "$(t MSG_CONFIRM_ALLOW_STORAGE) (O/n) : ")" -i "n" CHOICE
[[ "$CHOICE" =~ ^[oO]$ ]] && termux-setup-storage
fi
fi
}
#------------------------------------------------------------------------------
# TERMUX CONFIGURATION
#------------------------------------------------------------------------------
configure_termux() {
title_msg "$(t MSG_CONFIG_TERMUX)"
# 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 "$(t MSG_SUCCESS_ARGONAUT)"
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" "$(t MSG_PROGRESS_TERMUX_PROPERTIES_CONFIG)"
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\"" "$(t MSG_CONFIG_TERMUX_PROPS)"
fi
# Suppression of the login banner
execute_command "touch $HOME/.hushlogin" "$(t MSG_PROGRESS_SUPPRESS_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 "$(t MSG_CONFIG_PROOT)"
if [ -z "$PROOT_USERNAME" ]; then
if $USE_GUM; then
PROOT_USERNAME=$(gum input --placeholder "$(t MSG_INFO_ENTER_USERNAME_PROOT)")
PROOT_PASSWORD=$(gum input --password --placeholder "$(t MSG_INFO_ENTER_PASSWORD_PROOT)")
else
printf "${COLOR_BLUE}$(t MSG_INFO_ENTER_USERNAME_PROOT) ${COLOR_RESET}"
read -r PROOT_USERNAME
printf "${COLOR_BLUE}$(t MSG_INFO_ENTER_PASSWORD_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\"" "$(t MSG_PROGRESS_UPDATE_REPOS)"
execute_command "pkg upgrade -y -o Dpkg::Options::=\"--force-confold\"" "$(t MSG_PROGRESS_UPGRADE_PACKAGES)"
setup_storage
if $USE_GUM; then
show_banner
if gum_confirm "$(t MSG_CONFIRM_ACTIVATE_CONFIG)"; then
configure_termux
fi
else
show_banner
read -r -e -p "$(rl_prompt "${COLOR_BLUE}" "$(t MSG_CONFIRM_ACTIVATE_CONFIG) (O/n) : ")" -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 "$(t MSG_SHELL_CONFIG_TITLE)"
if $USE_GUM; then
SHELL_CHOICE=$(gum_choose "$(t MSG_CHOOSE_SHELL_PROMPT)" --selected="zsh" --height=5 "bash" "zsh" "fish")
else
echo -e "${COLOR_BLUE}$(t MSG_CHOOSE_SHELL_PROMPT)${COLOR_RESET}"
echo
echo -e "${COLOR_BLUE}$(t MSG_BASH_OPTION)${COLOR_RESET}"
echo -e "${COLOR_BLUE}$(t MSG_ZSH_OPTION)${COLOR_RESET}"
echo -e "${COLOR_BLUE}$(t MSG_FISH_OPTION)${COLOR_RESET}"
echo
read -r -e -p "$(rl_prompt "${COLOR_GOLD}" "$(t MSG_ENTER_SHELL_CHOICE) " "${COLOR_INPUT}")" -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 "$(t MSG_BASH_SELECTED)"
install_prompt
;;
"zsh")
if ! command -v zsh &> /dev/null; then
execute_command "pkg install -y zsh" "$(t MSG_INSTALL_ZSH)"
else
success_msg "$(t MSG_ZSH_ALREADY_INSTALLED)"
fi
# Installation de Oh My Zsh et autres configurations ZSH
title_msg "$(t MSG_ZSH_CONFIG_TITLE)"
if [ ! -d "$HOME/.oh-my-zsh" ]; then
if $USE_GUM; then
if gum_confirm "$(t MSG_CONFIRM_INSTALL_OHMYZSH)"; then
execute_command "pkg install -y wget curl git unzip" "$(t MSG_INSTALL_DEPENDENCIES)"
execute_command "git clone https://github.com/ohmyzsh/ohmyzsh.git \"$HOME/.oh-my-zsh\"" "$(t MSG_INSTALL_OHMYZSH_PROGRESS)"
cp "$HOME/.oh-my-zsh/templates/zshrc.zsh-template" "$ZSHRC"
fi
else
read -r -e -p "$(rl_prompt "${COLOR_BLUE}" "$(t MSG_CONFIRM_INSTALL_OHMYZSH) (O/n) : ")" -i "o" CHOICE
tput cuu1
tput el
if [[ "$CHOICE" =~ ^[oO]$ ]]; then
execute_command "pkg install -y wget curl git unzip" "$(t MSG_INSTALL_DEPENDENCIES)"
execute_command "git clone https://github.com/ohmyzsh/ohmyzsh.git \"$HOME/.oh-my-zsh\"" "$(t MSG_INSTALL_OHMYZSH_PROGRESS)"
cp "$HOME/.oh-my-zsh/templates/zshrc.zsh-template" "$ZSHRC"
fi
fi
else
success_msg "$(t MSG_OHMYZSH_ALREADY_INSTALLED)"
fi
execute_command "curl -fLo \"$ZSHRC\" $OHMYTERMUX_REPO_URL/$BRANCH/src/zshrc" "$(t MSG_DEFAULT_CONFIG_PROGRESS)" || error_msg "$(t MSG_ERROR_DEFAULT_CONFIG)"
if command -v zsh &> /dev/null; then
install_zsh_plugins
install_prompt
else
echo -e "${COLOR_RED}$(t MSG_ZSH_NOT_INSTALLED_ERROR)${COLOR_RESET}"
fi
chsh -s zsh
;;
"fish")
title_msg "$(t MSG_FISH_CONFIG_TITLE)"
execute_command "pkg install -y fish" "$(t MSG_FISH_INSTALLATION)"
execute_command "mkdir -p $HOME/.config/fish/functions" "$(t MSG_CREATE_FISH_DIR)"
# 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" "$(t MSG_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'" "$(t MSG_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 "$(t MSG_CHOOSE_PROMPT_BASH)" --height=4 --selected="Oh-My-Posh" "Oh-My-Posh" "Starship")
else
echo -e "${COLOR_BLUE}$(t MSG_CHOOSE_PROMPT_BASH)${COLOR_RESET}"
echo
echo -e "${COLOR_BLUE}$(t MSG_OHMYPOSH_OPTION_BASH)${COLOR_RESET}"
echo -e "${COLOR_BLUE}$(t MSG_STARSHIP_OPTION_BASH)${COLOR_RESET}"
echo
read -r -e -p "$(rl_prompt "${COLOR_GOLD}" "$(t MSG_ENTER_PROMPT_CHOICE_BASH) " "${COLOR_INPUT}")" -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 "$(t MSG_CHOOSE_PROMPT)" --height=5 --selected="PowerLevel10k" "PowerLevel10k" "Oh-My-Posh" "Starship")
else
echo -e "${COLOR_BLUE}$(t MSG_CHOOSE_PROMPT)${COLOR_RESET}"
echo
echo -e "${COLOR_BLUE}$(t MSG_POWERLEVEL10K_OPTION)${COLOR_RESET}"
echo -e "${COLOR_BLUE}$(t MSG_OHMYPOSH_OPTION)${COLOR_RESET}"
echo -e "${COLOR_BLUE}$(t MSG_STARSHIP_OPTION)${COLOR_RESET}"
echo
read -r -e -p "$(rl_prompt "${COLOR_GOLD}" "$(t MSG_ENTER_PROMPT_CHOICE) " "${COLOR_INPUT}")" -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 "$(t MSG_CONFIRM_POWERLEVEL10K)"; then
execute_command "git clone --depth=1 https://github.com/romkatv/powerlevel10k.git \"$HOME/.oh-my-zsh/custom/themes/powerlevel10k\" || true" "$(t MSG_INSTALL_POWERLEVEL10K_PROGRESS)"
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="powerlevel10k\/powerlevel10k"/' "$ZSHRC"
if gum_confirm "$(t MSG_CONFIRM_INSTALL_CUSTOM_PROMPT)"; then
execute_command "curl -fLo \"$HOME/.p10k.zsh\" $OHMYTERMUX_REPO_URL/$BRANCH/src/p10k.zsh" "$(t MSG_INSTALL_CUSTOM_PROMPT)" || error_msg "$(t MSG_ERROR_CUSTOM_PROMPT)"
echo -e "\n$(t MSG_CUSTOM_PROMPT_COMMENT)" >> "$ZSHRC"
echo "[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh" >> "$ZSHRC"
else
echo -e "${COLOR_BLUE}$(t MSG_CUSTOMIZE_P10K_INFO)${COLOR_RESET}"
fi
fi
else
read -r -e -p "$(rl_prompt "${COLOR_BLUE}" "$(t MSG_CONFIRM_POWERLEVEL10K) (O/n) : ")" -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" "$(t MSG_INSTALL_POWERLEVEL10K_PROGRESS)"
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="powerlevel10k\/powerlevel10k"/' "$ZSHRC"
read -r -e -p "$(rl_prompt "${COLOR_BLUE}" "$(t MSG_CONFIRM_INSTALL_CUSTOM_PROMPT) (O/n) : ")" -i "o" CHOICE
tput cuu1
tput el
if [[ "$CHOICE" =~ ^[oO]$ ]]; then
execute_command "curl -fLo \"$HOME/.p10k.zsh\" $OHMYTERMUX_REPO_URL/$BRANCH/src/p10k.zsh" "$(t MSG_INSTALL_CUSTOM_PROMPT)" || error_msg "$(t MSG_ERROR_CUSTOM_PROMPT)"
echo -e "\n$(t MSG_CUSTOM_PROMPT_COMMENT)" >> "$ZSHRC"
echo "[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh" >> "$ZSHRC"
else
echo -e "${COLOR_BLUE}$(t MSG_CUSTOMIZE_P10K_INFO)${COLOR_RESET}"
fi
fi
fi
;;
"Oh-My-Posh")
execute_command "pkg install -y oh-my-posh" "$(t MSG_INSTALL_OHMYPOSH_PROGRESS)"
# 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" "$(t MSG_INSTALL_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 \
"$(t MSG_CHOOSE_OHMYPOSH_THEME)" \
--height=25)
else
# Displaying the numbered list of themes
echo -e "${COLOR_BLUE}$(t MSG_CHOOSE_OHMYPOSH_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]} $(t MSG_DEFAULT_THEME)${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))
read -r -e -p "$(rl_prompt "${COLOR_GOLD}" "$(t MSG_ENTER_CHOICE_123) " "${COLOR_INPUT}")" -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
THEME="jandedobbeleer"
fi
fi
# Configuration for ZSH
if [ ! -f "$ZSHRC" ]; then
touch "$ZSHRC"
fi
sed -i '/# Initialize oh-my-posh/d' "$ZSHRC"
sed -i '/eval "$(oh-my-posh init/d' "$ZSHRC"
cat >> "$ZSHRC" << EOF
# Initialize oh-my-posh
eval "\$(oh-my-posh init zsh --config /data/data/com.termux/files/usr/share/oh-my-posh/themes/${THEME}.omp.json)"
EOF
# Configuration for Bash
if [ ! -f "$HOME/.bashrc" ]; then
touch "$HOME/.bashrc"
fi
sed -i '/# Initialize oh-my-posh/d' "$HOME/.bashrc"
sed -i '/eval "$(oh-my-posh init/d' "$HOME/.bashrc"
cat >> "$HOME/.bashrc" << EOF
# Initialize oh-my-posh
eval "\$(oh-my-posh init bash --config /data/data/com.termux/files/usr/share/oh-my-posh/themes/${THEME}.omp.json)"
EOF
;;
"Starship")
execute_command "pkg install -y starship" "$(t MSG_INSTALL_STARSHIP_PROGRESS)"
# 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" "$(t MSG_INSTALL_NERD_FONT)"
fi
# Creating the configuration directory if it doesn't exist
mkdir -p "$HOME/.config"
# Preset selection
if $USE_GUM; then
PRESET=$(gum_choose "$(t MSG_CHOOSE_STARSHIP_PRESET)" --height=15 --selected="$(t PRESET_CUSTOM)" \
"$(t PRESET_CUSTOM)" \
"$(t PRESET_NERD_FONT_SYMBOLS)" \
"$(t PRESET_BRACKETED_SEGMENTS)" \
"$(t PRESET_NO_EMPTY_ICONS)" \
"$(t PRESET_NO_RUNTIME_VERSIONS)" \
"$(t PRESET_PLAIN_TEXT_SYMBOLS)" \
"$(t PRESET_PASTEL_POWERLINE)" \
"$(t PRESET_TOKYO_NIGHT)" \