Skip to content

Commit d71476e

Browse files
committed
Update | Add version display on TUI & ASCII
1 parent 3b9834e commit d71476e

File tree

1 file changed

+268
-50
lines changed

1 file changed

+268
-50
lines changed

menu.sh

Lines changed: 268 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
#!/usr/bin/env bash
22
# ==============================================================================
3-
# menu.sh — Lanceur interactif des scripts OverStyleFR
3+
# menu.sh — TUI whiptail/dialog avec fallback Bash (ASCII OverStyleFR) + options
44
#
55
# USAGE :
6-
# sudo ./menu.sh
6+
# # TUI auto (whiptail/dialog si disponibles, sinon menu ASCII)
7+
# bash <(curl -fsSL https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/menu.sh)
8+
#
9+
# # Forcer le menu ASCII Bash (même si whiptail est présent)
10+
# bash <(curl -fsSL https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/menu.sh) --bash
11+
#
12+
# OPTIONS :
13+
# --bash Force le menu Bash (ASCII) et désactive whiptail/dialog
714
# ==============================================================================
815

916
set -uo pipefail
1017

18+
# ------------------------------ Branding / version ----------------------------
19+
APP_TITLE="OverStyleFR • AutoScriptBash"
20+
MENU_VERSION="V2.1"
21+
22+
# ------------------------------ CLI flags -------------------------------------
23+
FORCE_BASH=0
24+
for arg in "$@"; do
25+
case "$arg" in
26+
--bash) FORCE_BASH=1 ;;
27+
esac
28+
done
29+
1130
# ------------------------------- Couleurs -------------------------------------
1231
if command -v tput >/dev/null 2>&1 && [[ -t 1 ]]; then
1332
GREEN="$(tput setaf 2)"; RED="$(tput setaf 1)"; BLUE="$(tput setaf 4)"
@@ -23,63 +42,231 @@ if [[ ${EUID:-$UID} -ne 0 ]]; then
2342
exec sudo -E bash "$0" "$@"
2443
fi
2544

26-
# ----------------------------- URLs des scripts --------------------------------
45+
# ----------------------------- URLs des scripts -------------------------------
2746
DOCKER_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/dockerinstall.sh"
2847
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"
48+
NEW_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/refs/heads/fix/script-new-interactive-mode/.assets/new.sh"
3049
SPEED_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/speedtest.sh"
3150
FASTFETCH_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/fastfetch-install.sh"
3251
PANEL_REINSTALL_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/pterodactylpanelreinstall.sh"
3352
PTERO_MENU_URL="https://raw.githubusercontent.com/OverStyleFR/Pterodactyl-Installer-Menu/main/PterodactylMenu.sh"
3453
SSH_MENU_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/menu_id.sh"
3554

