Skip to content

Commit 60b535b

Browse files
committed
Add | Whiptail menu
Point a améliroer : - Ajout de catégorie (Installation, Script & Autre menus). - Si possible par défaut Whiptail sinon basculer sur bash.
1 parent 3b9834e commit 60b535b

File tree

1 file changed

+117
-83
lines changed

1 file changed

+117
-83
lines changed

menu.sh

Lines changed: 117 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,164 @@
11
#!/usr/bin/env bash
22
# ==============================================================================
3-
# menu.sh — Lanceur interactif des scripts OverStyleFR
3+
# menu.sh — TUI façon raspi-config (whiptail/dialog) pour lancer les scripts
44
#
55
# USAGE :
66
# sudo ./menu.sh
77
# ==============================================================================
88

99
set -uo pipefail
1010

11-
# ------------------------------- Couleurs -------------------------------------
12-
if command -v tput >/dev/null 2>&1 && [[ -t 1 ]]; then
13-
GREEN="$(tput setaf 2)"; RED="$(tput setaf 1)"; BLUE="$(tput setaf 4)"
14-
VIOLET="$(tput setaf 5)"; YELLOW="$(tput setaf 3)"
15-
BOLD="$(tput bold)"; RESET="$(tput sgr0)"
16-
else
17-
GREEN=""; RED=""; BLUE=""; VIOLET=""; YELLOW=""; BOLD=""; RESET=""
18-
fi
19-
2011
# ------------------------------ Vérif root ------------------------------------
2112
if [[ ${EUID:-$UID} -ne 0 ]]; then
22-
echo -e "${RED}${BOLD}Ce script doit être exécuté en tant que root.${RESET}"
13+
echo "Ce script doit être exécuté en root."
2314
exec sudo -E bash "$0" "$@"
2415
fi
2516

2617
# ----------------------------- URLs des scripts --------------------------------
2718
DOCKER_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/dockerinstall.sh"
2819
YARN_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/yarninstall.sh"
29-
NEW_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/refs/heads/main/.assets/new.sh"
20+
NEW_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/refs/heads/fix/script-new-interactive-mode/.assets/new.sh"
3021
SPEED_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/speedtest.sh"
3122
FASTFETCH_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/fastfetch-install.sh"
3223
PANEL_REINSTALL_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/pterodactylpanelreinstall.sh"
3324
PTERO_MENU_URL="https://raw.githubusercontent.com/OverStyleFR/Pterodactyl-Installer-Menu/main/PterodactylMenu.sh"
3425
SSH_MENU_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/menu_id.sh"
3526

36-
# ------------------------------- Helpers --------------------------------------
37-
pause() { read -n 1 -s -r -p "Appuyez sur une touche pour retourner au menu..." ; echo; }
27+
# ------------------------------ UI backend ------------------------------------
28+
DIALOG_BIN=""
29+
if command -v whiptail >/dev/null 2>&1; then
30+
DIALOG_BIN="whiptail"
31+
elif command -v dialog >/dev/null 2>&1; then
32+
DIALOG_BIN="dialog"
33+
else
34+
# petit essai d’installation silencieuse côté apt ; sinon fallback texte
35+
if command -v apt-get >/dev/null 2>&1; then
36+
apt-get update -y >/dev/null 2>&1 || true
37+
apt-get install -y whiptail >/dev/null 2>&1 || true
38+
command -v whiptail >/dev/null 2>&1 && DIALOG_BIN="whiptail"
39+
fi
40+
fi
41+
42+
msg_box() {
43+
# $1 titre, $2 message
44+
if [[ -n "$DIALOG_BIN" ]]; then
45+
$DIALOG_BIN --title "$1" --msgbox "$2" 13 70
46+
else
47+
echo -e "\n==== $1 ====\n$2\n(Entrée pour continuer)"; read -r _
48+
fi
49+
}
3850

51+
# ------------------------------- Helpers --------------------------------------
3952
download_to_tmp() {
4053
# $1=url $2=prefix (nom lisible)
41-
local url="$1" prefix="${2:-script}"
42-
local tmp
43-
tmp="$(mktemp -p /tmp "${prefix}.XXXXXX")" || { echo -e "${RED}${BOLD}mktemp a échoué${RESET}"; return 98; }
44-
54+
local url="$1" prefix="${2:-script}" tmp
55+
tmp="$(mktemp -p /tmp "${prefix}.XXXXXX")" || { echo "mktemp a échoué"; return 98; }
4556
if command -v curl >/dev/null 2>&1; then
46-
if ! curl -fsSL --retry 3 --retry-delay 1 "$url" -o "$tmp"; then
47-
echo -e "${RED}${BOLD}Téléchargement échoué (curl)${RESET}"; rm -f "$tmp"; return 90
48-
fi
57+
curl -fsSL --retry 3 --retry-delay 1 "$url" -o "$tmp" || { rm -f "$tmp"; return 90; }
4958
elif command -v wget >/dev/null 2>&1; then
50-
if ! wget -q "$url" -O "$tmp"; then
51-
echo -e "${RED}${BOLD}Téléchargement échoué (wget)${RESET}"; rm -f "$tmp"; return 90
52-
fi
59+
wget -q "$url" -O "$tmp" || { rm -f "$tmp"; return 90; }
5360
else
54-
echo -e "${RED}${BOLD}Ni curl ni wget disponible pour télécharger${RESET}"; rm -f "$tmp"; return 91
61+
rm -f "$tmp"; return 91
5562
fi
56-
5763
chmod +x "$tmp"
58-
printf "%s" "$tmp" # retourne le chemin
64+
printf "%s" "$tmp"
5965
}
6066

