borg-zenity/borg-gui.sh

232 lines
6.5 KiB
Bash
Raw Normal View History

2021-03-07 14:52:30 +01:00
#! /bin/bash
# tests de base
which zenity
if [ "$?" != "0" ]; then
echo "Zenity n'est pas installé.";exit
exit
fi
which borg
if [ "$?" != "0" ]; then
echo "borgbackup n'est pas installé.";exit
exit
fi
2021-03-07 14:52:30 +01:00
# META VARIABLES
#################################################################################
export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
2021-03-10 18:54:06 +01:00
dossierprofil="$HOME/.config/borg/"
W="--width=600"
H="--height=500"
iconborg="--window-icon=$HOME/.icons/borg.svg"
2021-03-07 14:52:30 +01:00
# FONCTIONS
#################################################################################
TestBorgRepo () {
if [ ! -f "config" ]; then
TestBorgErr=1
infoerr=$(echo "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.")
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")
zenity $W --error --text="$infoerr"
exit
fi
2021-03-07 14:52:30 +01:00
}
bobainfoa () {
TestBorgRepo
borg info ./::$borg_repo
2021-03-07 14:52:30 +01:00
}
DossierPresent () {
if [ ! -d "$1" ]; then
inforerror=$(echo "Erreur, le dossier $1 est absent.")
zenity $W --error --text="$inforerror"
VarDossierPresent="false"
fi
2021-03-07 14:52:30 +01:00
}
ZenityPulsate () {
zenity $W $iconborg --progress --pulsate --auto-close
}
2021-08-04 20:32:21 +02:00
BorgFilter () {
if [ "$filter" = "" ];then
Borg_Archive=$(borg list --short $borg_repo | zenity $H $iconborg --list --title "Listes des archives" --column "Archive")
2021-08-04 20:32:21 +02:00
else
Borg_Archive=$(borg list --short $borg_repo| grep $filter | zenity $H $iconborg --list --title "Listes des archives" --column "Archive")
2021-08-04 20:32:21 +02:00
fi
}
2021-03-07 14:52:30 +01:00
# Profils et tests
#################################################################################
# si $1 n'est pas vide fichier de profil = $1
# sinon afficher les profils disponibles
if [ ! $1 = "" ]; then
fichierprofil="$1"
. "$1"
else
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
2021-03-07 14:52:30 +01:00
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"
2021-03-07 14:52:30 +01:00
exit
elif [ "$borg_repo" = "" ]; then
infoerr=$(echo "Variable \$borg_repo absente")
zenity $W --error --text="$infoerr"
2021-03-07 14:52:30 +01:00
exit
fi
cd $borg_repo
TestBorgRepo
#################################################################################
# MENU PRINCIPAL Gestion des options du menu
2021-03-07 14:52:30 +01:00
#################################################################################
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
2021-03-07 14:52:30 +01:00
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\
2021-07-04 20:00:29 +02:00
fi\nFiltre : "$filter"\n\
--\n------------------------------------------\n\
id\nInformation sur le dépôt\n\
ap\nAfficher le profil\n\
--\n------------------------------------------\n\
ed\nEspace disque utilisé : $(df -k --output=pcent $borg_repo | tail -n +2)\n\
qu\nQUITTER\
" | zenity $iconborg --list $H $W --title "BORG GUI : $nomsauvegarde" \
--hide-header --hide-column=1 --column "id" --column "choix")
if [ "$choixmenu" = "" ];then
echo ""
2021-07-21 17:45:46 +02:00
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
2021-03-07 14:52:30 +01:00
elif [ "$choixmenu" = "ms" ];then
# Monter une archive
2021-08-04 20:32:21 +02:00
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<tt>$HOME/$Borg_Archive</tt>"
fi
2021-07-04 21:54:04 +02:00
elif [ "$choixmenu" = "dm" ];then
2021-08-04 20:32:21 +02:00
# 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
2021-03-07 14:52:30 +01:00
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
2021-08-04 20:32:21 +02:00
# 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
2021-03-07 14:52:30 +01:00
elif [ "$choixmenu" = "is" ];then
2021-08-04 20:32:21 +02:00
# Information archive
BorgFilter
if [ "$Borg_Archive" = "" ];then
2021-08-04 20:32:21 +02:00
zenity $W --info --text "Aucune archive choisie, retour au menu"
else
zenity $W --info --text="<tt>$(borg info $borg_repo::$Borg_Archive)</tt>" | ZenityPulsate
fi
elif [ "$choixmenu" = "fi" ];then
2021-08-04 20:32:21 +02:00
#Filtre
filter=$(zenity --entry)
2021-03-07 14:52:30 +01:00
elif [ "$choixmenu" = "id" ];then
2021-08-04 20:32:21 +02:00
# Information sur le dépôt
zenity $W --info --text="<tt>$(borg info $borg_repo)</tt>" | ZenityPulsate
2021-03-07 14:52:30 +01:00
elif [ "$choixmenu" = "ap" ];then
2021-08-04 20:32:21 +02:00
# Afficher le profil
zenity $W $H --info --text="<tt>$(cd $dossierprofil && cat "$fichierprofil".conf)</tt>"
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
done