borg-zenity/borg-gui.sh

304 lines
9.2 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
dossierprofil="$HOME/.config/borg/profils-borg-zenity/"
W="--width=600"
H="--height=500"
2022-04-18 17:40:13 +02:00
iconborg="--window-icon=/usr/share/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
#################################################################################
2021-03-07 14:52:30 +01:00
# si $1 n'est pas vide fichier de profil = $1
# sinon afficher les profils disponibles
if [ ! $1 = "" ]; then
fichierprofil="$1"
. "$1"
else
2022-04-29 19:45:49 +02:00
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
#################################################################################
# Fichier de configuration globale
#################################################################################
if [ -f $HOME/.config/borg/borg-zenity.conf ];then
. $HOME/.config/borg/borg-zenity.conf
fi
2021-03-07 14:52:30 +01:00
#################################################################################
# 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
2022-05-29 15:42:11 +02:00
MenuDemonter="dm\n🗀 Démonter une archive\ndmt\n🗀🗀 Dé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
2022-05-29 15:42:11 +02:00
MenuEspaceDisque="ed\n⚠ Espace disque utilisé : $EspaceDisqueUtil %\n"
else
MenuEspaceDisque=""
fi
#################################################################################
# Affichage du menu
#################################################################################
if [ $menu_avance = "true" ];then
2021-03-07 14:52:30 +01:00
choixmenu=$(echo -e "\
2022-05-29 15:42:11 +02:00
cs\n🖫 Créer l'archive : $(echo $borg_archive)\n\
ms\n🗁 Monter une archive\n\
$(echo $MenuDemonter)\
2022-05-29 15:42:11 +02:00
ss\n❌ Supprimer une archive\n\
sss\n❌❌ Supprimer des archives\n\
ra\n🖹 Renommer une archive\n\
is\n❔ Information archive\n\
fi\n☑ Filtre : "$filter"\n\
2021-07-04 20:00:29 +02:00
--\n------------------------------------------\n\
2022-05-29 15:42:11 +02:00
id\n❔ Information sur le dépôt\n\
ap\n❔ Afficher le profil\n\
--\n------------------------------------------\n\
$(echo $MenuEspaceDisque)\
2022-05-29 15:42:11 +02:00
qu\n⏻ QUITTER\
" | zenity $iconborg --list $H $W --title "BORG GUI : $nomsauvegarde" \
--hide-header --hide-column=1 --column "id" --column "choix")
else
choixmenu=$(echo -e "\
2022-05-29 15:42:11 +02:00
cs\n🖫 Créer l'archive : $(echo $borg_archive)\n\
ms\n🗁 Monter une archive\n\
$(echo $MenuDemonter)\
2022-05-29 15:42:11 +02:00
ss\n❌ Supprimer une archive\n\
is\n❔ Information archive\n\
$(echo $MenuEspaceDisque)\
2022-05-29 15:42:11 +02:00
qu\n⏻ QUITTER\
" | 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 ""
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
cd $borg_dir && borg create $borg_excludes $borg_compress $borg_repo::$borg_archive ./ | 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
2022-04-15 11:34:24 +02:00
# Démonter 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
2022-04-15 11:34:24 +02:00
# Démonter toutes les archives
while [ $(mount | grep borgfs | cut -d" " -f3 | head -n 1) ];do
ptnmontage="$(mount | grep borgfs | cut -d" " -f3 | head -n 1)"
2022-04-18 17:40:13 +02:00
notify-send -i $iconborg "borg-zenity" "Démontage de $ptnmontage"
fusermount -uz $ptnmontage && sleep 2 && rmdir $ptnmontage
done
elif [ "$choixmenu" = "ss" ];then
2022-04-15 11:34:24 +02:00
# Supprimer une archive
2021-08-04 20:32:21 +02:00
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
2022-04-15 11:34:24 +02:00
# Supprimer 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
2022-04-15 11:34:24 +02:00
zenity $W --info --text="Suppression des archives terminée.\nArchives supprimées : $(echo "$Borg_Archive" | sed s/\|/\ /g)"
fi
elif [ "$choixmenu" = "ra" ];then
# renommer une archive
BorgFilter
if [ "$Borg_Archive" = "" ];then
zenity $W --info --text "Aucune archive choisie, retour au menu"
else
borg_nouveaunom=$(zenity --entry --text "Nouveau nom" --entry-text="$Borg_Archive")
borg rename $borg_repo::"$Borg_Archive" "$borg_nouveaunom" | ZenityPulsate
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
2022-04-29 19:45:49 +02:00
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