6167
run_remote() {
6268
# $1=url $2=nom_affiché
6369
local url="$1" label="${2:-script}" tmp rc
64-
echo -e "${YELLOW}${BOLD}Téléchargement de ${label}${RESET}"
65-
if ! tmp="$(download_to_tmp "$url" "$label")"; then
66-
echo -e "${RED}${BOLD}Échec de préparation pour ${label}${RESET}"
70+
tmp="$(download_to_tmp "$url" "$label")" || {
71+
msg_box "Erreur" "Échec de téléchargement de ${label}.\nVérifie la connexion réseau."
6772
return 90
68-
fi
69-
echo -e "${YELLOW}${BOLD}Exécution de ${label}${RESET}"
73+
}
74+
75+
clear
76+
echo "=== Exécution de ${label} ==="
7077
bash "$tmp"; rc=$?
7178
rm -f "$tmp" 2>/dev/null || true
79+
7280
if [[ $rc -eq 0 ]]; then
73-
echo -e "${GREEN}${BOLD}${label} terminé avec succès${RESET}"
81+
msg_box "Terminé" "${label} s'est terminé avec succès."
7482
else
75-
echo -e "${RED}${BOLD}${label} a échoué (rc=${rc})${RESET}"
76-
ls -1 /var/log/new-basics-*.log 2>/dev/null | tail -n 1 | sed "s/^/Dernier log: /"
83+
local hint
84+
hint="$(ls -1 /var/log/new-basics-*.log 2>/dev/null | tail -n 1)"
85+
msg_box "Échec" "${label} a échoué (rc=$rc).\n${hint:+Dernier log : $hint}"
7786
fi
7887
return $rc
7988
}
8089

