diff --git a/borg-gui.sh b/borg-gui.sh index 64de26e..4cd7fab 100755 --- a/borg-gui.sh +++ b/borg-gui.sh @@ -1,14 +1,12 @@ #! /bin/bash # tests de base -which zenity -if [ "$?" != "0" ]; then +if ! which zenity ; then echo "Zenity n'est pas installé.";exit exit fi -which borg -if [ "$?" != "0" ]; then +if ! which borg ; then echo "borgbackup n'est pas installé.";exit exit fi @@ -26,22 +24,19 @@ iconborg="--window-icon=/usr/share/icons/borg.svg" ################################################################################# TestBorgRepo () { if [ ! -f "config" ]; then - TestBorgErr=1 - infoerr=$(echo "Impossible de trouver le fichier de configuration borg.") + infoerr="Impossible de trouver le fichier de configuration borg." zenity $W --error --text="$infoerr" exit fi if [ ! -d "data" ]; then - TestBorgErr=1 - infoerr=$(echo "Impossible de trouver le fichier de configuration borg.") + infoerr="Impossible de trouver le fichier de configuration borg." zenity $W --error --text="$infoerr" 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") + infoerr="Le dépôt est verrouillé, une opération est peut-être en cours" zenity $W --error --text="$infoerr" exit fi @@ -54,7 +49,7 @@ bobainfoa () { DossierPresent () { if [ ! -d "$1" ]; then - inforerror=$(echo "Erreur, le dossier $1 est absent.") + inforerror="Erreur, le dossier $1 est absent." zenity $W --error --text="$inforerror" VarDossierPresent="false" fi @@ -76,7 +71,7 @@ BorgFilter () { # Profils et tests ################################################################################# -cd "$dossierprofil" +cd "$dossierprofil" || exit fichierprofil=$(ls -1 *.conf | cut -d. -f1 | \ zenity $W $H $iconborg --list \ --title "Liste des profils" \ @@ -85,21 +80,26 @@ zenity $W $H $iconborg --list \ ) && . "$dossierprofil"/"$fichierprofil".conf if [ "$fichierprofil" = "" ]; then - infoerr=$(echo "Aucun profil choisi.") + infoerr="Aucun profil choisi." zenity $W --error --text="$infoerr" exit elif [ "$nomsauvegarde" = "" ]; then - infoerr=$(echo "Nom de sauvegarde non défini.") + infoerr="Nom de sauvegarde non défini." zenity $W --error --text="$infoerr" exit elif [ "$borg_repo" = "" ]; then - infoerr=$(echo "Variable \$borg_repo absente") + infoerr="Variable \$borg_repo absente" zenity $W --error --text="$infoerr" exit fi -cd "$borg_repo" -TestBorgRepo + +if ! cd "$borg_repo" ;then + zenity $W --error --text="Impossible de trouver de dépôt borg." + exit +else + TestBorgRepo +fi ################################################################################# @@ -116,6 +116,7 @@ fi ################################################################################# while [ "$quitter" != "yes" ];do +cd "$borg_repo" || exit # si des archives sont montées afficher les entrées de menu «démonter» # si des archives sont montés, cacher les entrées «supprimer et renommer» @@ -130,7 +131,7 @@ MenuDemonter="" MenuSupprimer="ss\nSupprimer une archive\nsss\nSupprimer des archives\n" MenuRenommer="ra\nRenommer une archive\n" MenuInfo="is\nInformation archive\n" -MenuCreer="cs\nCréer l'archive : $(echo $borg_archive)\n" +MenuCreer="cs\nCréer l'archive : $borg_archive\n" fi # afficher l'espace disque sous condition, la variable vient du fichier borg-zenity.conf @@ -190,18 +191,16 @@ fi TestBorgRepo DossierPresent "$borg_repo" - DossierPresent "$borg_dir" + DossierPresent "$borg_dir" && cd "$borg_dir" - borg list --short "$borg_repo" | grep $borg_archive - if [ "$?" = "0" ];then + if borg list --short "$borg_repo" | grep $borg_archive ;then zenity --warning $W $iconborg --text "L'archive existe déjà." else if [ "$VarDossierPresent" != "false" ];then - cd "$borg_dir" - log="$HOME/borg-zenity-$borg_archive.log" - borg create $borg_excludes $borg_compress "$borg_repo"::"$borg_archive" ./ 2>> "$log" | ZenityPulsate + log="/tmp/borg-zenity-$borg_archive.log" + borg create $borg_excludes $borg_compress "$borg_repo"::"$borg_archive" ./ 2> "$log" | ZenityPulsate chmod 777 "$log" - if ls "$log" ;then + if [ $(wc -c "$log" | cut -f1 -d " ") -gt 1 ] ;then zenity $W --error --title "borg-zenity erreur" --text "$(cat $log)" else sync | ZenityPulsate