Skip to content

Commit 15263fc

Browse files
committed
Update | Categories & Advanced settings
Ajout des catégories. Ajout d'option avancé pour utiliser des flags (que new.sh pour l'instant). Point à améliorer : - Si possible utiliser Whiptail par défaut mais basculer sur le menu bash si cas échéant. - Avoir la possibilité de utiliser un flag --bash afin de forcer le lancement du script via bash.
1 parent 60b535b commit 15263fc

File tree

1 file changed

+179
-90
lines changed

1 file changed

+179
-90
lines changed

menu.sh

Lines changed: 179 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env bash
22
# ==============================================================================
3-
# menu.sh — TUI façon raspi-config (whiptail/dialog) pour lancer les scripts
4-
#
3+
# menu.sh — TUI façon raspi-config (whiptail/dialog) avec sous-menus + options
4+
# - Cancel fonctionne partout (main + sous-menus)
5+
# - Les flags de new.sh n'apparaissent que s'il y en a
56
# USAGE :
67
# sudo ./menu.sh
78
# ==============================================================================
@@ -24,33 +25,131 @@ PANEL_REINSTALL_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBas
2425
PTERO_MENU_URL="https://raw.githubusercontent.com/OverStyleFR/Pterodactyl-Installer-Menu/main/PterodactylMenu.sh"
2526
SSH_MENU_URL="https://raw.githubusercontent.com/OverStyleFR/AutoScriptBash/main/menu_id.sh"
2627

27-
# ------------------------------ UI backend ------------------------------------
28+
# ------------------------------ Backend UI ------------------------------------
2829
DIALOG_BIN=""
2930
if command -v whiptail >/dev/null 2>&1; then
3031
DIALOG_BIN="whiptail"
3132
elif command -v dialog >/dev/null 2>&1; then
3233
DIALOG_BIN="dialog"
3334
else
34-
# petit essai d’installation silencieuse côté apt ; sinon fallback texte
3535
if command -v apt-get >/dev/null 2>&1; then
3636
apt-get update -y >/dev/null 2>&1 || true
3737
apt-get install -y whiptail >/dev/null 2>&1 || true
3838
command -v whiptail >/dev/null 2>&1 && DIALOG_BIN="whiptail"
3939
fi
4040
fi
4141

