kyopages/scripts/tests/test_guiDialog

310 lines
11 KiB
Bash
Executable File

#!/bin/bash
version=1.0.0
date=18/09/2017
script="$(basename $0)"
urlNotice="https://kyodev.frama.io/kyopages/scripts/getInfo/"
# assigne $affichage_text
f_g_affichage(){ # 19/09/2017
f_g_color
affichage_text=" _ ___ __
__ _ ___| |_|_ _|_ __ / _| ___
/ _' |/ _ \ __|| || '_ \| |_ / _ \
| (_| | __/ |_ | || | | | _| (_) |
\__, |\___|\__|___|_| |_|_| \___/
|___/
"
case $context_appli in
terminal)
echo -e "$affichage_text\n$YELLOW version $version - $date$COLOR\n"
;;
zenity)
affichage_text="$(sed 's/\\/\\\\/g' <<< $affichage_text)"
affichage_text+="\n$YELLOW version $version - $date</span>"
# zenity --info --icon-name preferences-system --no-wrap --timeout 3 --title "$script $version" \
# --text="<span font-family=\"monospace\">$(f_g_lint zen "$affichage_text")</span>\n$g_espaces$g_espaces"
;;
esac
}
#system-help applications-internet go-up go-top
#https://developer.gnome.org/icon-naming-spec/#names
f_g_color(){ # 18/09/2017
case $context_appli in
terminal)
RED="$(printf "\033[0;31m")" # alerte
GREEN="$(printf "\033[0;32m")" # ok
YELLOW="$(printf "\033[0;33m")" # question
BLUE="$(printf "\033[0;34m")" # info
# COLOR="$(printf "\033[0m")" # standard par défaut, black
COLOR="$(tput sgr0)" # standard par défaut, black
MAGENTA="$(printf "\033[0;35m")"
CYAN="$(printf "\033[0;36m")"
WHITE="$(printf "\033[0;37m")"
comment(){
tput setab 7 # background white ??!! gris clair! tput setb 7 (HP)
tput setaf 0 # foreground black
clear
tput setab 7 # background white ??!! gris clair! tput setb 7 (HP)
tput setaf 0 # foreground black
clear
tput sgr0 & clear # effacement attribut -> réglages par défaut
\033[code_police;couleur_texte;couleur_fondm
COULEUR....TEXTE....ARRIÈRE-PLAN
Noir 30 40
Rouge 31 41
Vert 32 42
Jaune 33 43
Bleu 34 44
Magenta 35 45
Cyan 36 46
Blanc 37 47
Tektronix-type terminal voir tput setaf ou setab
BLACK 0 0, 0, 0
RED 1 max,0,0
GREEN 2 0,max,0
YELLOW 3 max,max,0
BLUE 4 0,0,max
MAGENTA 5 max,0,max
CYAN 6 0,max,max
WHITE 7 max,max,max
}
;;
zenity)
# red green blue yellow magenta white black gray lightblue lightgray violet purple teal navy MediumBlue Brown Chocolate
# http://htmlcolorcodes.com/fr/noms-de-couleur/
YELLOW="<span color=\"Chocolate\">" #D2691E
GREEN="<span color=\"green\">" #008000
BLUE="<span color=\"MediumBlue\">" # blue: 0000FF
RED="<span color=\"red\">" #FF0000
COLOR="<span color=\"black\">" #000000
;;
esac
}
# assigne $context_appli, context_break
f_g_context(){ # 15/09/2017
g_espaces="$(printf " %.s" $(seq 40))" # nb d'espaces pour élargir la fenêtre
if [ -t 0 ]; then context_appli="terminal";
elif [ -x /usr/bin/zenity ]; then context_appli="zenity";
elif [ -x /usr/bin/kdialog ]; then context_appli="kdialog";
else exit 1; fi
}
# $1=oui|non réponse par défaut, $2=message de la question, return 0 pour oui, 1 pour non
f_g_dialog_oui_non () { # 18/09/2017
local reply
[[ "$1" =~ ^oui$|^non$ ]] || f_g_error "dialog_oui_non, erreur \$1 fonction"
case $context_appli in
terminal )
printf "$BLUE $2"
[ "$1" == "oui" ] && printf " [O/n] " || printf " [o/N] "
printf "$COLOR"
read -r reply
if [ -z "$reply" ]; then
[ "$1" == "oui" ] && reply="oui" || reply="non"
fi
if [[ ${reply,,} =~ ^ou?i?$ ]]; then return 0; else return 1; fi #${,,} lowercase
;;
zenity )
local yes no default_cancel
[ "$1" != "oui" ] && default_cancel="--default-cancel" # non par défaut
zenity --question "$default_cancel" --ok-label "Oui" --cancel-label "Non" --no-wrap \
--title "$script $version" --text="<span color=\"$YELLOW\"> $(f_g_lint zen "$2") </span>\n$g_espaces"
[ "$?" -eq 0 ] && return 0 || return 1
# if [ "$?" -eq 0 ]; then return 0
# elif [ "$?" -eq 1 ]; then return 1
# elif [ "$?" -eq -1 ]; then f_g_error "erreur inattendue"
# elif [ "$?" -eq 5 ]; then f_g_info "timeout"
# else return 1
# fi
;;
esac
}
# affichage $1 en rouge, $1++ optionnels en bleu, sortie script sur erreur, log $1 si $opType=upgrade
# pas de balisage dans $1 pour éviter pollution logs
# pour inclure un balisage couleur à lintérieur d'un paramètre: $COULEUR texte</span>
f_g_error() { # 23/09/2017
local text depart=2
text="$RED $script $version, erreur critique: $1"
case $context_appli in
terminal)
text+="$COLOR\n"
for (( i="$depart" ; i<="$#" ; i++ )); do text+="$BLUE ${!i}$COLOR\n"; done
unset i
echo -e "$(f_g_lint trm "$text")"
if [ "$opType" == "upgrade" ]; then f__log "$script $version: $1"; fi
exit 1
;;
zenity)
text+="</span>\n"
for (( i="$depart" ; i<="$#" ; i++ )); do text+="$BLUE ${!i}</span>\n"; done
unset i
zenity --error --no-wrap --title "$script $version, erreur critique" \
--text="$(f_g_lint zen "$text")\n$g_espaces"
;;
esac
}
# affichage des paramètres en bleu, si $1=raw pas de ligne vide à la fin, si $1=log $2 uniquement logué
# pour inclure un balisage couleur à lintérieur d'un paramètre: $COULEUR texte</span>
f_g_info() { # 23/09/2017
local text depart=1
if [ "$1" == "raw" ] || [ "$1" == "log" ]; then depart=2; fi
[ "$1" == "log" ] && f__log "$(sed -E 's/\\t//;s/\\n// ' <<< $2 | xargs )"
case $context_appli in
terminal)
for (( i="$depart" ; i<="$#" ; i++ )); do text+="$BLUE $(sed "s/<\/span>/$COLOR/" <<< ${!i})$COLOR\n"; done
[ "$1" == raw ] && printf "$(f_g_lint trm "$text")" || echo -e "$(f_g_lint trm "$text")"
unset i
;;
zenity)
for (( i="$depart" ; i<="$#" ; i++ )); do text+="$BLUE ${!i}</span>\n"; done
zenity --info --no-wrap --title "$script $version" --text="$(f_g_lint zen "$text")\n$g_espaces"
unset i
;;
esac
}
# $1=trm|zen|kdi $2=texte à nettoyer
f_g_lint(){ # 20/09/2017
case "$1" in
trm)
sed "s/<\/span>/$COLOR/g" <<< "$2"
;;
zen)
sed 's/&/&amp;/g' <<< "$2"
;;
esac
}
fg_help(){ # 19/09/2017
local text
text+=" ./getInfo : exécution normale, rapport markdown configuration & diagnostic
getInfo : exécution normale si script installé dans le système
options:
-d, --dmesg : dmesg erreur, warning, critique.$RED root requis</span>$BLUE, rapport markdown seul de dmesg
-h, --help : affichage aide
-l, --list : afficher le rapport markdown existant
-p, --paste : exporte le rapport markdown existant, durée du paste standard 7 jours
--ip : affiche ip(s) publique(s) (ipv4 / ipv6), infos confidentielles, sans rapport markdown
-m, --mac : affiche les adresses Mac, infos confidentielles, sans rapport markdown
-s, --ssid : affiche configurations ssid, infos confidentielles
pas de rapport markdown, root et NetworkManager requis
debug : le résultat json du paste sera affiché après export
-tn : durée du paste de n jour(s)
-i, --install : installation du script dans le système, droits root requis
-r, --remove : suppression du script dans le système, droits root requis
-u, --upgrade : upgrade script si maj possible
-v, --version : version du script, en ligne et en cours d'exécution</span>
"
text+="\n plus d'infos: $GREEN$urlNotice</span>"
case $context_appli in
terminal)
echo -e "$BLUE$(f_g_lint trm "$text")$COLOR\n"
;;
zenity)
local text2="$(f_g_lint zen "$affichage_text")\n"
text2+="$GREEN<b> ------------------------------------ OPTIONS EN CONSOLE TERMINAL -----</b></span>\n"
text2+="$(f_g_lint zen "$text")\n"
zenity --info --icon-name=preferences-system --no-wrap --title "$script $version" \
--text="<span font-family=\"monospace\">$BLUE$text2</span></span>\n$g_espaces$g_espaces"
;;
esac
}
##################################""
f_g_context
f_g_affichage
# création lanceur.desktop
scrpt_lanceur_desktop(){ # 21/09/2017
# local fileDesktop="/usr/share/applications/$script.desktop"
local fileDesktop="$HOME/.local/share/applications/"$script".desktop"
rm "$fileDesktop"
# echo "#!/usr/bin/env xdg-open" > "$fileDesktop"
echo "[Desktop Entry]" >> "$fileDesktop"
echo "Name=$script" >> "$fileDesktop"
echo "Name[fr]=$script" >> "$fileDesktop"
echo "X-GNOME-FullName=$script" >> "$fileDesktop"
echo "X-GNOME-FullName[fr]=$script" >> "$fileDesktop"
echo "StartupWMClass=$script" >> "$fileDesktop"
# echo "Exec=/usr/bin/$script" >> "$fileDesktop"
# echo Exec=$HOME/kyopages/scripts/"$script" >> "$fileDesktop"
echo "Exec=$HOME/.local/bin/$script" >> "$fileDesktop"
echo "Icon=preferences-system" >> "$fileDesktop"
echo "Comment=System infos and pastebin with markdown format" >> "$fileDesktop"
echo "Comment[fr]=Infos système et pastebin au format markdown" >> "$fileDesktop"
echo "GenericName=System infos" >> "$fileDesktop"
echo "GenericName[fr]=Système infos" >> "$fileDesktop"
echo "Terminal=false" >> "$fileDesktop"
echo "X-MultipleArgs=false" >> "$fileDesktop"
echo "Type=Application" >> "$fileDesktop"
echo "Categories=System;" >> "$fileDesktop"
echo "StartupNotify=true" >> "$fileDesktop"
}
#fileDesktop=$HOME/.local/share/applications/"$script".desktop # +x pas obligatoire pour DE
#chmod -x $fileDesktop
#cp ~/kyopages/scripts/"$script" $HOME/.local/bin/"$script"
#chmod +x $HOME/.local/bin/"$script"
scrpt_lanceur_desktop
#fg_help
exit
f_g_info raw "Certaines$GREEN boîtes de dialogue</span> Zenity permettent l'utilisation de touches d'accès." \
"Pour indiquer la lettre à utiliser comme$RED touche d'accès</span>, placez un souligné _" \
"avant cette lettre dans le texte de la boîte de dialogue."
f_g_info "FIN"
f_g_error "Certaines$RED boîtes de dialogue</span> de Zenity permettent l'utilisation de touches d'accès." \
"Pour indiquer la lettre à utiliser comme$GREEN touche d'accès</span>, placez un souligné _" \
"avant cette lettre dans le texte de la boîte de dialogue."
if f_g_dialog_oui_non "non" "continuer?"; then
f_g_info "raw" "réponse oui,$GREEN script</span>"
else
f_g_info "raw" "réponse non,$GREEN sortie</span>"
exit
fi;
echo "Script:$script"
systemd-path | less
ps -p1 | grep systemd && userBinaires=$(systemd-path user-binaries) || userBinaires=$($HOME/.local/bin)
cat /etc/profile.d/debian-mate-default-settings_gtk-accessibility.sh
echo "# Set path to MYSTUFF folder if it exists." >> /etc/profile.d/mystuff.sh
echo "# Added /usr/local/mystuff folder for myprogram." >> /etc/profile.d/mystuff.sh
echo "[ -d /usr/local/mystuff ] && PATH=$PATH:/usr/local/mystuff" >> /etc/profile.d/mystuff.sh
man file-hierarchy
~/.local/bin
Executables that shall appear in the user s $PATH search path. It is recommended not to place executables in this directory that are not useful
for invocation from a shell; these should be placed in a subdirectory of ~/.local/lib instead. Care should be taken when placing
architecture-dependent binaries in this place, which might be problematic if the home directory is shared between multiple hosts with different
architectures.
initial(){
if [ "$1" == "oui" ]; then
if [[ ! ${reply,,} =~ ^no?n?$ ]]; then return 0; else return 1; fi #*{,,} lowercase
elif [ "$1" == "non" ]; then
if [[ ! ${reply,,} =~ ^ou?i?$ ]]; then return 0; else return 1; fi
fi
}