#! /bin/bash <<<<<<< HEAD ======= # tests de base >>>>>>> dev which zenity if [ "$?" != "0" ]; then echo "Zenity n'est pas installé.";exit exit fi <<<<<<< HEAD ======= which borg if [ "$?" != "0" ]; then echo "borgbackup n'est pas installé.";exit exit fi >>>>>>> dev # META VARIABLES ################################################################################# export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes <<<<<<< HEAD ======= dossierprofil="$HOME/.config/borg/profils-borg-zenity/" W="--width=600" H="--height=500" iconborg="--window-icon=$HOME/.icons/borg.svg" >>>>>>> dev # FONCTIONS ################################################################################# TestBorgRepo () { if [ ! -f "config" ]; then TestBorgErr=1 infoerr=$(echo "Impossible de trouver le fichier de configuration borg.") <<<<<<< HEAD zenity --width=500 --error --text="$infoerr" ======= zenity $W --error --text="$infoerr" >>>>>>> dev exit fi if [ ! -d "data" ]; then TestBorgErr=1 infoerr=$(echo "Impossible de trouver le fichier de configuration borg.") <<<<<<< HEAD zenity --width=500 --error --text="$infoerr" ======= zenity $W --error --text="$infoerr" >>>>>>> dev exit fi if [ -d "lock.exclusive" ]; then TestBorgErr=1 infoerr=$(echo "Le dépôt est bloqué, une opération est peut-être en cours") <<<<<<< HEAD zenity --width=500 --error --text="$infoerr" ======= zenity $W --error --text="$infoerr" >>>>>>> dev exit fi } bobainfoa () { TestBorgRepo borg info ./::$borg_repo } DossierPresent () { if [ ! -d "$1" ]; then <<<<<<< HEAD inforerror=$(echo "Erreur, le dossier $1 est absent.\nFin du script.") zenity --width=500 --error --text="$inforerror" exit fi } SauvegardeBorg () { DossierPresent $borg_repo DossierPresent $borg_dir zenity --width=500 --height=600 --info --text="$(cd $dossierprofil && cat $fichierprofil)" borg create $borg_excludes $borg_compress $borg_repo::$borg_archive $borg_dir | zenity --width=400 --progress --pulsate --auto-close --title="Sauvegarde en cours..." sync | zenity --width=400 --progress --pulsate --auto-close --title="Synchronisation des écritures..." zenity --notification --text "Sauvegarde $nomsauvegarde terminée" zenity --width=300 --info --text "Sauvegarde $nomsauvegarde terminée" } # Profils et tests ################################################################################# ======= inforerror=$(echo "Erreur, le dossier $1 est absent.") zenity $W --error --text="$inforerror" VarDossierPresent="false" fi } ZenityPulsate () { zenity $W $iconborg --progress --pulsate --auto-close } BorgFilter () { if [ "$filter" = "" ];then Borg_Archive=$(borg list --short $borg_repo | zenity $H $iconborg --list --title "Listes des archives" --column "Archive") else Borg_Archive=$(borg list --short $borg_repo| grep $filter | zenity $H $iconborg --list --title "Listes des archives" --column "Archive") fi } ################################################################################# # Profils et tests ################################################################################# >>>>>>> dev # si $1 n'est pas vide fichier de profil = $1 # sinon afficher les profils disponibles if [ ! $1 = "" ]; then fichierprofil="$1" . "$1" else <<<<<<< HEAD fichierprofil=$(ls -1 $HOME/.config/borg/*.txt | zenity --height=500 --width=600 --list --title "Profils" --column "profil") && . $fichierprofil fi if [ "$nomsauvegarde" = "" ]; then infoerr=$(echo "Nom de sauvegarde non défini.") zenity --width=200 --error --text="$infoerr" exit elif [ "$borg_repo" = "" ]; then infoerr=$(echo "Variable \$borg_repo absente") zenity --width=200 --error --text="$infoerr" ======= cd $dossierprofil fichierprofil=$(ls -1 *.conf | cut -d. -f1 | \ zenity $W $H $iconborg --list \ --title "Liste des profils" \ --text "Choisir un profil dans la liste" \ --column "Fichier de profil"\ ) && . "$dossierprofil"/"$fichierprofil".conf fi if [ "$fichierprofil" = "" ]; then infoerr=$(echo "Aucun profil choisi.") zenity $W --error --text="$infoerr" exit elif [ "$nomsauvegarde" = "" ]; then infoerr=$(echo "Nom de sauvegarde non défini.") zenity $W --error --text="$infoerr" exit elif [ "$borg_repo" = "" ]; then infoerr=$(echo "Variable \$borg_repo absente") zenity $W --error --text="$infoerr" >>>>>>> dev exit fi cd $borg_repo TestBorgRepo <<<<<<< HEAD ################################################################################# # MENU PRINCIPAL ################################################################################# ################################################################################# # Gestion des options du menu ################################################################################# while [ ! "$choixmenu" = "QUITTER" ] do choixmenu=$(echo -e "\ creer_sauvegarde\n\ monter_sauvegarde\n\ demonter_sauvegarde\n\ supprimmer_sauvegarde\n\ info_sauvegarde\n\ info_depot\n\ afficher_variables_profil\n\ QUITTER\ " | zenity --list --height=400 --width=400 --title "BORG GUI" --column "Nom : $nomsauvegarde") if [ "$choixmenu" = "creer_sauvegarde" ] ;then TestBorgRepo SauvegardeBorg elif [ "$choixmenu" = "monter_sauvegarde" ];then borg_archive=$(borg list --short $borg_repo | zenity --height=500 --list --title "Listes des archives" --column "Archive") mkdir $HOME/$borg_archive borg mount $borg_repo::$borg_archive $HOME/$borg_archive zenity --width=400 --info --text="La sauvegarde est disponible dans le dossier\n$HOME/$borg_archive" elif [ "$choixmenu" = "demonter_sauvegarde" ];then ptnmontage=$(mount | grep borgfs | cut -d" " -f3 | zenity --width=500 --height=400 --list --title "Liste des points de montages" --column "") fusermount -u $ptnmontage sleep 5 rmdir $ptnmontage elif [ "$choixmenu" = "supprimmer_sauvegarde" ];then borg_archive=$(borg list --short $borg_repo | zenity --height=500 --list --title "Listes des archives" --column "Archive") borg delete $borg_repo::$borg_archive | zenity --width=400 --progress --pulsate --auto-close --title="Suppression en cours..." zenity --width=200 --info --text="Suppresion terminée" elif [ "$choixmenu" = "info_sauvegarde" ];then borg_archive=$(borg list --short $borg_repo | zenity --height=500 --list --title "Listes des archives" --column "Archive") info=$(borg info $borg_repo::$borg_archive) zenity --width=600 --info --text="$info" elif [ "$choixmenu" = "info_depot" ];then info=$(borg info $borg_repo) zenity --width=600 --info --text="$info" elif [ "$choixmenu" = "afficher_variables_profil" ];then info=$(cd $dossierprofil && cat $fichierprofil) zenity --width=500 --height=600 --info --text="$info" elif [ "$choixmenu" = "" ];then zenity --width=500 --info --text="Aucun choix, retour au menu." fi ======= ################################################################################# # Fichier de configuration globale ################################################################################# if [ -f $HOME/.config/borg/borg-zenity.conf ];then . $HOME/.config/borg/borg-zenity.conf fi ################################################################################# # MENU PRINCIPAL Gestion des options du menu ################################################################################# while [ ! "$quitter" = "yes" ];do # si aucune archive n'est montée, cacher l'entrée de menu «Démonter une archive» if [ "$(mount | grep borgfs)" != "" ];then MenuDemonter="dm\nDemonter une archive\ndmt\nDémonter toutes les archives\n" else MenuDemonter="" fi # afficher l'espace disque sous condition, la variable vient du fichier borg-zenity.conf EspaceDisqueUtil=$(df -k --output=pcent $borg_repo | tail -n +2 | cut -d% -f1) if [ $EspaceDisqueUtil -gt $seuil_alerte_espace_disque ];then MenuEspaceDisque="ed\n/!\ Espace disque utilisé : $EspaceDisqueUtil %\n" else MenuEspaceDisque="" fi ################################################################################# # Affichage du menu ################################################################################# if [ $menu_avance = "true" ];then choixmenu=$(echo -e "\ cs\nCréer l'archive : $(echo $borg_archive)\n\ ms\nMonter une archive\n\ $(echo $MenuDemonter)\ ss\nSupprimmer une archive\n\ sss\nSupprimmer des archives\n\ is\nInformation archive\n\ fi\nFiltre : "$filter"\n\ --\n------------------------------------------\n\ id\nInformation sur le dépôt\n\ ap\nAfficher le profil\n\ --\n------------------------------------------\n\ $(echo $MenuEspaceDisque)\ qu\nQUITTER\ " | zenity $iconborg --list $H $W --title "BORG GUI : $nomsauvegarde" \ --hide-header --hide-column=1 --column "id" --column "choix") else choixmenu=$(echo -e "\ cs\nCréer l'archive : $(echo $borg_archive)\n\ ms\nMonter une archive\n\ $(echo $MenuDemonter)\ ss\nSupprimmer une archive\n\ is\nInformation archive\n\ $(echo $MenuEspaceDisque)\ qu\nQUITTER\ " | zenity $iconborg --list $H $W --title "BORG GUI : $nomsauvegarde" \ --hide-header --hide-column=1 --column "id" --column "choix") fi ################################################################################# # Gestion des choix du menu ################################################################################# if [ "$choixmenu" = "" ];then echo "" elif [ "$choixmenu" = "cs" ];then # Créer une archive TestBorgRepo DossierPresent $borg_repo DossierPresent $borg_dir borg list --short $borg_repo | grep $borg_archive if [ "$?" = "0" ];then zenity --warning $W $iconborg --text "L'archive existe déjà." else if [ "$VarDossierPresent" != "false" ];then borg create $borg_excludes $borg_compress $borg_repo::$borg_archive $borg_dir | ZenityPulsate sync | ZenityPulsate zenity --notification --text "Sauvegarde $nomsauvegarde terminée" zenity $W --info --text "Sauvegarde $nomsauvegarde terminée" fi fi elif [ "$choixmenu" = "ms" ];then # Monter une archive BorgFilter if [ ! "$Borg_Archive" = "" ];then mkdir $HOME/$Borg_Archive borg mount $borg_repo::$Borg_Archive $HOME/$Borg_Archive | ZenityPulsate zenity $W --info --text="La sauvegarde est disponible dans le dossier\n$HOME/$Borg_Archive" fi elif [ "$choixmenu" = "dm" ];then # Demonter une archive ptnmontage=$(mount | grep borgfs | cut -d" " -f3 | zenity $W $H $iconborg --list --title "Liste des points de montages" --column "Archive") if [ ! "$ptnmontage" = "" ];then fusermount -u $ptnmontage | ZenityPulsate sleep 2 | ZenityPulsate rmdir $ptnmontage | ZenityPulsate fi elif [ "$choixmenu" = "dmt" ];then # Demonter toutes les archives while [ $(mount | grep borgfs | cut -d" " -f3 | head -n 1) ];do ptnmontage="$(mount | grep borgfs | cut -d" " -f3 | head -n 1)" notify-send -i $HOME/.icons/borg.svg "borg-zenity" "Démontage de $ptnmontage" fusermount -uz $ptnmontage && sleep 2 && rmdir $ptnmontage done elif [ "$choixmenu" = "ss" ];then # Supprimmer une archive BorgFilter if [ "$Borg_Archive" = "" ];then zenity $W --info --text "Aucune archive choisie, retour au menu" else borg delete $borg_repo::$Borg_Archive | ZenityPulsate zenity $W --info --text="Suppresion de l'archive $Borg_Archive terminée" fi elif [ "$choixmenu" = "sss" ];then # Supprimmer des archives if [ "$filter" = "" ];then Borg_Archive=$(borg list --short $borg_repo | sed s/^/\\n/g | zenity $H $iconborg --list --checklist --title "Listes des archives" --column "Sel" --column "Archive") else Borg_Archive=$(borg list --short $borg_repo | grep $filter | sed s/^/S\\n/g | zenity $H $iconborg --list --checklist --title "Listes des archives" --column "S" --column "Archive") fi if [ "$Borg_Archive" = "" ];then zenity $W --info --text "Aucune archive choisie, retour au menu" else borg delete $borg_repo::$(echo "$Borg_Archive" | sed s/\|/\ /g) | ZenityPulsate zenity $W --info --text="Suppression des archives terminée.\nArchives supprimmées : $(echo "$Borg_Archive" | sed s/\|/\ /g)" fi elif [ "$choixmenu" = "is" ];then # Information archive BorgFilter if [ "$Borg_Archive" = "" ];then zenity $W --info --text "Aucune archive choisie, retour au menu" else zenity $W --info --text="$(borg info $borg_repo::$Borg_Archive)" | ZenityPulsate fi elif [ "$choixmenu" = "fi" ];then #Filtre filter=$(zenity --entry) elif [ "$choixmenu" = "id" ];then # Information sur le dépôt zenity $W --info --text="$(borg info $borg_repo)" | ZenityPulsate elif [ "$choixmenu" = "ap" ];then # Afficher le profil zenity $W $H --info --text="$(cd $dossierprofil && cat "$fichierprofil".conf)" elif [ "$choixmenu" = "qu" ];then if [ "$(mount | grep borgfs)" = "" ];then quitter="yes" else zenity $W --warning --text="Une ou des archives sont montées.\nDémontez-le afin de laisser le dépôt dans un état cohérent." fi fi >>>>>>> dev done