42-
msg_box() {
43-
# $1 titre, $2 message
44-
if [[ -n "$DIALOG_BIN" ]]; then
45-
$DIALOG_BIN --title "$1" --msgbox "$2" 13 70
42+
if [[ -z "$DIALOG_BIN" ]]; then
43+
echo "Ni 'whiptail' ni 'dialog' détecté. Installe 'whiptail' (apt install -y whiptail) puis relance."
44+
exit 1
45+
fi
46+
47+
# Wrapper uniforme pour --menu (retourne le choix sur stdout, et code:
48+
# 0=OK, 1=Cancel, 255=ESC)
49+
ui_menu() {
50+
local title="$1" prompt="$2" h="$3" w="$4" mh="$5"; shift 5
51+
local status out
52+
if [[ "$DIALOG_BIN" == "whiptail" ]]; then
53+
out=$(whiptail --title "$title" --ok-button "OK" --cancel-button "Cancel" \
54+
--menu "$prompt" "$h" "$w" "$mh" "$@" 3>&1 1>&2 2>&3)
55+
status=$?
56+
else
57+
out=$(dialog --title "$title" --ok-label "OK" --cancel-label "Cancel" \
58+
--menu "$prompt" "$h" "$w" "$mh" "$@" 3>&1 1>&2 2>&3)
59+
status=$?
60+
fi
61+
printf "%s" "$out"
62+
return $status
63+
}
64+
65+
ui_msg() {
66+
local title="$1" msg="$2"
67+
if [[ "$DIALOG_BIN" == "whiptail" ]]; then
68+
whiptail --title "$title" --msgbox "$msg" 13 70
69+
else
70+
dialog --title "$title" --msgbox "$msg" 13 70
71+
fi
72+
}
73+
74+
# ------------------------------ Options new.sh --------------------------------
75+
NEW_F_DEBUG=0
76+
NEW_F_DRYRUN=0
77+
NEW_F_QUIET=0
78+
NEW_EXTRA_ARGS=""
79+
declare -a NEW_FLAGS=()
80+
81+
build_new_flags() {
82+
NEW_FLAGS=()
83+
(( NEW_F_DEBUG )) && NEW_FLAGS+=(--debug)
84+
(( NEW_F_DRYRUN )) && NEW_FLAGS+=(--dry-run)
85+
(( NEW_F_QUIET )) && NEW_FLAGS+=(--quiet)
86+
if [[ -n "$NEW_EXTRA_ARGS" ]]; then
87+
# shellcheck disable=SC2206
88+
local extra=( $NEW_EXTRA_ARGS )
89+
NEW_FLAGS+=( "${extra[@]}" )
90+
fi
91+
}
92+
flags_inline_if_any() {
93+
build_new_flags
94+
if ((${#NEW_FLAGS[@]}==0)); then
95+
echo "" # rien si aucun flag (demande)
4696
else
47-
echo -e "\n==== $1 ====\n$2\n(Entrée pour continuer)"; read -r _
97+
echo " [${NEW_FLAGS[*]}]"
4898
fi
4999
}
50100

51-
# ------------------------------- Helpers --------------------------------------
101+
adv_menu() {
102+
local dbg="OFF" dry="OFF" qui="OFF"
103+
(( NEW_F_DEBUG )) && dbg="ON"
104+
(( NEW_F_DRYRUN )) && dry="ON"
105+
(( NEW_F_QUIET )) && qui="ON"
106+
107+
local sel status
108+
if [[ "$DIALOG_BIN" == "whiptail" ]]; then
109+
sel=$(whiptail --title "Options avancées (new.sh)" \
110+
--checklist "Sélectionne les flags à activer :" 16 70 6 \
111+
DEBUG "Activer --debug (bash -x + logs DEBUG)" "$dbg" \
112+
DRYRUN "Activer --dry-run (simulation)" "$dry" \
113+
QUIET "Activer --quiet (console moins bavarde)" "$qui" \
114+
3>&1 1>&2 2>&3); status=$?
115+
else
116+
sel=$(dialog --title "Options avancées (new.sh)" \
117+
--checklist "Sélectionne les flags à activer :" 16 70 6 \
118+
DEBUG "Activer --debug (bash -x + logs DEBUG)" "$dbg" \
119+
DRYRUN "Activer --dry-run (simulation)" "$dry" \
120+
QUIET "Activer --quiet (console moins bavarde)" "$qui" \
121+
3>&1 1>&2 2>&3); status=$?
122+
fi
123+
[[ $status -ne 0 ]] && return 0
124+
125+
NEW_F_DEBUG=0; NEW_F_DRYRUN=0; NEW_F_QUIET=0
126+
for t in $sel; do
127+
t="${t%\"}"; t="${t#\"}"
128+
case "$t" in
129+
DEBUG) NEW_F_DEBUG=1 ;;
130+
DRYRUN) NEW_F_DRYRUN=1 ;;
131+
QUIET) NEW_F_QUIET=1 ;;
132+
esac
133+
done
134+
135+
local extra
136+
if [[ "$DIALOG_BIN" == "whiptail" ]]; then
137+
extra=$(whiptail --title "Arguments libres (new.sh)" \
138+
--inputbox "Autres arguments (ex: --log /tmp/x.log) :" 10 70 "$NEW_EXTRA_ARGS" \
139+
3>&1 1>&2 2>&3); status=$?
140+
else
141+
extra=$(dialog --title "Arguments libres (new.sh)" \
142+
--inputbox "Autres arguments (ex: --log /tmp/x.log) :" 10 70 "$NEW_EXTRA_ARGS" \
143+
3>&1 1>&2 2>&3); status=$?
144+
fi
145+
[[ $status -ne 0 ]] && return 0
146+
NEW_EXTRA_ARGS="$extra"
147+
148+
ui_msg "Options mises à jour" "new.sh sera lancé avec : $(flags_inline_if_any)"
149+
}
150+
151+
# ------------------------------- Helpers exec ---------------------------------
52152
download_to_tmp() {
53-
# $1=url $2=prefix (nom lisible)
54153
local url="$1" prefix="${2:-script}" tmp
55154
tmp="$(mktemp -p /tmp "${prefix}.XXXXXX")" || { echo "mktemp a échoué"; return 98; }
56155
if command -v curl >/dev/null 2>&1; then
@@ -63,102 +162,92 @@ download_to_tmp() {
63162
chmod +x "$tmp"
64163
printf "%s" "$tmp"
65164
}
66-
67165
run_remote() {
68-
# $1=url $2=nom_affiché
69-
local url="$1" label="${2:-script}" tmp rc
70-
tmp="$(download_to_tmp "$url" "$label")" || {
71-
msg_box "Erreur" "Échec de téléchargement de ${label}.\nVérifie la connexion réseau."
72-
return 90
73-
}
74-
75-
clear
76-
echo "=== Exécution de ${label} ==="
77-
bash "$tmp"; rc=$?
166+
local url="$1" label="${2:-script}"; shift 2 || true
167+
local args=( "$@" ) tmp rc
168+
tmp="$(download_to_tmp "$url" "$label")" || { ui_msg "Erreur" "Échec de téléchargement de ${label}."; return 90; }
169+
clear; echo "=== Exécution de ${label} ==="
170+
bash "$tmp" "${args[@]}"; rc=$?
78171
rm -f "$tmp" 2>/dev/null || true
79-
80172
if [[ $rc -eq 0 ]]; then
81-
msg_box "Terminé" "${label} s'est terminé avec succès."
173+
ui_msg "Terminé" "${label} s'est terminé avec succès."
82174
else
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}"
175+
local hint; hint="$(ls -1 /var/log/new-basics-*.log 2>/dev/null | tail -n 1)"
176+
ui_msg "Échec" "${label} a échoué (rc=$rc).${hint:+\nDernier log : $hint}"
86177
fi
87178
return $rc
88179
}
89180

90-
# ------------------------------- Menu loop ------------------------------------
91-
text_menu() {
181+
# ------------------------------- Sous-menus ------------------------------------
182+
submenu_installation() {
92183
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
184+
local sel
185+
sel=$(ui_menu "Installation" "Choisis une action :" 15 70 6 \
186+
1 "Installer docker" \
187+
2 "Installer yarn" \
188+
3 "Retour")
189+
case $? in 1|255) return 0 ;; esac
190+
case "$sel" in
110191
1) run_remote "$DOCKER_URL" "dockerinstall.sh" ;;
111192
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-
*) ;;
193+
3|"") return 0 ;;
194+
esac
195+
done
196+
}
197+
submenu_scripts() {
198+
while true; do
199+
local flags; flags="$(flags_inline_if_any)"
200+
local sel
201+
sel=$(ui_menu "Scripts" "Choisis un script à exécuter :" 20 78 8 \
202+
1 "Exécuter 'new.sh'${flags}" \
203+
2 "Exécuter 'speedtest.sh'" \
204+
3 "Exécuter 'fastfetch-install.sh'" \
205+
4 "Exécuter 'pterodactyl-panel-reinstaller'" \
206+
5 "Retour")
207+
case $? in 1|255) return 0 ;; esac
208+
case "$sel" in
209+
1) build_new_flags; run_remote "$NEW_URL" "new.sh" "${NEW_FLAGS[@]}" ;;
210+
2) run_remote "$SPEED_URL" "speedtest.sh" ;;
211+
3) run_remote "$FASTFETCH_URL" "fastfetch-install.sh" ;;
212+
4) run_remote "$PANEL_REINSTALL_URL" "pterodactylpanelreinstall.sh" ;;
213+
5|"") return 0 ;;
214+
esac
215+
done
216+
}
217+
submenu_autres() {
218+
while true; do
219+
local sel
220+
sel=$(ui_menu "Autres menus" "Choisis une action :" 15 70 6 \
221+
1 "Exécuter le Pterodactyl Menu" \
222+
2 "Menu SSH" \
223+
3 "Retour")
224+
case $? in 1|255) return 0 ;; esac
225+
case "$sel" in
226+
1) run_remote "$PTERO_MENU_URL" "PterodactylMenu.sh" ;;
227+
2) run_remote "$SSH_MENU_URL" "menu_id.sh" ;;
228+
3|"") return 0 ;;
120229
esac
121230
done
122231
}
123232

124-
whip_menu() {
125-
local choice ret
233+
# ------------------------------- Menu principal --------------------------------
234+
main_menu() {
126235
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 ;;
236+
local sel
237+
sel=$(ui_menu "Menu principal" "Sélectionne une catégorie :" 16 60 6 \
238+
1 "Installation" \
239+
2 "Scripts" \
240+
3 "Autres menus" \
241+
4 "Options avancées (new.sh)")
242+
case $? in 1|255) exit 0 ;; esac
243+
case "$sel" in
244+
1) submenu_installation ;;
245+
2) submenu_scripts ;;
246+
3) submenu_autres ;;
247+
4) adv_menu ;;
248+
*) : ;;
153249
esac
154250
done
155251
}
156252

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
253+
main_menu

0 commit comments

Comments
 (0)