36-
# ------------------------------- Helpers --------------------------------------
55+
# ------------------------------ Options new.sh --------------------------------
56+
NEW_F_DEBUG=0
57+
NEW_F_DRYRUN=0
58+
NEW_F_QUIET=0
59+
NEW_EXTRA_ARGS=""
60+
declare -a NEW_FLAGS=()
61+
62+
build_new_flags() {
63+
NEW_FLAGS=()
64+
(( NEW_F_DEBUG )) && NEW_FLAGS+=(--debug)
65+
(( NEW_F_DRYRUN )) && NEW_FLAGS+=(--dry-run)
66+
(( NEW_F_QUIET )) && NEW_FLAGS+=(--quiet)
67+
if [[ -n "$NEW_EXTRA_ARGS" ]]; then
68+
# shellcheck disable=SC2206
69+
local extra=( $NEW_EXTRA_ARGS )
70+
NEW_FLAGS+=( "${extra[@]}" )
71+
fi
72+
}
73+
flags_inline_if_any() {
74+
build_new_flags
75+
((${#NEW_FLAGS[@]})) && echo " [${NEW_FLAGS[*]}]" || echo ""
76+
}
77+
78+
# ------------------------------- Helpers communs ------------------------------
3779
pause() { read -n 1 -s -r -p "Appuyez sur une touche pour retourner au menu..." ; echo; }
3880

3981
download_to_tmp() {
40-
# $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-
82+
local url="$1" prefix="${2:-script}" tmp
83+
tmp="$(mktemp -p /tmp "${prefix}.XXXXXX")" || { echo "mktemp a échoué"; return 98; }
4584
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
85+
curl -fsSL --retry 3 --retry-delay 1 "$url" -o "$tmp" || { rm -f "$tmp"; return 90; }
4986
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
87+
wget -q "$url" -O "$tmp" || { rm -f "$tmp"; return 90; }
5388
else
54-
echo -e "${RED}${BOLD}Ni curl ni wget disponible pour télécharger${RESET}"; rm -f "$tmp"; return 91
89+
rm -f "$tmp"; return 91
5590
fi
56-
5791
chmod +x "$tmp"
58-
printf "%s" "$tmp" # retourne le chemin
92+
printf "%s" "$tmp"
5993
}
6094

6195
run_remote() {
62-
# $1=url $2=nom_affiché
63-
local url="$1" label="${2:-script}" tmp rc
96+
local url="$1" label="${2:-script}"; shift 2 || true
97+
local args=( "$@" ) tmp rc
6498
echo -e "${YELLOW}${BOLD}Téléchargement de ${label}${RESET}"
6599
if ! tmp="$(download_to_tmp "$url" "$label")"; then
66-
echo -e "${RED}${BOLD}Échec de préparation pour ${label}${RESET}"
67-
return 90
100+
echo -e "${RED}${BOLD}Échec de téléchargement.${RESET}"; return 90
68101
fi
69102
echo -e "${YELLOW}${BOLD}Exécution de ${label}${RESET}"
70-
bash "$tmp"; rc=$?
103+
bash "$tmp" "${args[@]}"; rc=$?
71104
rm -f "$tmp" 2>/dev/null || true
72105
if [[ $rc -eq 0 ]]; then
73106
echo -e "${GREEN}${BOLD}${label} terminé avec succès${RESET}"
74107
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: /"
108+
echo -e "${RED}${BOLD}${label} a échoué (rc=$rc)${RESET}"
109+
ls -1 /var/log/new-basics-*.log 2>/dev/null | tail -n 1 | sed "s/^/Dernier log : /"
77110
fi
78111
return $rc
79112
}
80113

81-
draw_menu() {
114+
# =============================== UI: WHIPTAIL/DIALOG ==========================
115+
DIALOG_BIN=""
116+
if [[ $FORCE_BASH -eq 0 ]]; then
117+
if command -v whiptail >/dev/null 2>&1; then
118+
DIALOG_BIN="whiptail"
119+
elif command -v dialog >/dev/null 2>&1; then
120+
DIALOG_BIN="dialog"
121+
fi
122+
fi
123+
124+
ui_menu() {
125+
local title="$1" prompt="$2" h="$3" w="$4" mh="$5"; shift 5
126+
local status out bt="${APP_TITLE} ${MENU_VERSION}"
127+
if [[ "$DIALOG_BIN" == "whiptail" ]]; then
128+
out=$(whiptail --backtitle "$bt" --title "$title" --ok-button "OK" --cancel-button "Cancel" \
129+
--menu "$prompt" "$h" "$w" "$mh" "$@" 3>&1 1>&2 2>&3)
130+
status=$?
131+
else
132+
out=$(dialog --backtitle "$bt" --title "$title" --ok-label "OK" --cancel-label "Cancel" \
133+
--menu "$prompt" "$h" "$w" "$mh" "$@" 3>&1 1>&2 2>&3)
134+
status=$?
135+
fi
136+
printf "%s" "$out"
137+
return $status
138+
}
139+
140+
ui_msg() {
141+
local title="$1" msg="$2" bt="${APP_TITLE} ${MENU_VERSION}"
142+
if [[ "$DIALOG_BIN" == "whiptail" ]]; then
143+
whiptail --backtitle "$bt" --title "$title" --msgbox "$msg" 13 70
144+
else
145+
dialog --backtitle "$bt" --title "$title" --msgbox "$msg" 13 70
146+
fi
147+
}
148+
149+
adv_menu_ui() {
150+
local dbg="OFF" dry="OFF" qui="OFF" sel status
151+
(( NEW_F_DEBUG )) && dbg="ON"
152+
(( NEW_F_DRYRUN )) && dry="ON"
153+
(( NEW_F_QUIET )) && qui="ON"
154+
155+
if [[ "$DIALOG_BIN" == "whiptail" ]]; then
156+
sel=$(whiptail --backtitle "${APP_TITLE} ${MENU_VERSION}" --title "Options avancées (new.sh)" \
157+
--checklist "Sélectionne les flags à activer :" 16 70 6 \
158+
DEBUG "Activer --debug (bash -x + logs DEBUG)" "$dbg" \
159+
DRYRUN "Activer --dry-run (simulation)" "$dry" \
160+
QUIET "Activer --quiet (console moins bavarde)" "$qui" \
161+
3>&1 1>&2 2>&3); status=$?
162+
else
163+
sel=$(dialog --backtitle "${APP_TITLE} ${MENU_VERSION}" --title "Options avancées (new.sh)" \
164+
--checklist "Sélectionne les flags à activer :" 16 70 6 \
165+
DEBUG "Activer --debug (bash -x + logs DEBUG)" "$dbg" \
166+
DRYRUN "Activer --dry-run (simulation)" "$dry" \
167+
QUIET "Activer --quiet (console moins bavarde)" "$qui" \
168+
3>&1 1>&2 2>&3); status=$?
169+
fi
170+
[[ $status -ne 0 ]] && return 0
171+
172+
NEW_F_DEBUG=0; NEW_F_DRYRUN=0; NEW_F_QUIET=0
173+
for t in $sel; do
174+
t="${t%\"}"; t="${t#\"}"
175+
case "$t" in
176+
DEBUG) NEW_F_DEBUG=1 ;;
177+
DRYRUN) NEW_F_DRYRUN=1 ;;
178+
QUIET) NEW_F_QUIET=1 ;;
179+
esac
180+
done
181+
182+
local extra
183+
if [[ "$DIALOG_BIN" == "whiptail" ]]; then
184+
extra=$(whiptail --backtitle "${APP_TITLE} ${MENU_VERSION}" --title "Arguments libres (new.sh)" \
185+
--inputbox "Autres arguments (ex: --log /tmp/x.log) :" 10 70 "$NEW_EXTRA_ARGS" \
186+
3>&1 1>&2 2>&3); status=$?
187+
else
188+
extra=$(dialog --backtitle "${APP_TITLE} ${MENU_VERSION}" --title "Arguments libres (new.sh)" \
189+
--inputbox "Autres arguments (ex: --log /tmp/x.log) :" 10 70 "$NEW_EXTRA_ARGS" \
190+
3>&1 1>&2 2>&3); status=$?
191+
fi
192+
[[ $status -ne 0 ]] && return 0
193+
NEW_EXTRA_ARGS="$extra"
194+
195+
ui_msg "Options mises à jour" "new.sh sera lancé avec : $(flags_inline_if_any)"
196+
}
197+
198+
submenu_installation_ui() {
199+
while true; do
200+
local sel; sel=$(ui_menu "Installation" "Choisis une action :" 15 70 6 \
201+
1 "Installer docker" \
202+
2 "Installer yarn" \
203+
3 "Retour")
204+
case $? in 1|255) return 0 ;; esac
205+
case "$sel" in
206+
1) run_remote "$DOCKER_URL" "dockerinstall.sh" ;;
207+
2) run_remote "$YARN_URL" "yarninstall.sh" ;;
208+
3|"") return 0 ;;
209+
esac
210+
done
211+
}
212+
213+
submenu_scripts_ui() {
214+
while true; do
215+
local flags; flags="$(flags_inline_if_any)"
216+
local sel; sel=$(ui_menu "Scripts" "Choisis un script à exécuter :" 20 78 8 \
217+
1 "Exécuter 'new.sh'${flags}" \
218+
2 "Exécuter 'speedtest.sh'" \
219+
3 "Exécuter 'fastfetch-install.sh'" \
220+
4 "Exécuter 'pterodactyl-panel-reinstaller'" \
221+
5 "Retour")
222+
case $? in 1|255) return 0 ;; esac
223+
case "$sel" in
224+
1) build_new_flags; run_remote "$NEW_URL" "new.sh" "${NEW_FLAGS[@]}" ;;
225+
2) run_remote "$SPEED_URL" "speedtest.sh" ;;
226+
3) run_remote "$FASTFETCH_URL" "fastfetch-install.sh" ;;
227+
4) run_remote "$PANEL_REINSTALL_URL" "pterodactylpanelreinstall.sh" ;;
228+
5|"") return 0 ;;
229+
esac
230+
done
231+
}
232+
233+
submenu_autres_ui() {
234+
while true; do
235+
local sel; sel=$(ui_menu "Autres menus" "Choisis une action :" 15 70 6 \
236+
1 "Exécuter le Pterodactyl Menu" \
237+
2 "Menu SSH" \
238+
3 "Retour")
239+
case $? in 1|255) return 0 ;; esac
240+
case "$sel" in
241+
1) run_remote "$PTERO_MENU_URL" "PterodactylMenu.sh" ;;
242+
2) run_remote "$SSH_MENU_URL" "menu_id.sh" ;;
243+
3|"") return 0 ;;
244+
esac
245+
done
246+
}
247+
248+
main_menu_ui() {
249+
while true; do
250+
local sel; sel=$(ui_menu "Menu principal" "Sélectionne une catégorie :" 16 60 6 \
251+
1 "Installation" \
252+
2 "Scripts" \
253+
3 "Autres menus" \
254+
4 "Options avancées (new.sh)")
255+
case $? in 1|255) exit 0 ;; esac
256+
case "$sel" in
257+
1) submenu_installation_ui ;;
258+
2) submenu_scripts_ui ;;
259+
3) submenu_autres_ui ;;
260+
4) adv_menu_ui ;;
261+
esac
262+
done
263+
}
264+
265+
# =============================== UI: MENU BASH (ASCII) ========================
266+
draw_ascii_menu() {
82267
clear
268+
echo -e "${BOLD}${APP_TITLE} ${MENU_VERSION}${RESET}"
269+
echo
83270
echo " +------------+"
84271
echo " | ${BOLD}${VIOLET}M${GREEN}e${YELLOW}n${BLUE}u${RESET}${BOLD} :${RESET} |"
85272
echo " +--------+------------+----------+"
@@ -88,43 +275,74 @@ draw_menu() {
88275
echo "| 1. Installer docker |"
89276
echo "| 2. Installer yarn |"
90277
echo "+----------------------------------------------+"
91-
echo ""
278+
echo
92279
echo " +-------------+"
93280
echo " | ${GREEN}${BOLD}Script${RESET}${BOLD} :${RESET} |"
94281
echo " +-------------+-------------+----------------+"
95282
echo " | 3. Exécuter 'new.sh' |"
96-
echo " | |"
97283
echo " | 4. Exécuter 'speedtest.sh' |"
98-
echo " | |"
99-
echo " | 5. Exécuter 'fastfetch.sh' |"
100-
echo " | |"
284+
echo " | 5. Exécuter 'fastfetch-install.sh' |"
101285
echo " | 6. Exécuter 'pterodactyl-panel-reinstaller'|"
102286
echo " +--------------------------------------------+"
103287
echo " | 7. ${BLUE}${BOLD}Exécuter le Pterodactyl Menu${RESET} |"
104288
echo " | └ ${YELLOW}${BOLD}OverStyleFR/Pterodactyl-Installer-Menu${RESET} |"
105289
echo " +--------------------------------------------+"
106-
echo " | 8. ${BOLD}${VIOLET}M${GREEN}e${YELLOW}n${BLUE}u${RESET}${BOLD} SSH ${RESET} |"
290+
echo " | 8. ${BOLD}${VIOLET}Menu SSH ${RESET} |"
107291
echo " | └ ${VIOLET}${BOLD}OverStyleFR/AutoScriptBash${RESET} |"
108292
echo " +-------------+------------+-----------------+"
109293
echo " | ${RED}${BOLD}9. Quitter${RESET} |"
110294
echo " +------------+"
111295
echo
112296
}
113297

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
298+
adv_menu_ascii() {
299+
while true; do
300+
clear
301+
echo -e "${BOLD}${APP_TITLE} ${MENU_VERSION}${RESET}"
302+
echo
303+
echo "=== Options avancées (new.sh) ==="
304+
echo "Flags actuels :$(flags_inline_if_any)"
305+
echo
306+
echo " 1) Basculer --debug"
307+
echo " 2) Basculer --dry-run"
308+
echo " 3) Basculer --quiet"
309+
echo " 4) Définir arguments libres (ligne unique)"
310+
echo " r) Retour"
311+
read -rp "Choix : " c
312+
case "$c" in
313+
1) NEW_F_DEBUG=$((1 - NEW_F_DEBUG)) ;;
314+
2) NEW_F_DRYRUN=$((1 - NEW_F_DRYRUN)) ;;
315+
3) NEW_F_QUIET=$((1 - NEW_F_QUIET)) ;;
316+
4) read -rp "Args libres (ex: --log /tmp/x.log) : " NEW_EXTRA_ARGS ;;
317+
r|R) return 0 ;;
318+
esac
319+
done
320+
}
321+
322+
main_menu_ascii() {
323+
while true; do
324+
draw_ascii_menu
325+
read -rp "Choisissez une option (1-9) : " choix
326+
case "${choix:-}" in
327+
1) echo "Installation de Docker." ; run_remote "$DOCKER_URL" "dockerinstall.sh" ; pause ;;
328+
2) echo "Installation de Yarn." ; run_remote "$YARN_URL" "yarninstall.sh" ; pause ;;
329+
3) echo "Exécution du script 'new.sh'." ; build_new_flags; run_remote "$NEW_URL" "new.sh" "${NEW_FLAGS[@]}"; pause ;;
330+
4) echo "Exécution du script 'speedtest.sh'." ; run_remote "$SPEED_URL" "speedtest.sh" ; pause ;;
331+
5) echo "Exécution du script 'fastfetch-install.sh'." ; run_remote "$FASTFETCH_URL" "fastfetch-install.sh" ; pause ;;
332+
6) echo "Exécution du script 'pterodactyl-panel-reinstaller'." ; run_remote "$PANEL_REINSTALL_URL" "pterodactylpanelreinstall.sh" ; pause ;;
333+
7) echo -e "${BLUE}${BOLD}Exécuter le Pterodactyl Menu${RESET}" ; run_remote "$PTERO_MENU_URL" "PterodactylMenu.sh" ; pause ;;
334+
8) echo -e "${BOLD}${VIOLET}Menu SSH${RESET}" ; run_remote "$SSH_MENU_URL" "menu_id.sh" ; pause ;;
335+
9) echo "Au revoir !" ; exit 0 ;;
336+
0) adv_menu_ascii ;; # raccourci non documenté si tu veux y accéder vite
337+
*) echo -e "${RED}Choix non valide. Veuillez entrer un numéro entre 1 et 9.${RESET}"; sleep 1 ;;
338+
esac
339+
done
340+
}
341+
342+
# =============================== Lancement ====================================
343+
if [[ -n "${DIALOG_BIN}" ]]; then
344+
main_menu_ui
345+
else
346+
echo "(UI Bash : whiptail/dialog indisponibles ou --bash forcé)"
347+
main_menu_ascii
348+
fi

0 commit comments

Comments
 (0)