-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall.fr.sh
2024 lines (1820 loc) · 74.9 KB
/
install.fr.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
#------------------------------------------------------------------------------
# VARIABLES GLOBALES
#------------------------------------------------------------------------------
# Interface interactive avec gum
USE_GUM=false
# Configuration initiale
EXECUTE_INITIAL_CONFIG=true
# Sortie détaillée
VERBOSE=false
# Variables pour Debian PRoot
PROOT_USERNAME=""
PROOT_PASSWORD=""
#------------------------------------------------------------------------------
# SELECTEURS DE MODULES
#------------------------------------------------------------------------------
# Sélection du shell
SHELL_CHOICE=false
# Installation de paquets additionnels
PACKAGES_CHOICE=false
# Installation de polices personnalisées
FONT_CHOICE=false
# Installation de l'environnement XFCE
XFCE_CHOICE=false
# Installation de Debian Proot
PROOT_CHOICE=false
# Installation de Termux-X11
X11_CHOICE=false
# Installation complète sans interactions
FULL_INSTALL=false
# Utilisation de gum pour les interactions
ONLY_GUM=true
#------------------------------------------------------------------------------
# FICHIERS DE CONFIGURATION
#------------------------------------------------------------------------------
BASHRC="$HOME/.bashrc"
ZSHRC="$HOME/.zshrc"
FISHRC="$HOME/.config/fish/config.fish"
#------------------------------------------------------------------------------
# COULEURS D'AFFICHAGE
#------------------------------------------------------------------------------
COLOR_BLUE='\033[38;5;33m' # Information
COLOR_GREEN='\033[38;5;82m' # Succès
COLOR_GOLD='\033[38;5;220m' # Avertissement
COLOR_RED='\033[38;5;196m' # Erreur
COLOR_RESET='\033[0m' # Réinitialisation
#------------------------------------------------------------------------------
# REDIRECTION
#------------------------------------------------------------------------------
if [ "$VERBOSE" = false ]; then
REDIRECT="> /dev/null 2>&1"
else
REDIRECT=""
fi
#------------------------------------------------------------------------------
# AFFICHAGE DE L'AIDE
#------------------------------------------------------------------------------
show_help() {
clear
echo "Aide OhMyTermux"
echo
echo "Usage: $0 [OPTIONS] [username] [password]"
echo "Options:"
echo " --gum | -g Utiliser gum pour l'interface utilisateur"
echo " --verbose | -v Afficher les sorties détaillées"
echo " --shell | -sh Module d'installation du shell"
echo " --package | -pk Module d'installation des packages"
echo " --font | -f Module d'installation de la police"
echo " --xfce | -x Module d'installation de XFCE"
echo " --proot | -pr Module d'installation de Debian PRoot"
echo " --x11 Module d'installation de Termux-X11"
echo " --skip Ignorer la configuration initiale"
echo " --uninstall Désinstallation de Debian Proot"
echo " --full Installer tous les modules sans confirmation"
echo " --help | -h Afficher ce message d'aide"
echo
echo "Exemples:"
echo " $0 --gum # Installation interactive avec gum"
echo " $0 --full user pass # Installation complète avec identifiants"
}
#------------------------------------------------------------------------------
# GESTION DES ARGUMENTS
#------------------------------------------------------------------------------
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
;;
*)
# Récupérer le nom d'utilisateur et le mot de passe s'ils sont fournis
if [ -z "$PROOT_USERNAME" ]; then
PROOT_USERNAME="$ARG"
shift
elif [ -z "$PROOT_PASSWORD" ]; then
PROOT_PASSWORD="$ARG"
shift
else
break
fi
;;
esac
done
# Si on est en mode FULL_INSTALL et que les identifiants ne sont pas fournis, les demander
if $FULL_INSTALL; then
if [ -z "$PROOT_USERNAME" ]; then
if $USE_GUM; then
PROOT_USERNAME=$(gum input --placeholder "Entrez le nom d'utilisateur pour Debian PRoot")
else
printf "${COLOR_BLUE}Entrez le nom d'utilisateur pour 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 "Entrer un mot de passe")
PASSWORD_CONFIRM=$(gum input --password --prompt "Confirm password: " --placeholder "Confirmer le mot de passe")
else
printf "${COLOR_BLUE}Entrer un mot de passe: ${COLOR_RESET}"
read -r -s PROOT_PASSWORD
echo
printf "${COLOR_BLUE}Confirmer le mot de passe: ${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 "Les mots de passe ne correspondent pas. Veuillez réessayer."
else
echo -e "${COLOR_RED}Les mots de passe ne correspondent pas. Veuillez réessayer.${COLOR_RESET}"
fi
fi
done
fi
fi
# Activation de tous les modules si --gum est le seul 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
#------------------------------------------------------------------------------
# MESSAGES D'INFORMATION
#------------------------------------------------------------------------------
info_msg() {
if $USE_GUM; then
gum style "${1//$'\n'/ }" --foreground 33
else
echo -e "${COLOR_BLUE}$1${COLOR_RESET}"
fi
}
#------------------------------------------------------------------------------
# MESSAGES DE SUCCÈS
#------------------------------------------------------------------------------
success_msg() {
if $USE_GUM; then
gum style "${1//$'\n'/ }" --foreground 82
else
echo -e "${COLOR_GREEN}$1${COLOR_RESET}"
fi
}
#------------------------------------------------------------------------------
# MESSAGES D'ERREUR
#------------------------------------------------------------------------------
error_msg() {
if $USE_GUM; then
gum style "${1//$'\n'/ }" --foreground 196
else
echo -e "${COLOR_RED}$1${COLOR_RESET}"
fi
}
#------------------------------------------------------------------------------
# MESSAGES DE TITRE
#------------------------------------------------------------------------------
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
}
#------------------------------------------------------------------------------
# MESSAGES DE SOUS-TITRE
#------------------------------------------------------------------------------
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
}
#------------------------------------------------------------------------------
# JOURNALISATION DES ERREURS
#------------------------------------------------------------------------------
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"
}
#------------------------------------------------------------------------------
# AFFICHAGE DYNAMIQUE DU RÉSULTAT D'UNE COMMANDE
#------------------------------------------------------------------------------
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
}
#------------------------------------------------------------------------------
# CONFIRMATION GUM
#------------------------------------------------------------------------------
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
}
#------------------------------------------------------------------------------
# SÉLECTION GUM UNIQUE
#------------------------------------------------------------------------------
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
# Retourner la première option par défaut
echo "${OPTIONS[0]}"
fi
else
gum choose --selected.foreground="33" --header.foreground="33" --cursor.foreground="33" --height="$HEIGHT" --header="$PROMPT" --selected="$SELECTED" "${OPTIONS[@]}"
fi
}
#------------------------------------------------------------------------------
# SÉLECTION GUM MULTIPLE
#------------------------------------------------------------------------------
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
}
#------------------------------------------------------------------------------
# AFFICHAGE DE LA BANNIERE EN MODE TEXTE
#------------------------------------------------------------------------------
bash_banner() {
clear
local BANNER="
╔════════════════════════════════════════╗
║ ║
║ OHMYTERMUX ║
║ ║
╚════════════════════════════════════════╝"
echo -e "${COLOR_BLUE}${BANNER}${COLOR_RESET}\n"
}
#------------------------------------------------------------------------------
# INSTALLATION DE GUM
#------------------------------------------------------------------------------
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
#------------------------------------------------------------------------------
# GESTION DES ERREURS
#------------------------------------------------------------------------------
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
#------------------------------------------------------------------------------
# AFFICHAGE DE LA BANNIERE EN MODE GRAPHIQUE
#------------------------------------------------------------------------------
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
}
#------------------------------------------------------------------------------
# SAUVEGARDE DES FICHIERS
#------------------------------------------------------------------------------
create_backups() {
local BACKUP_DIR="$HOME/.config/OhMyTermux/backups"
# Création du répertoire de sauvegarde
execute_command "mkdir -p \"$BACKUP_DIR\"" "Création du répertoire de sauvegarde"
# Liste des fichiers à sauvegarder
local FILES_TO_BACKUP=(
"$HOME/.bashrc"
"$HOME/.termux/colors.properties"
"$HOME/.termux/termux.properties"
"$HOME/.termux/font.ttf"
#"$0"
)
# Copie des fichiers dans le répertoire de sauvegarde
for FILE in "${FILES_TO_BACKUP[@]}"; do
if [ -f "$FILE" ]; then
execute_command "cp \"$FILE\" \"$BACKUP_DIR/\"" "Sauvegarde de $(basename "$FILE")"
fi
done
}
#------------------------------------------------------------------------------
# CONFIGURATION DES ALIAS COMMUNS
#------------------------------------------------------------------------------
common_alias() {
# Création du fichier d'alias centralisé
if [ ! -d "$HOME/.config/OhMyTermux" ]; then
execute_command "mkdir -p \"$HOME/.config/OhMyTermux\"" "Création du dossier de configuration"
fi
ALIASES_FILE="$HOME/.config/OhMyTermux/aliases"
cat > "$ALIASES_FILE" << 'EOL'
# Navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
# Commandes de base
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
# Ajout du sourcing .bashrc
echo -e "\n# Source des alias personnalisés\n[ -f \"$ALIASES_FILE\" ] && . \"$ALIASES_FILE\"" >> "$BASHRC"
# Le sourcing .zshrc est fait dans update_zshrc()
}
#------------------------------------------------------------------------------
# FONCTION POUR TELECHARGER ET EXECUTER UN SCRIPT
#------------------------------------------------------------------------------
download_and_execute() {
local URL="$1"
local SCRIPT_NAME=$(basename "$URL")
local DESCRIPTION="${2:-$SCRIPT_NAME}"
shift 2
local EXEC_ARGS="$@"
# Vérifier si le fichier existe déjà et le supprimer
[ -f "$SCRIPT_NAME" ] && rm "$SCRIPT_NAME"
# Télécharger avec curl en mode silencieux mais avec barre de progression
#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
# Vérifier que le fichier a bien été téléchargé
if [ ! -f "$SCRIPT_NAME" ]; then
error_msg "Le fichier $SCRIPT_NAME n'a pas été créé"
return 1
fi
# Rendre le script exécutable
if ! chmod +x "$SCRIPT_NAME"; then
error_msg "Impossible de rendre le script $DESCRIPTION exécutable"
return 1
fi
# Exécuter le script avec les arguments
if ! ./"$SCRIPT_NAME" $EXEC_ARGS; then
error_msg "Erreur lors de l'exécution du script $DESCRIPTION"
return 1
fi
return 0
}
#------------------------------------------------------------------------------
# CHANGEMENT DE DEPOT
#------------------------------------------------------------------------------
change_repo() {
show_banner
if $USE_GUM; then
if gum_confirm "Changer le miroir des dépôts ?"; then
termux-change-repo
fi
else
printf "${COLOR_BLUE}Changer le miroir des dépôts ? (O/n) : ${COLOR_RESET}"
read -r -e -p "" -i "o" CHOICE
[[ "$CHOICE" =~ ^[oO]$ ]] && termux-change-repo
fi
}
#------------------------------------------------------------------------------
# CONFIGURATION DU STOCKAGE
#------------------------------------------------------------------------------
setup_storage() {
if [ ! -d "$HOME/storage" ]; then
show_banner
if $USE_GUM; then
if gum_confirm "Autoriser l'accès au stockage ?"; then
termux-setup-storage
fi
else
printf "${COLOR_BLUE}Autoriser l'accès au stockage ? (O/n) : ${COLOR_RESET}"
read -r -e -p "" -i "n" CHOICE
[[ "$CHOICE" =~ ^[oO]$ ]] && termux-setup-storage
fi
fi
}
#------------------------------------------------------------------------------
# CONFIGURATION DE TERMUX
#------------------------------------------------------------------------------
configure_termux() {
title_msg "❯ Configuration de Termux"
# Sauvegarde des fichiers existants
create_backups
TERMUX_DIR="$HOME/.termux"
# Configuration de colors.properties
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 "✓ Installation du thème Argonaut"
fi
# Configuration des alias communs
common_alias
# Configuration de termux.properties
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" "Configuration des propriétés Termux"
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\"" "Configuration de Termux"
fi
# Suppression de la bannière de connexion
execute_command "touch $HOME/.hushlogin" "Suppression de la bannière de connexion"
}
#------------------------------------------------------------------------------
# CONFIGURATION INITIALE
#------------------------------------------------------------------------------
initial_config() {
# Si on est en mode FULL_INSTALL, demander les identifiants au début
if $FULL_INSTALL; then
title_msg "❯ Configuration de Debian PRoot"
if [ -z "$PROOT_USERNAME" ]; then
if $USE_GUM; then
PROOT_USERNAME=$(gum input --placeholder "Entrez le nom d'utilisateur pour Debian PRoot")
PROOT_PASSWORD=$(gum input --password --placeholder "Entrez le mot de passe pour Debian PRoot")
else
printf "${COLOR_BLUE}Entrez le nom d'utilisateur pour Debian PRoot : ${COLOR_RESET}"
read -r PROOT_USERNAME
printf "${COLOR_BLUE}Entrez le mot de passe pour Debian PRoot : ${COLOR_RESET}"
read -r -s PROOT_PASSWORD
echo
fi
fi
fi
change_repo
# Mise à jour et mise à niveau des paquets en préservant les configurations existantes
clear
show_banner
execute_command "pkg update -y -o Dpkg::Options::=\"--force-confold\"" "Mise à jour des dépôts"
execute_command "pkg upgrade -y -o Dpkg::Options::=\"--force-confold\"" "Mise à niveau des paquets"
setup_storage
if $USE_GUM; then
show_banner
if gum_confirm "Activer la configuration recommandée ?"; then
configure_termux
fi
else
show_banner
printf "${COLOR_BLUE}Activer la configuration recommandée ? (O/n) : ${COLOR_RESET}"
read -r -e -p "" -i "o" CHOICE
# Effacer la ligne précédente
tput cuu1 # Remonte d'une ligne
tput el # Efface jusqu'à la fin de la ligne
[[ "$CHOICE" =~ ^[oO]$ ]] && configure_termux
fi
}
#------------------------------------------------------------------------------
# INSTALLATION DU SHELL
#------------------------------------------------------------------------------
install_shell() {
if $SHELL_CHOICE; then
title_msg "❯ Configuration du shell"
if $USE_GUM; then
SHELL_CHOICE=$(gum_choose "Choisissez le shell à installer :" --selected="zsh" --height=5 "bash" "zsh" "fish")
else
echo -e "${COLOR_BLUE}Choisissez le shell à installer :${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}Entrez le numéro de votre choix : ${COLOR_RESET}"
tput setaf 3
read -r -e -p "" -i "2" CHOICE
tput sgr0
# Effacer le menu de sélection
tput cuu 7 # Remonte le curseur de 7 lignes
tput ed # Efface du curseur à la fin de l'écran
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 "✓ Séléction de Bash"
install_prompt
;;
"zsh")
if ! command -v zsh &> /dev/null; then
execute_command "pkg install -y zsh" "Installation de ZSH"
else
success_msg="✓ Zsh déjà installé"
fi
# Installation de Oh My Zsh et autres configurations ZSH
title_msg "❯ Configuration de ZSH"
if [ ! -d "$HOME/.oh-my-zsh" ]; then
if $USE_GUM; then
if gum_confirm "Installer Oh-My-Zsh ?"; then
execute_command "pkg install -y wget curl git unzip" "Installation des dépendances"
execute_command "git clone https://github.com/ohmyzsh/ohmyzsh.git \"$HOME/.oh-my-zsh\"" "Installation de Oh-My-Zsh"
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" "Installation des dépendances"
execute_command "git clone https://github.com/ohmyzsh/ohmyzsh.git \"$HOME/.oh-my-zsh\"" "Installation de Oh-My-Zsh"
cp "$HOME/.oh-my-zsh/templates/zshrc.zsh-template" "$ZSHRC"
fi
fi
else
success_msg "✓ Oh-My-Zsh déjà installé"
fi
execute_command "curl -fLo \"$ZSHRC\" https://raw.githubusercontent.com/GiGiDKR/OhMyTermux/1.0.0/src/zshrc" "Configuration par défaut" || error_msg "Configuration par défaut impossible"
if command -v zsh &> /dev/null; then
install_zsh_plugins
install_prompt
else
echo -e "${COLOR_RED}ZSH n'est pas installé. Impossible d'installer les plugins.${COLOR_RESET}"
fi
chsh -s zsh
;;
"fish")
title_msg "❯ Configuration de Fish"
execute_command "pkg install -y fish" "Installation de Fish"
execute_command "mkdir -p $HOME/.config/fish/functions" "Création du répertoire fish"
# Installation de Fisher en mode non-interactif
execute_command "curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish -o $HOME/.config/fish/functions/fisher.fish" "Téléchargement de Fisher"
# Installation de Tide via Fisher en mode non-interactif
execute_command "fish -c 'source $HOME/.config/fish/functions/fisher.fish && fisher install IlanCosman/tide@v5'" "Installation de Tide"
chsh -s fish
;;
esac
fi
}
#------------------------------------------------------------------------------
# INSTALLATION DU 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 "Choisissez le prompt à installer :" --height=4 --selected="Oh-My-Posh" "Oh-My-Posh" "Starship")
else
echo -e "${COLOR_BLUE}Choisissez le prompt à installer :${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}Entrez votre choix (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 "Choisissez le prompt à installer :" --height=5 --selected="PowerLevel10k" "PowerLevel10k" "Oh-My-Posh" "Starship")
else
echo -e "${COLOR_BLUE}Choisissez le prompt à installer :${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}Entrez votre choix (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 "Installer 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 "Installer le prompt personnalisé ?"; then
execute_command "curl -fLo \"$HOME/.p10k.zsh\" https://raw.githubusercontent.com/GiGiDKR/OhMyTermux/1.0.0/src/p10k.zsh" "Installation du prompt personnalisé" || error_msg "Impossible d'installer le prompt personnalisé"
echo -e "\n# Pour personnaliser le prompt, exécuter \`p10k configure\` ou éditer ~/.p10k.zsh." >> "$ZSHRC"
echo "[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh" >> "$ZSHRC"
else
echo -e "${COLOR_BLUE}Vous pouvez configurer le prompt en exécutant 'p10k configure'.${COLOR_RESET}"
fi
fi
else
printf "${COLOR_BLUE}Installer 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}Installer le prompt personnalisé ? (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 du prompt personnalisé" || error_msg "Impossible d'installer le prompt personnalisé"
echo -e "\n# Pour personnaliser le prompt, exécuter \`p10k configure\` ou éditer ~/.p10k.zsh." >> "$ZSHRC"
echo "[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh" >> "$ZSHRC"
else
echo -e "${COLOR_BLUE}Vous pouvez configurer le prompt en exécutant 'p10k configure'.${COLOR_RESET}"
fi
fi
fi
;;
"Oh-My-Posh")
execute_command "pkg install -y oh-my-posh" "Installation de Oh-My-Posh"
# Installation optionnelle d'une police Nerd
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 de la police Nerd"
fi
# Récupération de la liste complète des thèmes
THEMES_DIR="/data/data/com.termux/files/usr/share/oh-my-posh/themes"
if [ -d "$THEMES_DIR" ]; then
# Création d'un tableau avec tous les thèmes disponibles
mapfile -t AVAILABLE_THEMES < <(find "$THEMES_DIR" -name "*.omp.json" -exec basename {} .omp.json \; | sort)
else
error_msg "Répertoire des thèmes Oh-My-Posh non trouvé"
return 1
fi
# Sélection du thème
if $USE_GUM; then
THEME=$(printf '%s\n' "${AVAILABLE_THEMES[@]}" | gum_choose \
"Choisissez un thème Oh-My-Posh :" \
--height=25)
else
# Affichage de la liste numérotée des thèmes
echo -e "${COLOR_BLUE}Choisissez un thème Oh-My-Posh :${COLOR_RESET}"
echo
for i in "${!AVAILABLE_THEMES[@]}"; do
# Formatage du numéro pour l'alignement (3 caractères)
NUM=$(printf "%3d" $((i+1)))
if [ "${AVAILABLE_THEMES[$i]}" = "jandedobbeleer" ]; then
echo -e "${COLOR_BLUE}${NUM}) ${AVAILABLE_THEMES[$i]} (par défaut)${COLOR_RESET}"
else
echo -e "${COLOR_BLUE}${NUM}) ${AVAILABLE_THEMES[$i]}${COLOR_RESET}"
fi
done
echo
# Calcul du nombre de lignes à effacer (nombre de thèmes + 3 lignes pour le texte supplémentaire)
LINES_TO_CLEAR=$((${#AVAILABLE_THEMES[@]}+3))
printf "${COLOR_GOLD}Entrez le numéro de votre choix : ${COLOR_RESET}"
tput setaf 3
read -r -e -p "" -i "1" CHOICE
tput sgr0
# Effacement du menu
tput cuu $LINES_TO_CLEAR
tput ed
# Validation du choix
if [[ "$CHOICE" =~ ^[0-9]+$ ]] && [ "$CHOICE" -ge 1 ] && [ "$CHOICE" -le "${#AVAILABLE_THEMES[@]}" ]; then
THEME="${AVAILABLE_THEMES[$((CHOICE-1))]}"
else