variables courte pour la hauteur et la largeur

gestion du choix Créer un nouveau profil/dépôt
gestion du choix Afficher les profils
This commit is contained in:
Djan GICQUEL 2021-08-03 16:55:22 +02:00
parent 1b4c040524
commit 131ba2f400
1 changed files with 59 additions and 15 deletions

View File

@ -1,30 +1,74 @@
#! /bin/bash
W="600"
H="500"
ZenityPulsate () {
zenity $W --window-icon=$HOME/.icons/borg.svg --progress --pulsate --auto-close
}
W="--width=600"
H="--height=500"
dossierprofil="$HOME/.config/borg/"
cd $dossierprofil
# affichage du menu
choixmenu=$(echo -e "\
cp\nCréer un nouveau profil\n\
ap\nAfficher les profils\
" | zenity --height=$H --width=$W --window-icon=$HOME/.icons/borg.svg --list \
cp\nCréer un nouveau profil/dépôt\n\
ap\nAfficher les profils\n\
" | zenity $H $W --window-icon=$HOME/.icons/borg.svg --list \
--column "id" --column "choix")
if [ "$choixmenu" = "cp" ];then
choixdossier=$(zenity --file-selection --directory)
# gestion des choix du menu
if [ -z "$(ls -A $choixdossier)" ]; then
zenity --width=$W --window-icon=$HOME/.icons/borg.svg --progress --pulsate --auto-close | zenity --notification --text "Initialisation du dépôt..."
else
zenity --width=$W --error --text="Erreur, le dossier n'est pas vide."
if [ "$choixmenu" = "cp" ];then
# Créer un nouveau profil/dépôt
borg_repo=$(zenity --file-selection --directory)
if [ ! -z "$(ls -A $borg_repo)" ]; then
zenity $W --error --text="Erreur, le dossier n'est pas vide."
exit
fi
zenity $W --question --text "Chiffrer le dépôt ? (fortement recommandé)"
elif [ "$choixmenu" = "ap" ];then
fichierprofil=$(ls -1 *.txt | zenity --height=$H --width=$W --window-icon=$HOME/.icons/borg.svg --list --title "Liste des profils" --text "Choisir un profil dans la liste" --hide-header --column "profil")
zenity --width=$W --height=$H --info --text="<tt>$(cd $dossierprofil && cat $fichierprofil)</tt>"
if [ "$?" = "0" ];then
zenity $W --warning --text \
"Le fichier-clé du dépot sera stocké dans le dossier <tt>$HOME/.config/borg/keys/</tt>.\n\n\
Veuillez à sauvegarder ce dossier dans un endroit sûr.\n\n\
Si cette clé ne peut être lue les données ne seront pas récupérables.\n\n\
Notez qu'il n'existe aucun mécanisme de récupération de clé."
borg init $borg_repo | ZenityPulsate
zenity $W --info --text "Un nouveau dépot chiffré a été généré dans <tt>$borg_repo</tt>"
elif [ "$?" = "1" ];then
zenity $W --warning --text \
"Je comprends qu'en ne sécurisant pas mon dépot les données qu'il contient seront librement accessible par toute personne ayant accès aux fichiers du dépôt."
borg init --encryption none $borg_repo | ZenityPulsate
zenity $W --info --text "Un nouveau dépot en clair a été généré dans <tt>$borg_repo</tt>"
fi
borg_dir=$(zenity --title "Dossier à sauvegarder" --file-selection --directory)
vars=$(zenity --forms \
--text "Laisser les champs vides pour les options par défaut" \
--add-entry "Nom de sauvegarde" \
--add-entry "Nom de profil (pas d'espace ni caractères spéciaux)")
nomsauvegarde=$(echo $vars | cut -d\| -f1)
profilename=$(echo $vars | cut -d\| -f2)
cat << EOF >> $HOME/.config/borg/"$profilename".txt
nomsauvegarde="$nomsauvegarde"
borg_repo="$borg_repo"
borg_archive="\$(date +%d_%B_%Y)"
borg_dir="$borg_dir"
borg_excludes=""
borg_compress=""
dryrun=""
EOF
elif [ "$choixmenu" = "ap" ];then
# Afficher les profils
fichierprofil=$(ls -1 *.txt | zenity $H $W --window-icon=$HOME/.icons/borg.svg --list --title "Liste des profils" --text "Choisir un profil dans la liste" --hide-header --column "profil")
zenity $W $H --info --text="<tt>$(cd $dossierprofil && cat $fichierprofil)</tt>"
elif [ "$choixmenu" = "" ];then
zenity --width=$W --info --text="Aucun choix, retour au menu."
exit
fi