Skip to content

Commit eb3915e

Browse files
authored
Merge pull request #7 from OverStyleFR/features/whiptail-menu-v2-1
Update | 'menu.sh' - Whiptail & flag.
2 parents 3b9834e + 04b4337 commit eb3915e

File tree

1 file changed

+224
-51
lines changed

1 file changed

+224
-51
lines changed

menu.sh

Lines changed: 224 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
#!/usr/bin/env bash
22
# ==============================================================================
3-
# menu.sh — Lanceur interactif des scripts OverStyleFR
3+
# menu.sh — TUI whiptail/dialog avec fallback Bash (ASCII style OverStyleFR)
44
#
55
# USAGE :
6-
# sudo ./menu.sh
6+
# bash <(curl -fsSL https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/menu.sh)
7+
# bash <(curl -fsSL https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/menu.sh) --bash
8+
#
9+
# OPTIONS :
10+
# --bash Force le menu Bash (ASCII), même si whiptail/dialog sont présents
711
# ==============================================================================
812

913
set -uo pipefail
1014

15+
# ------------------------------ CLI flags -------------------------------------
16+
FORCE_BASH=0
17+
for arg in "$@"; do
18+
case "$arg" in
19+
--bash) FORCE_BASH=1 ;;
20+
esac
21+
done
22+
1123
# ------------------------------- Couleurs -------------------------------------
1224
if command -v tput >/dev/null 2>&1 && [[ -t 1 ]]; then
1325
GREEN="$(tput setaf 2)"; RED="$(tput setaf 1)"; BLUE="$(tput setaf 4)"
@@ -23,62 +35,217 @@ if [[ ${EUID:-$UID} -ne 0 ]]; then
2335
exec sudo -E bash "$0" "$@"
2436
fi
2537

26-
# ----------------------------- URLs des scripts --------------------------------
38+
# ----------------------------- URLs des scripts -------------------------------
2739
DOCKER_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/dockerinstall.sh"
2840
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"
41+
NEW_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/refs/heads/fix/script-new-interactive-mode/.assets/new.sh"
3042
SPEED_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/speedtest.sh"
3143
FASTFETCH_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/fastfetch-install.sh"
3244
PANEL_REINSTALL_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/.assets/pterodactylpanelreinstall.sh"
3345
PTERO_MENU_URL="https://raw.githubusercontent.com/OverStyleFR/Pterodactyl-Installer-Menu/main/PterodactylMenu.sh"
3446
SSH_MENU_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/menu_id.sh"
3547

36-
# ------------------------------- Helpers --------------------------------------
37-
pause() { read -n 1 -s -r -p "Appuyez sur une touche pour retourner au menu..." ; echo; }
48+
# ------------------------------ Options new.sh --------------------------------
49+
NEW_F_DEBUG=0
50+
NEW_F_DRYRUN=0
51+
NEW_F_QUIET=0
52+
NEW_EXTRA_ARGS=""
53+
declare -a NEW_FLAGS=()
3854