81-
draw_menu() {
82-
clear
83-
echo " +------------+"
84-
echo " | ${BOLD}${VIOLET}M${GREEN}e${YELLOW}n${BLUE}u${RESET}${BOLD} :${RESET} |"
85-
echo " +--------+------------+----------+"
86-
echo " | ${VIOLET}${BOLD}Installation${RESET}${BOLD} :${RESET} |"
87-
echo "+------+--------------------------------+------+"
88-
echo "| 1. Installer docker |"
89-
echo "| 2. Installer yarn |"
90-
echo "+----------------------------------------------+"
91-
echo ""
92-
echo " +-------------+"
93-
echo " | ${GREEN}${BOLD}Script${RESET}${BOLD} :${RESET} |"
94-
echo " +-------------+-------------+----------------+"
95-
echo " | 3. Exécuter 'new.sh' |"
96-
echo " | |"
97-
echo " | 4. Exécuter 'speedtest.sh' |"
98-
echo " | |"
99-
echo " | 5. Exécuter 'fastfetch.sh' |"
100-
echo " | |"
101-
echo " | 6. Exécuter 'pterodactyl-panel-reinstaller'|"
102-
echo " +--------------------------------------------+"
103-
echo " | 7. ${BLUE}${BOLD}Exécuter le Pterodactyl Menu${RESET} |"
104-
echo " | └ ${YELLOW}${BOLD}OverStyleFR/Pterodactyl-Installer-Menu${RESET} |"
105-
echo " +--------------------------------------------+"
106-
echo " | 8. ${BOLD}${VIOLET}M${GREEN}e${YELLOW}n${BLUE}u${RESET}${BOLD} SSH ${RESET} |"
107-
echo " | └ ${VIOLET}${BOLD}OverStyleFR/AutoScriptBash${RESET} |"
108-
echo " +-------------+------------+-----------------+"
109-
echo " | ${RED}${BOLD}9. Quitter${RESET} |"
110-
echo " +------------+"
111-
echo
90+
# ------------------------------- Menu loop ------------------------------------
91+
text_menu() {
92+
while true; do
93+
clear
94+
cat <<'TXT'
95+
+-------------------------------+
96+
| MENU (texte) |
97+
+-------------------------------+
98+
1) Installer docker
99+
2) Installer yarn
100+
3) Exécuter 'new.sh'
101+
4) Exécuter 'speedtest.sh'
102+
5) Exécuter 'fastfetch-install.sh'
103+
6) Exécuter 'pterodactyl-panel-reinstaller'
104+
7) Lancer PterodactylMenu.sh
105+
8) Menu SSH
106+
9) Quitter
107+
TXT
108+
read -rp "Choix (1-9) : " choix
109+
case "${choix:-}" in
110+
1) run_remote "$DOCKER_URL" "dockerinstall.sh" ;;
111+
2) run_remote "$YARN_URL" "yarninstall.sh" ;;
112+
3) run_remote "$NEW_URL" "new.sh" ;;
113+
4) run_remote "$SPEED_URL" "speedtest.sh" ;;
114+
5) run_remote "$FASTFETCH_URL" "fastfetch-install.sh" ;;
115+
6) run_remote "$PANEL_REINSTALL_URL" "pterodactylpanelreinstall.sh" ;;
116+
7) run_remote "$PTERO_MENU_URL" "PterodactylMenu.sh" ;;
117+
8) run_remote "$SSH_MENU_URL" "menu_id.sh" ;;
118+
9) exit 0 ;;
119+
*) ;;
120+
esac
121+
done
122+
}
123+
124+
whip_menu() {
125+
local choice ret
126+
while true; do
127+
choice=$($DIALOG_BIN --backtitle "OverStyleFR • AutoScriptBash" \
128+
--title "Menu principal" \
129+
--menu "Sélectionne une action :" 20 74 10 \
130+
1 "Installer docker" \
131+
2 "Installer yarn" \
132+
3 "Exécuter 'new.sh'" \
133+
4 "Exécuter 'speedtest.sh'" \
134+
5 "Exécuter 'fastfetch-install.sh'" \
135+
6 "Exécuter 'pterodactyl-panel-reinstaller'" \
136+
7 "Exécuter le Pterodactyl Menu" \
137+
8 "Menu SSH" \
138+
9 "Quitter" \
139+
3>&1 1>&2 2>&3)
140+
ret=$?
141+
[[ $ret -ne 0 ]] && exit 0
142+
143+
case "$choice" in
144+
1) run_remote "$DOCKER_URL" "dockerinstall.sh" ;;
145+
2) run_remote "$YARN_URL" "yarninstall.sh" ;;
146+
3) run_remote "$NEW_URL" "new.sh" ;;
147+
4) run_remote "$SPEED_URL" "speedtest.sh" ;;
148+
5) run_remote "$FASTFETCH_URL" "fastfetch-install.sh" ;;
149+
6) run_remote "$PANEL_REINSTALL_URL" "pterodactylpanelreinstall.sh" ;;
150+
7) run_remote "$PTERO_MENU_URL" "PterodactylMenu.sh" ;;
151+
8) run_remote "$SSH_MENU_URL" "menu_id.sh" ;;
152+
9) exit 0 ;;
153+
esac
154+
done
112155
}
113156

114-
# --------------------------------- Boucle -------------------------------------
115-
while true; do
116-
draw_menu
117-
read -rp "Choisissez une option (1-9) : " choix
118-
case "${choix:-}" in
119-
1) echo "Installation de Docker." ; run_remote "$DOCKER_URL" "dockerinstall.sh" ; pause ;;
120-
2) echo "Installation de Yarn." ; run_remote "$YARN_URL" "yarninstall.sh" ; pause ;;
121-
3) echo "Exécution du script 'new.sh'." ; run_remote "$NEW_URL" "new.sh" ; pause ;;
122-
4) echo "Exécution du script 'speedtest.sh'." ; run_remote "$SPEED_URL" "speedtest.sh" ; pause ;;
123-
5) echo "Exécution du script 'fastfetch-install.sh'." ; run_remote "$FASTFETCH_URL" "fastfetch-install.sh" ; pause ;;
124-
6) echo "Exécution du script 'pterodactyl-panel-reinstaller'."; run_remote "$PANEL_REINSTALL_URL" "pterodactylpanelreinstall.sh" ; pause ;;
125-
7) echo -e "${BLUE}${BOLD}Exécuter le Pterodactyl Menu${RESET}" ; run_remote "$PTERO_MENU_URL" "PterodactylMenu.sh" ; pause ;;
126-
8) echo -e "${BOLD}${VIOLET}Menu SSH${RESET}" ; run_remote "$SSH_MENU_URL" "menu_id.sh" ; pause ;;
127-
9) echo "Au revoir !" ; exit 0 ;;
128-
*) echo -e "${RED}Choix non valide. Veuillez entrer un numéro entre 1 et 9.${RESET}" ; sleep 1 ;;
129-
esac
130-
done
157+
# Lancer le bon menu selon disponibilité
158+
if [[ -n "$DIALOG_BIN" ]]; then
159+
whip_menu
160+
else
161+
echo "Ni 'whiptail' ni 'dialog' détecté — menu texte simple."
162+
echo "Conseil (Debian/Ubuntu) : apt-get install -y whiptail"
163+
text_menu
164+
fi

0 commit comments

Comments
 (0)