diff --git a/profile-manager.sh b/profile-manager.sh index 2d8580c..a7a2a4d 100644 --- a/profile-manager.sh +++ b/profile-manager.sh @@ -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="$(cd $dossierprofil && cat $fichierprofil)" +if [ "$?" = "0" ];then + zenity $W --warning --text \ + "Le fichier-clé du dépot sera stocké dans le dossier $HOME/.config/borg/keys/.\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 $borg_repo" +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 $borg_repo" +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="$(cd $dossierprofil && cat $fichierprofil)" elif [ "$choixmenu" = "" ];then -zenity --width=$W --info --text="Aucun choix, retour au menu." +exit fi