39-
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; }
55+
build_new_flags() {
56+
NEW_FLAGS=()
57+
(( NEW_F_DEBUG )) && NEW_FLAGS+=(--debug)
58+
(( NEW_F_DRYRUN )) && NEW_FLAGS+=(--dry-run)
59+
(( NEW_F_QUIET )) && NEW_FLAGS+=(--quiet)
60+
if [[ -n "$NEW_EXTRA_ARGS" ]]; then
61+
# shellcheck disable=SC2206
62+
local extra=( $NEW_EXTRA_ARGS )
63+
NEW_FLAGS+=( "${extra[@]}" )
64+
fi
65+
}
66+
flags_inline_if_any() {
67+
build_new_flags
68+
((${#NEW_FLAGS[@]})) && echo " [${NEW_FLAGS[*]}]" || echo ""
69+
}
4470

71+
# ------------------------------- Helpers communs ------------------------------
72+
download_to_tmp() {
73+
local url="$1" prefix="${2:-script}" tmp
74+
tmp="$(mktemp -p /tmp "${prefix}.XXXXXX")" || { echo "mktemp a échoué"; return 98; }
4575
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
76+
curl -fsSL --retry 3 --retry-delay 1 "$url" -o "$tmp" || { rm -f "$tmp"; return 90; }
4977
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
78+
wget -q "$url" -O "$tmp" || { rm -f "$tmp"; return 90; }
5379
else
54-
echo -e "${RED}${BOLD}Ni curl ni wget disponible pour télécharger${RESET}"; rm -f "$tmp"; return 91
80+
rm -f "$tmp"; return 91
5581
fi
56-
5782
chmod +x "$tmp"
58-
printf "%s" "$tmp" # retourne le chemin
83+
printf "%s" "$tmp"
5984
}
60-
6185
run_remote() {
62-
# $1=url $2=nom_affiché
63-
local url="$1" label="${2:-script}" tmp rc
86+
local url="$1" label="${2:-script}"; shift 2 || true
87+
local args=( "$@" ) tmp rc
6488
echo -e "${YELLOW}${BOLD}Téléchargement de ${label}${RESET}"
6589
if ! tmp="$(download_to_tmp "$url" "$label")"; then
66-
echo -e "${RED}${BOLD}Échec de préparation pour ${label}${RESET}"
67-
return 90
90+
echo -e "${RED}${BOLD}Échec de téléchargement.${RESET}"; return 90
6891
fi
6992
echo -e "${YELLOW}${BOLD}Exécution de ${label}${RESET}"
70-
bash "$tmp"; rc=$?
93+
bash "$tmp" "${args[@]}"; rc=$?
7194
rm -f "$tmp" 2>/dev/null || true
7295
if [[ $rc -eq 0 ]]; then
7396
echo -e "${GREEN}${BOLD}${label} terminé avec succès${RESET}"
7497
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: /"
98+
echo -e "${RED}${BOLD}${label} a échoué (rc=$rc)${RESET}"
99+
ls -1 /var/log/new-basics-*.log 2>/dev/null | tail -n 1 | sed "s/^/Dernier log : /"
77100
fi
78101
return $rc
79102
}
80103

81-
draw_menu() {
104+
# =============================== UI: WHIPTAIL/DIALOG ==========================
105+
DIALOG_BIN=""
106+
if [[ $FORCE_BASH -eq 0 ]]; then
107+
if command -v whiptail >/dev/null 2>&1; then
108+
DIALOG_BIN="whiptail"
109+
elif command -v dialog >/dev/null 2>&1; then
110+
DIALOG_BIN="dialog"
111+
fi
112+
fi
113+
114+
ui_menu() {
115+
local title="$1" prompt="$2" h="$3" w="$4" mh="$5"; shift 5
116+
local status out
117+
if [[ "$DIALOG_BIN" == "whiptail" ]]; then
118+
out=$(whiptail --title "$title" --ok-button "OK" --cancel-button "Cancel" \
119+
--menu "$prompt" "$h" "$w" "$mh" "$@" 3>&1 1>&2 2>&3)
120+
status=$?
121+
else
122+
out=$(dialog --title "$title" --ok-label "OK" --cancel-label "Cancel" \
123+
--menu "$prompt" "$h" "$w" "$mh" "$@" 3>&1 1>&2 2>&3)
124+
status=$?
125+
fi
126+
printf "%s" "$out"
127+
return $status
128+
}
129+
ui_msg() {
130+
local title="$1" msg="$2"
131+
if [[ "$DIALOG_BIN" == "whiptail" ]]; then
132+
whiptail --title "$title" --msgbox "$msg" 13 70
133+
else
134+
dialog --title "$title" --msgbox "$msg" 13 70
135+
fi
136+
}
137+
adv_menu_ui() {
138+
local dbg="OFF" dry="OFF" qui="OFF" sel status
139+
(( NEW_F_DEBUG )) && dbg="ON"
140+
(( NEW_F_DRYRUN )) && dry="ON"
141+
(( NEW_F_QUIET )) && qui="ON"
142+
if [[ "$DIALOG_BIN" == "whiptail" ]]; then
143+
sel=$(whiptail --title "Options avancées (new.sh)" \
144+
--checklist "Sélectionne les flags à activer :" 16 70 6 \
145+
DEBUG "Activer --debug (bash -x + logs DEBUG)" "$dbg" \
146+
DRYRUN "Activer --dry-run (simulation)" "$dry" \
147+
QUIET "Activer --quiet (console moins bavarde)" "$qui" \
148+
3>&1 1>&2 2>&3); status=$?
149+
else
150+
sel=$(dialog --title "Options avancées (new.sh)" \
151+
--checklist "Sélectionne les flags à activer :" 16 70 6 \
152+
DEBUG "Activer --debug (bash -x + logs DEBUG)" "$dbg" \
153+
DRYRUN "Activer --dry-run (simulation)" "$dry" \
154+
QUIET "Activer --quiet (console moins bavarde)" "$qui" \
155+
3>&1 1>&2 2>&3); status=$?
156+
fi
157+
[[ $status -ne 0 ]] && return 0
158+
NEW_F_DEBUG=0; NEW_F_DRYRUN=0; NEW_F_QUIET=0
159+
for t in $sel; do
160+
t="${t%\"}"; t="${t#\"}"
161+
case "$t" in
162+
DEBUG) NEW_F_DEBUG=1 ;;
163+
DRYRUN) NEW_F_DRYRUN=1 ;;
164+
QUIET) NEW_F_QUIET=1 ;;
165+
esac
166+
done
167+
local extra
168+
if [[ "$DIALOG_BIN" == "whiptail" ]]; then
169+
extra=$(whiptail --title "Arguments libres (new.sh)" \
170+
--inputbox "Autres arguments (ex: --log /tmp/x.log) :" 10 70 "$NEW_EXTRA_ARGS" \
171+
3>&1 1>&2 2>&3); status=$?
172+
else
173+
extra=$(dialog --title "Arguments libres (new.sh)" \
174+
--inputbox "Autres arguments (ex: --log /tmp/x.log) :" 10 70 "$NEW_EXTRA_ARGS" \
175+
3>&1 1>&2 2>&3); status=$?
176+
fi
177+
[[ $status -ne 0 ]] && return 0
178+
NEW_EXTRA_ARGS="$extra"
179+
ui_msg "Options mises à jour" "new.sh sera lancé avec : $(flags_inline_if_any)"
180+
}
181+
submenu_installation_ui() {
182+
while true; do
183+
local sel; sel=$(ui_menu "Installation" "Choisis une action :" 15 70 6 \
184+
1 "Installer docker" \
185+
2 "Installer yarn" \
186+
3 "Retour")
187+
case $? in 1|255) return 0 ;; esac
188+
case "$sel" in
189+
1) run_remote "$DOCKER_URL" "dockerinstall.sh" ;;
190+
2) run_remote "$YARN_URL" "yarninstall.sh" ;;
191+
3|"") return 0 ;;
192+
esac
193+
done
194+
}
195+
submenu_scripts_ui() {
196+
while true; do
197+
local flags; flags="$(flags_inline_if_any)"
198+
local sel; sel=$(ui_menu "Scripts" "Choisis un script à exécuter :" 20 78 8 \
199+
1 "Exécuter 'new.sh'${flags}" \
200+
2 "Exécuter 'speedtest.sh'" \
201+
3 "Exécuter 'fastfetch-install.sh'" \
202+
4 "Exécuter 'pterodactyl-panel-reinstaller'" \
203+
5 "Retour")
204+
case $? in 1|255) return 0 ;; esac
205+
case "$sel" in
206+
1) build_new_flags; run_remote "$NEW_URL" "new.sh" "${NEW_FLAGS[@]}" ;;
207+
2) run_remote "$SPEED_URL" "speedtest.sh" ;;
208+
3) run_remote "$FASTFETCH_URL" "fastfetch-install.sh" ;;
209+
4) run_remote "$PANEL_REINSTALL_URL" "pterodactylpanelreinstall.sh" ;;
210+
5|"") return 0 ;;
211+
esac
212+
done
213+
}
214+
submenu_autres_ui() {
215+
while true; do
216+
local sel; sel=$(ui_menu "Autres menus" "Choisis une action :" 15 70 6 \
217+
1 "Exécuter le Pterodactyl Menu" \
218+
2 "Menu SSH" \
219+
3 "Retour")
220+
case $? in 1|255) return 0 ;; esac
221+
case "$sel" in
222+
1) run_remote "$PTERO_MENU_URL" "PterodactylMenu.sh" ;;
223+
2) run_remote "$SSH_MENU_URL" "menu_id.sh" ;;
224+
3|"") return 0 ;;
225+
esac
226+
done
227+
}
228+
main_menu_ui() {
229+
while true; do
230+
local sel; sel=$(ui_menu "Menu principal" "Sélectionne une catégorie :" 16 60 6 \
231+
1 "Installation" \
232+
2 "Scripts" \
233+
3 "Autres menus" \
234+
4 "Options avancées (new.sh)")
235+
case $? in 1|255) exit 0 ;; esac
236+
case "$sel" in
237+
1) submenu_installation_ui ;;
238+
2) submenu_scripts_ui ;;
239+
3) submenu_autres_ui ;;
240+
4) adv_menu_ui ;;
241+
esac
242+
done
243+
}
244+
245+
# =============================== UI: MENU BASH (ASCII) ========================
246+
pause() { read -n 1 -s -r -p "Appuyez sur une touche pour retourner au menu..." ; echo; }
247+
248+
draw_ascii_menu() {
82249
clear
83250
echo " +------------+"
84251
echo " | ${BOLD}${VIOLET}M${GREEN}e${YELLOW}n${BLUE}u${RESET}${BOLD} :${RESET} |"
@@ -93,38 +260,44 @@ draw_menu() {
93260
echo " | ${GREEN}${BOLD}Script${RESET}${BOLD} :${RESET} |"
94261
echo " +-------------+-------------+----------------+"
95262
echo " | 3. Exécuter 'new.sh' |"
96-
echo " | |"
97263
echo " | 4. Exécuter 'speedtest.sh' |"
98-
echo " | |"
99-
echo " | 5. Exécuter 'fastfetch.sh' |"
100-
echo " | |"
264+
echo " | 5. Exécuter 'fastfetch-install.sh' |"
101265
echo " | 6. Exécuter 'pterodactyl-panel-reinstaller'|"
102266
echo " +--------------------------------------------+"
103267
echo " | 7. ${BLUE}${BOLD}Exécuter le Pterodactyl Menu${RESET} |"
104268
echo " | └ ${YELLOW}${BOLD}OverStyleFR/Pterodactyl-Installer-Menu${RESET} |"
105269
echo " +--------------------------------------------+"
106-
echo " | 8. ${BOLD}${VIOLET}M${GREEN}e${YELLOW}n${BLUE}u${RESET}${BOLD} SSH ${RESET} |"
270+
echo " | 8. ${BOLD}${VIOLET}Menu SSH ${RESET} |"
107271
echo " | └ ${VIOLET}${BOLD}OverStyleFR/AutoScriptBash${RESET} |"
108272
echo " +-------------+------------+-----------------+"
109273
echo " | ${RED}${BOLD}9. Quitter${RESET} |"
110274
echo " +------------+"
111275
echo
112276
}
113277

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
278+
main_menu_ascii() {
279+
while true; do
280+
draw_ascii_menu
281+
read -rp "Choisissez une option (1-9) : " choix
282+
case "${choix:-}" in
283+
1) echo "Installation de Docker." ; run_remote "$DOCKER_URL" "dockerinstall.sh" ; pause ;;
284+
2) echo "Installation de Yarn." ; run_remote "$YARN_URL" "yarninstall.sh" ; pause ;;
285+
3) echo "Exécution du script 'new.sh'." ; build_new_flags; run_remote "$NEW_URL" "new.sh" "${NEW_FLAGS[@]}"; pause ;;
286+
4) echo "Exécution du script 'speedtest.sh'." ; run_remote "$SPEED_URL" "speedtest.sh" ; pause ;;
287+
5) echo "Exécution du script 'fastfetch-install.sh'." ; run_remote "$FASTFETCH_URL" "fastfetch-install.sh" ; pause ;;
288+
6) echo "Exécution du script 'pterodactyl-panel-reinstaller'." ; run_remote "$PANEL_REINSTALL_URL" "pterodactylpanelreinstall.sh" ; pause ;;
289+
7) echo -e "${BLUE}${BOLD}Exécuter le Pterodactyl Menu${RESET}" ; run_remote "$PTERO_MENU_URL" "PterodactylMenu.sh" ; pause ;;
290+
8) echo -e "${BOLD}${VIOLET}Menu SSH${RESET}" ; run_remote "$SSH_MENU_URL" "menu_id.sh" ; pause ;;
291+
9) echo "Au revoir !" ; exit 0 ;;
292+
*) echo -e "${RED}Choix non valide. Veuillez entrer un numéro entre 1 et 9.${RESET}"; sleep 1 ;;
293+
esac
294+
done
295+
}
296+
297+
# =============================== Lancement ====================================
298+
if [[ -n "$DIALOG_BIN" ]]; then
299+
main_menu_ui
300+
else
301+
echo "(UI Bash : whiptail/dialog indisponibles ou --bash forcé)"
302+
main_menu_ascii
303+
fi

0 commit comments

Comments
 (0)