Bash : Whiptail
De www.yakakliker.org
Msgbox
whiptail --title "Déploiement" --fb --msgbox " Avant d'aller plus loin, veillez à avoir ces différentes informations en votre possession :" 20 100
--yesno
if (whiptail --title "Déploiement" --fb --yesno "Souhaitez vous continuer ?" 10 60);
then
echo "ok"
else
echo "Fin"
fi
Choix multiples
#Fonction 1
fct003(){
echo "Action 1"
exit $?
}
#Fonction 2
fct004(){
echo "Action 2"
exit $?
}
#Fonction 3
fct008(){
echo "Sortie du script"
exit $?
}
#Choix multiple
OPTION=$(whiptail --title "Deploiement" --fb --menu "Que souhaitez vous faire ?" 15 60 6 \
"fct003" " Action 1" \
"fct004" " Action 2" \
"fct008" " Quitter le script" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
$OPTION
else
fct008
fi
Inputbox
variable=$(whiptail --title "Adresse IP" --fb --inputbox "Entrez l'adresse IP ou le nom du Srv" 10 60 3>&1 1>&2 2>&3)
echo $variable
Passwordbox
variable=$(whiptail --title "Passroot" --fb --passwordbox "Entrez le mot de passe root de connexion" 10 60 3>&1 1>&2 2>&3)
echo $variable
Personnaliser les couleurs
export NEWT_COLORS='
window=,red
border=white,red
textbox=white,red
button=black,white'
# to reset the color back to default use:
# unset NEWT_COLORS
root root fg, bg
border border fg, bg
window window fg, bg
shadow shadow fg, bg
title title fg, bg
button button fg, bg
actbutton active button fg, bg
checkbox checkbox fg, bg
actcheckbox active checkbox fg, bg
entry entry box fg, bg
label label fg, bg
listbox listbox fg, bg
actlistbox active listbox fg, bg
textbox textbox fg, bg
acttextbox active textbox fg, bg
helpline help line
roottext root text
emptyscale scale full
fullscale scale empty
disentry disabled entry fg, bg
compactbutton compact button fg, bg
actsellistbox active & sel listbox
sellistbox selected listbox
bg and fg can be:
color0 or black
color1 or red
color2 or green
color3 or brown
color4 or blue
color5 or magenta
color6 or cyan
color7 or lightgray
color8 or gray
color9 or brightred
color10 or brightgreen
color11 or yellow
color12 or brightblue
color13 or brightmagenta
color14 or brightcyan
color15 or white
Liens
https://man.developpez.com/man1/whiptail/
https://github.com/JazerBarclay/whiptail-examples
https://funprojects.blog/2022/04/06/text-interfaces-with-whiptail-and-dialog/