Merge branch 'dev' into stable

This commit is contained in:
Djan GICQUEL 2023-04-09 17:12:59 +02:00
commit 462e99362e
7 changed files with 285 additions and 250 deletions

View File

@ -1,14 +1,12 @@
#! /bin/bash #! /bin/bash
# tests de base # tests de base
which zenity if ! which zenity ; then
if [ "$?" != "0" ]; then
echo "Zenity n'est pas installé.";exit echo "Zenity n'est pas installé.";exit
exit exit
fi fi
which borg if ! which borg ; then
if [ "$?" != "0" ]; then
echo "borgbackup n'est pas installé.";exit echo "borgbackup n'est pas installé.";exit
exit exit
fi fi
@ -25,50 +23,68 @@ iconborg="--window-icon=/usr/share/icons/borg.svg"
# FONCTIONS # FONCTIONS
################################################################################# #################################################################################
TestBorgRepo () { TestBorgRepo () {
if [ ! -f "config" ]; then if [ ! -d "$borg_repo" ];then
TestBorgErr=1 zenity $W --error --text="Impossible de trouver de dépôt borg."
infoerr=$(echo "Impossible de trouver le fichier de configuration borg.")
zenity $W --error --text="$infoerr"
exit exit
else
echo "[OK] Le dépôt borg existe"
fi fi
if [ ! -d "data" ]; then if ! ls "$borg_repo";then
TestBorgErr=1 zenity $W --error --text="Impossible d'accéder au dépôt borg.\nIl s'agit probablement d'un problème de droits"
infoerr=$(echo "Impossible de trouver le fichier de configuration borg.")
zenity $W --error --text="$infoerr"
exit exit
else
echo "[OK] L'accès au dépôt borg est possible"
fi fi
if [ -d "lock.exclusive" ]; then if ! ls "$borg_repo/data";then
TestBorgErr=1 zenity $W --error --text="Impossible d'accéder aux données du dépôt borg.\nIl s'agit probablement d'un problème de droits"
infoerr=$(echo "Le dépôt est bloqué, une opération est peut-être en cours") exit
else
echo "[OK] L'accès aux données du dépôt borg est possible"
fi
if [ ! -f "$borg_repo/config" ]; then
infoerr="Impossible de trouver le fichier de configuration borg."
zenity $W --error --text="$infoerr" zenity $W --error --text="$infoerr"
exit exit
else
echo "[OK] Le fichier de configuration a été trouvé"
fi fi
}
bobainfoa () { if [ -d "$borg_repo/lock.exclusive" ]; then
TestBorgRepo infoerr="Le dépôt est verrouillé, une opération est peut-être en cours"
borg info ./::$borg_repo zenity $W --error --text="$infoerr"
exit
else
echo "[OK] Le dépôt n'est pas verrouillé"
fi
} }
DossierPresent () { DossierPresent () {
if [ ! -d "$1" ]; then if [ ! -d "$1" ]; then
inforerror=$(echo "Erreur, le dossier $1 est absent.") inforerror="Erreur, le dossier $1 est absent."
zenity $W --error --text="$inforerror" zenity $W --error --text="$inforerror"
VarDossierPresent="false" VarDossierPresent="false"
fi fi
} }
ZenityPulsate () { ZenityPulsate () {
zenity $W $iconborg --progress --pulsate --auto-close zenity $W $iconborg --title "borg-zenity" --progress --pulsate --auto-close --text "$1"
}
ZenityNotification () {
zenity $iconborg --notification --text "$1"
} }
BorgFilter () { BorgFilter () {
if [ "$filter" = "" ];then if [ "$filter" = "" ];then
Borg_Archive=$(borg list --short $borg_repo | zenity $H $iconborg --list --title "Listes des archives" --column "Archive") ZenityNotification "borg-zenity\nGénération de la liste des archives en cours..."
BorgArchiveList=$(borg list --short "$borg_repo")
Borg_Archive=$(echo -e "$BorgArchiveList" | zenity $H $W $iconborg --list --title "Listes des archives" --column "Archive")
else else
Borg_Archive=$(borg list --short $borg_repo| grep $filter | zenity $H $iconborg --list --title "Listes des archives" --column "Archive") BorgArchiveList=$(borg list --short "$borg_repo")
Borg_Archive=$(echo -e "$BorgArchiveList" | grep "$filter" | zenity $H $W $iconborg --list --title "Listes des archives" --column "Archive")
fi fi
} }
@ -76,39 +92,31 @@ BorgFilter () {
# Profils et tests # Profils et tests
################################################################################# #################################################################################
# si $1 n'est pas vide fichier de profil = $1 cd "$dossierprofil" || exit
# sinon afficher les profils disponibles fichierprofil=$(ls -1 *.conf | cut -d. -f1 | \
if [ ! $1 = "" ]; then zenity $W $H $iconborg --list \
fichierprofil="$1" --title "Liste des profils" \
. "$1" --text "Choisir un profil dans la liste" \
else --column "Fichier de profil" \
cd "$dossierprofil" --hide-header \
fichierprofil=$(ls -1 *.conf | cut -d. -f1 | \ ) && . "$dossierprofil"/"$fichierprofil".conf
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 if [ "$fichierprofil" = "" ]; then
infoerr=$(echo "Aucun profil choisi.") infoerr="Aucun profil choisi."
zenity $W --error --text="$infoerr" zenity $W --error --text="$infoerr"
exit exit
elif [ "$nomsauvegarde" = "" ]; then elif [ "$nomsauvegarde" = "" ]; then
infoerr=$(echo "Nom de sauvegarde non défini.") infoerr="Nom de sauvegarde non défini."
zenity $W --error --text="$infoerr" zenity $W --error --text="$infoerr"
exit exit
elif [ "$borg_repo" = "" ]; then elif [ "$borg_repo" = "" ]; then
infoerr=$(echo "Variable \$borg_repo absente") infoerr="Variable \$borg_repo absente"
zenity $W --error --text="$infoerr" zenity $W --error --text="$infoerr"
exit exit
fi fi
cd $borg_repo
TestBorgRepo TestBorgRepo
################################################################################# #################################################################################
# Fichier de configuration globale # Fichier de configuration globale
################################################################################# #################################################################################
@ -122,57 +130,88 @@ fi
# MENU PRINCIPAL Gestion des options du menu # MENU PRINCIPAL Gestion des options du menu
################################################################################# #################################################################################
while [ ! "$quitter" = "yes" ];do while [ "$quitter" != "yes" ];do
cd "$borg_repo" || exit
# si aucune archive n'est montée, cacher l'entrée de menu «Démonter une archive» # 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»
if [ "$(mount | grep borgfs)" != "" ];then if [ "$(mount | grep borgfs)" != "" ];then
MenuDemonter="dm\nDémonter une archive\ndmt\nDémonter toutes les archives\n" MenuDemonter="dm\nDémonter une archive\ndmt\nDémonter toutes les archives\n"
MenuSupprimer=""
MenuRenommer=""
MenuInfo=""
MenuCreer=""
else else
MenuDemonter="" MenuDemonter=""
MenuSupprimer1="ss\nSupprimer une archive\n"
MenuSupprimerX="sss\nSupprimer des archives\n"
MenuRenommer="ra\nRenommer une archive\n"
MenuInfo="is\nInformation archive\n"
MenuCreer="cs\nCréer l'archive : $borg_archive\n"
fi fi
# afficher l'espace disque sous condition, la variable vient du fichier borg-zenity.conf # 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) EspaceDisqueUtil=$(df -k --output=pcent "$borg_repo" | tail -n +2 | cut -d% -f1)
if [ $EspaceDisqueUtil -gt $seuil_alerte_espace_disque ];then if [ $EspaceDisqueUtil -gt $seuil_alerte_espace_disque ];then
MenuEspaceDisque="ed\n/!\ Espace disque utilisé : $EspaceDisqueUtil %\n" MenuEspaceDisque="ed\n/!\ Espace disque utilisé : $EspaceDisqueUtil %\n"
else else
MenuEspaceDisque="" MenuEspaceDisque=""
fi fi
# notification si espace disque faible
NotificationEspaceDisque () {
if [ $EspaceDisqueUtil -gt $seuil_alerte_espace_disque ];then
ZenityNotification "borg-zenity\nEspace disque faible, $EspaceDisqueUtil% occupé"
fi
}
MenuCompacter="co\nCompacter le dépôt\n"
MenuMonter="ms\nMonter une archive\n"
MenuFiltre="fi\nFiltre : "$filter"\n"
MenuBarreHorizontale="--\n------------------------------------------\n"
MenuInfoDepot="id\nInformation sur le dépôt\n"
MenuAfficherProfil="ap\nAfficher le profil\n"
MenuQuitter="qu\nQUITTER"
################################################################################# #################################################################################
# Affichage du menu # Affichage du menu
################################################################################# #################################################################################
if [ $menu_avance = "true" ];then if [ $menu_avance = "true" ];then
NotificationEspaceDisque
# menu avancé
choixmenu=$(echo -e "\ choixmenu=$(echo -e "\
cs\nCréer l'archive : $(echo $borg_archive)\n\ $(echo $MenuCreer)\
ms\nMonter une archive\n\ $(echo $MenuMonter)\
$(echo $MenuDemonter)\ $(echo $MenuDemonter)\
ss\nSupprimer une archive\n\ $(echo $MenuSupprimer1)\
sss\nSupprimer des archives\n\ $(echo $MenuSupprimerX)\
ra\nRenommer une archive\n\ $(echo $MenuRenommer)\
is\nInformation archive\n\ $(echo $MenuCompacter)\
fi\nFiltre : "$filter"\n\ $(echo $MenuInfo)\
--\n------------------------------------------\n\ $(echo $MenuFiltre)\
id\nInformation sur le dépôt\n\ $(echo $MenuBarreHorizontale)\
ap\nAfficher le profil\n\ $(echo $MenuInfoDepot)\
--\n------------------------------------------\n\ $(echo $MenuAfficherProfil)\
$(echo $MenuBarreHorizontale)\
$(echo $MenuEspaceDisque)\ $(echo $MenuEspaceDisque)\
qu\nQUITTER\ $(echo $MenuQuitter)\
" | zenity $iconborg --list $H $W --title "BORG GUI : $nomsauvegarde" \ " | zenity $iconborg --list $H $W --title "$nomsauvegarde" --hide-header --hide-column=1 --column "id" --column "choix")
--hide-header --hide-column=1 --column "id" --column "choix")
else else
NotificationEspaceDisque
# menu simple
choixmenu=$(echo -e "\ choixmenu=$(echo -e "\
cs\nCréer l'archive : $(echo $borg_archive)\n\ $(echo $MenuCreer)\
ms\nMonter une archive\n\ $(echo $MenuMonter)\
$(echo $MenuDemonter)\ $(echo $MenuDemonter)\
ss\nSupprimer une archive\n\ $(echo $MenuSupprimer1)\
is\nInformation archive\n\
$(echo $MenuEspaceDisque)\ $(echo $MenuEspaceDisque)\
qu\nQUITTER\ $(echo $MenuQuitter)\
" | zenity $iconborg --list $H $W --title "BORG GUI : $nomsauvegarde" \ " | zenity $iconborg --list $H $W --title "BORG GUI : $nomsauvegarde" --hide-header --hide-column=1 --column "id" --column "choix")
--hide-header --hide-column=1 --column "id" --column "choix")
fi fi
@ -188,19 +227,27 @@ fi
# Créer une archive # Créer une archive
TestBorgRepo TestBorgRepo
DossierPresent "$borg_repo"
DossierPresent "$borg_dir"
cd "$borg_dir"
if [ ! "$?" = "0" ] ;then
zenity $W --error --text "Impossible de se rendre dans le dossier de sauvegarde."
exit
fi
DossierPresent $borg_repo if borg list --short "$borg_repo" | grep "$borg_archive" ;then
DossierPresent $borg_dir
borg list --short $borg_repo | grep $borg_archive
if [ "$?" = "0" ];then
zenity --warning $W $iconborg --text "L'archive existe déjà." zenity --warning $W $iconborg --text "L'archive existe déjà."
else else
if [ "$VarDossierPresent" != "false" ];then if [ "$VarDossierPresent" != "false" ];then
cd $borg_dir && borg create $borg_excludes $borg_compress $borg_repo::$borg_archive ./ | ZenityPulsate log="/tmp/borg-zenity-$borg_archive-$(date +%H-%M-%S).log"
sync | ZenityPulsate borg create ${borg_excludes} ${borg_compress} "$borg_repo"::"$borg_archive" . 2> "$log" | zenity $W $iconborg --progress --pulsate --auto-close --no-cancel --text "Sauvegarde en cours..." --title "borg-zenity"
zenity --notification --text "Sauvegarde $nomsauvegarde terminée" chmod 777 "$log"
zenity $W --info --text "Sauvegarde $nomsauvegarde terminée" if [ $(wc -c "$log" | cut -f1 -d " ") -gt 1 ] ;then
zenity $W --error --title "borg-zenity erreur" --text "$(cat $log)"
fi
sync | ZenityPulsate "Synchronisation des écritures..."
ZenityNotification "borg-zenity\nSauvegarde $nomsauvegarde terminée"
zenity $W --info --text "Sauvegarde $nomsauvegarde terminée"
fi fi
fi fi
@ -209,8 +256,8 @@ fi
# Monter une archive # Monter une archive
BorgFilter BorgFilter
if [ ! "$Borg_Archive" = "" ];then if [ ! "$Borg_Archive" = "" ];then
mkdir $HOME/$Borg_Archive mkdir $HOME/"$Borg_Archive"
borg mount $borg_repo::$Borg_Archive $HOME/$Borg_Archive | ZenityPulsate borg mount "$borg_repo"::"$Borg_Archive" $HOME/"$Borg_Archive" | ZenityPulsate "Montage de l'archive..."
zenity $W --info --text="La sauvegarde est disponible dans le dossier\n<tt>$HOME/$Borg_Archive</tt>" zenity $W --info --text="La sauvegarde est disponible dans le dossier\n<tt>$HOME/$Borg_Archive</tt>"
fi fi
@ -218,27 +265,26 @@ fi
# Démonter une archive # Démonter une archive
ptnmontage=$(mount | grep borgfs | cut -d" " -f3 | zenity $W $H $iconborg --list --title "Liste des points de montages" --column "Archive") ptnmontage=$(mount | grep borgfs | cut -d" " -f3 | zenity $W $H $iconborg --list --title "Liste des points de montages" --column "Archive")
if [ ! "$ptnmontage" = "" ];then if [ ! "$ptnmontage" = "" ];then
fusermount -u $ptnmontage | ZenityPulsate fusermount -u "$ptnmontage" | ZenityPulsate "Démontage de l'archive..."
sleep 2 | ZenityPulsate sleep 2 | ZenityPulsate ""
rmdir $ptnmontage | ZenityPulsate rmdir "$ptnmontage" | ZenityPulsate "Suppression du point du montage..."
fi fi
ZenityNotification "borg-zenity\nDémontage de $ptnmontage"
elif [ "$choixmenu" = "dmt" ];then elif [ "$choixmenu" = "dmt" ];then
# Démonter toutes les archives # Démonter toutes les archives
while [ $(mount | grep borgfs | cut -d" " -f3 | head -n 1) ];do while [ $(mount | grep borgfs | cut -d" " -f3 | head -n 1) ];do
ptnmontage="$(mount | grep borgfs | cut -d" " -f3 | head -n 1)" ptnmontage="$(mount | grep borgfs | cut -d" " -f3 | head -n 1)"
notify-send -i $iconborg "borg-zenity" "Démontage de $ptnmontage" ZenityNotification "borg-zenity\nDémontage de $ptnmontage"
fusermount -uz $ptnmontage && sleep 2 && rmdir $ptnmontage fusermount -uz "$ptnmontage" && sleep 2 && rmdir "$ptnmontage"
done done
elif [ "$choixmenu" = "ss" ];then elif [ "$choixmenu" = "ss" ];then
# Supprimer une archive # Supprimer une archive
BorgFilter BorgFilter
if [ "$Borg_Archive" = "" ];then if [ ! "$Borg_Archive" = "" ];then
zenity $W --info --text "Aucune archive choisie, retour au menu" borg delete "$borg_repo"::"$Borg_Archive" | ZenityPulsate "Suppresion de l'archive..."
else
borg delete $borg_repo::$Borg_Archive | ZenityPulsate
zenity $W --info --text="Suppresion de l'archive $Borg_Archive terminée" zenity $W --info --text="Suppresion de l'archive $Borg_Archive terminée"
fi fi
@ -246,46 +292,51 @@ fi
# Supprimer des archives # Supprimer des archives
if [ "$filter" = "" ];then 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") Borg_Archive=$(borg list --short "$borg_repo" | sed s/^/\\n/g | zenity $H $W $iconborg --list --checklist --title "Listes des archives" --column "Sel" --column "Archive")
else 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") Borg_Archive=$(borg list --short "$borg_repo" | grep "$filter" | sed s/^/S\\n/g | zenity $H $W $iconborg --list --checklist --title "Listes des archives" --column "S" --column "Archive")
fi fi
if [ "$Borg_Archive" = "" ];then if [ ! "$Borg_Archive" = "" ];then
zenity $W --info --text "Aucune archive choisie, retour au menu" borg delete "$borg_repo"::$(echo "$Borg_Archive" | sed s/\|/\ /g) | ZenityPulsate "Suppression de l'archive..."
else
borg delete $borg_repo::$(echo "$Borg_Archive" | sed s/\|/\ /g) | ZenityPulsate
zenity $W --info --text="Suppression des archives terminée.\nArchives supprimées : $(echo "$Borg_Archive" | sed s/\|/\ /g)" zenity $W --info --text="Suppression des archives terminée.\nArchives supprimées : $(echo "$Borg_Archive" | sed s/\|/\ /g)"
fi fi
elif [ "$choixmenu" = "co" ];then
# Compacter le dépôt
borg compact --verbose "$borg_repo" 2> /tmp/borg-compact.log | ZenityPulsate "Compactage du dépôt..."
zenity $W --info --text "$(cat /tmp/borg-compact.log)"
elif [ "$choixmenu" = "ra" ];then elif [ "$choixmenu" = "ra" ];then
# renommer une archive # renommer une archive
BorgFilter BorgFilter
if [ "$Borg_Archive" = "" ];then if [ ! "$Borg_Archive" = "" ];then
zenity $W --info --text "Aucune archive choisie, retour au menu" borg_nouveaunom=$(zenity $W --entry --text "Nouveau nom" --entry-text="$Borg_Archive")
else if [ "$borg_nouveaunom" = "$Borg_Archive" ];then
borg_nouveaunom=$(zenity --entry --text "Nouveau nom" --entry-text="$Borg_Archive") ZenityNotification "Renommage annulé"
borg rename $borg_repo::"$Borg_Archive" "$borg_nouveaunom" | ZenityPulsate elif [ "$borg_nouveaunom" = "" ];then
ZenityNotification "Renommage annulé"
elif [ "$Borg_Archive" != "$borg_nouveaunom" ];then
borg rename "$borg_repo"::"$Borg_Archive" "$borg_nouveaunom" | ZenityPulsate "Renommage de l'archive..."
ZenityNotification "Renommage terminé\n"$Borg_Archive" -> "$borg_nouveaunom""
fi
fi fi
elif [ "$choixmenu" = "is" ];then elif [ "$choixmenu" = "is" ];then
# Information archive # Information archive
BorgFilter BorgFilter
if [ "$Borg_Archive" = "" ];then if [ ! "$Borg_Archive" = "" ];then
zenity $W --info --text "Aucune archive choisie, retour au menu" zenity $W --info --text="<tt>$(borg info "$borg_repo"::"$Borg_Archive")</tt>" | ZenityPulsate "Récupération des informations..."
else
zenity $W --info --text="<tt>$(borg info $borg_repo::$Borg_Archive)</tt>" | ZenityPulsate
fi fi
elif [ "$choixmenu" = "fi" ];then elif [ "$choixmenu" = "fi" ];then
#Filtre #Filtre
filter=$(zenity --entry) filter=$(zenity $W --entry --entry-text "$filter")
elif [ "$choixmenu" = "id" ];then elif [ "$choixmenu" = "id" ];then
# Information sur le dépôt # Information sur le dépôt
zenity $W --info --text="<tt>$(borg info $borg_repo)</tt>" | ZenityPulsate zenity $W --info --text="<tt>$(borg info "$borg_repo")</tt>" | ZenityPulsate "Récupération des informations..."
elif [ "$choixmenu" = "ap" ];then elif [ "$choixmenu" = "ap" ];then
# Afficher le profil # Afficher le profil
@ -298,6 +349,5 @@ fi
else 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." 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
fi fi
done done

View File

@ -1,16 +1,41 @@
#! /bin/bash #! /bin/bash
. testdistro.sh
# Borg zenity install and update # Borg zenity install and update
which zenity if [[ "$OS" =~ "Fedora" ]];then
if [ "$?" != "0" ]; then echo "Fedora detecté"
bash testdistro.sh || exit sudo dnf install borgbackup zenity
elif [[ "$OS" =~ "Debian" ]];then
echo "Debian detecté"
su -c "apt-get -y install borgbackup zenity"
elif [[ "$OS" =~ "Ubuntu" ]];then
echo "Ubuntu detecté"
sudo apt-get install -y borgbackup zenity
elif [[ "$OS" =~ "Linux Mint" ]];then
echo "Linux Mint detecté"
sudo apt-get install -y borgbackup zenity
elif [[ "$OS" =~ "Manjaro" ]];then
echo "Manjaro detecté"
sudo pacman -Sy borgbackup zenity
fi fi
which borg if [[ "$OS" =~ "Debian" ]];then
if [ "$?" != "0" ]; then su -c "mkdir -vp /opt/borg-zenity"
bash testdistro.sh || exit su -c "cp -fv icons/borg.svg /usr/share/icons/"
fi su -c "cp -fv icons/borgzenity-profils.svg /usr/share/icons/"
su -c "cp -fv icons/borgzenity-sauvegarde.svg /usr/share/icons/"
su -c "cp -fv borg-zenity-sauvegarde.desktop /usr/share/applications/"
su -c "cp -fv borg-zenity-gestprofils.desktop /usr/share/applications/"
su -c "cp -fv borg-gui.sh /opt/borg-zenity/"
su -c "cp -fv profile-manager.sh /opt/borg-zenity/"
su -c "cp -fv uninstall.sh /opt/borg-zenity/"
else
# Copie des fichiers # Copie des fichiers
sudo mkdir -vp /opt/borg-zenity sudo mkdir -vp /opt/borg-zenity
sudo cp -fv icons/borg.svg /usr/share/icons/ sudo cp -fv icons/borg.svg /usr/share/icons/
@ -20,15 +45,26 @@ sudo cp -fv borg-zenity-sauvegarde.desktop /usr/share/applications/
sudo cp -fv borg-zenity-gestprofils.desktop /usr/share/applications/ sudo cp -fv borg-zenity-gestprofils.desktop /usr/share/applications/
sudo cp -fv borg-gui.sh /opt/borg-zenity/ sudo cp -fv borg-gui.sh /opt/borg-zenity/
sudo cp -fv profile-manager.sh /opt/borg-zenity/ sudo cp -fv profile-manager.sh /opt/borg-zenity/
sudo cp -fv uninstall.sh /opt/borg-zenity/
fi
# réglages des droits # réglages des droits
if [[ "$OS" =~ "Debian" ]];then
su -c "chmod a+rx /opt/borg-zenity/borg-gui.sh"
su -c "chmod a+rx /opt/borg-zenity/profile-manager.sh"
else
sudo chmod a+rx /opt/borg-zenity/borg-gui.sh sudo chmod a+rx /opt/borg-zenity/borg-gui.sh
sudo chmod a+rx /opt/borg-zenity/profile-manager.sh sudo chmod a+rx /opt/borg-zenity/profile-manager.sh
fi
# Création du fichier de configuration de base # Création du fichier de configuration de base
mkdir -vp $HOME/.config/borg/ mkdir -vp $HOME/.config/borg/
if [ ! -f $HOME/.config/borg/borg-zenity.conf ];then
cp -fv borg-zenity.conf $HOME/.config/borg/ cp -fv borg-zenity.conf $HOME/.config/borg/
fi
# nettoyage
if [ -f readme.md ];then cd ..;fi if [ -f readme.md ];then cd ..;fi
if [ -f borg-zenity.zip ];then rm -v borg-zenity.zip;fi if [ -f borg-zenity.zip ];then rm -v borg-zenity.zip;fi
if [ -d borg-zenity ];then rm -rv borg-zenity;fi if [ -d borg-zenity ];then rm -rv borg-zenity;fi

View File

@ -1,6 +0,0 @@
nomsauvegarde=""
borg_repo=""
borg_archive="$(date +%d_%B_%Y)"
borg_dir=""
borg_excludes=""
borg_compress="--compress zlib,5"

View File

@ -2,49 +2,41 @@
# Fonctions et variables # Fonctions et variables
########################################################### ###########################################################
W="--width=600"
H="--height=500"
ZenityPulsate () { ZenityPulsate () {
zenity $W --window-icon=$HOME/.icons/borg.svg --progress --pulsate --auto-close zenity $W --window-icon=borg --progress --pulsate --auto-close
} }
TestBorgRepo () { TestBorgRepo () {
if [ ! -f "config" ]; then if [ ! -f "config" ]; then
TestBorgErr=1 zenity $W --error --text="Impossible de trouver le fichier de configuration du dépôt."
infoerr=$(echo "Impossible de trouver le fichier de configuration du dépôt.") TestBorgErr="true"
zenity $W --error --text="$infoerr" else
exit TestBorgErr="false"
fi fi
if [ ! -d "data" ]; then if [ ! -d "data" ]; then
TestBorgErr=1 zenity $W --error --text="Impossible de trouver le dossier des données du dépôt."
infoerr=$(echo "Impossible de trouver le dossier des données du dépôt.") TestBorgErr="true"
zenity $W --error --text="$infoerr" else
exit TestBorgErr="false"
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 fi
} }
W="--width=600"
H="--height=500"
dossierprofil="$HOME/.config/borg/profils-borg-zenity/" dossierprofil="$HOME/.config/borg/profils-borg-zenity/"
mkdir -p $dossierprofil && cd $dossierprofil mkdir -p "$dossierprofil" && cd "$dossierprofil" || exit
# Affichage du menu # Affichage du menu
########################################################### ###########################################################
choixmenu=$(echo -e "\ choixmenu=$(echo -e "\
cp\nCréer un nouveau profil/dépôt\n\ cp\nCréer un nouveau profil/dépôt\n\
ajd\nAjouter un dépôt\n\ ajd\nCréer un nouveau profil et le lier à un dépôt existant\n\
ap\nAfficher les profils\ ap\nAfficher les profils\n\
" | zenity $H $W --window-icon=$HOME/.icons/borg.svg --list \ mp\nModifier un profil (connaissance en ligne de commande borg requise)\
--column "id" --column "choix") " | zenity $H $W --window-icon=borg --list --column "id" --column "choix" --hide-column=1 --hide-header)
# Gestion des choix du menu # Gestion des choix du menu
########################################################### ###########################################################
@ -52,41 +44,40 @@ ap\nAfficher les profils\
### Créer un nouveau profil/dépôt ### ### Créer un nouveau profil/dépôt ###
if [ "$choixmenu" = "cp" ];then if [ "$choixmenu" = "cp" ];then
cd $HOME
borg_repo=$(zenity --file-selection --directory) zenity $W --info --text="Séléctionnez maintenant le dossier qui contiendra votre dépôt, généralement sur un disque dur externe.\nCe dossier doit être vide."
if [ ! -z "$(ls -A $borg_repo)" ]; then borg_repo=$(zenity --title "Dossier du dépôt" --file-selection --directory)
while [ ! -z "$(ls -A "$borg_repo")" ];do
zenity $W --error --text="Erreur, le dossier n'est pas vide." zenity $W --error --text="Erreur, le dossier n'est pas vide."
exit borg_repo=$(zenity --title "Dossier du dépôt" --file-selection --directory)
fi done
zenity $W --question --text "Chiffrer le dépôt ? (recommandé)" zenity $W --question --text "Chiffrer le dépôt ?\n\n\
Si vous chiffrez le dépôt, le fichier-clé du dépôt sera stocké dans le dossier <tt>$HOME/.config/borg/keys/</tt>.\n\
Veuillez à sauvegarder ce dossier dans un endroit sûr.\n\
Si cette clé ne peut être lue les données ne seront pas récupérables. Notez qu'il n'existe aucun mécanisme de récupération de clé.\n\n\
Si vous ne chiffrez pas le dépôt, les données qu'il contient seront librement accessible par toute personne ayant accès aux fichiers du dépôt.
"
if [ "$?" = "0" ];then if [ "$?" = "0" ];then
zenity $W --warning --text \ export BORG_PASSPHRASE=""
"Le fichier-clé du dépôt sera stocké dans le dossier <tt>$HOME/.config/borg/keys/</tt>.\n\n\ borg init --encryption=keyfile "$borg_repo" | ZenityPulsate
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épôt chiffré a été généré dans <tt>$borg_repo</tt>" zenity $W --info --text "Un nouveau dépôt chiffré a été généré dans <tt>$borg_repo</tt>"
repo_status="chiffré"
elif [ "$?" = "1" ];then elif [ "$?" = "1" ];then
zenity $W --warning --text \ borg init --encryption=none "$borg_repo" | ZenityPulsate
"Je comprends qu'en ne sécurisant pas mon dépôt 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épôt en clair a été généré dans <tt>$borg_repo</tt>" zenity $W --info --text "Un nouveau dépôt en clair a été généré dans <tt>$borg_repo</tt>"
repo_status="non chiffré"
fi fi
zenity $W --info --text="Séléctionnez maintenant le dossier à sauvegarder dans Borg-Zenity."
borg_dir=$(zenity --title "Dossier à sauvegarder" --file-selection --directory) borg_dir=$(zenity --title "Dossier à sauvegarder" --file-selection --directory)
profilename=$(zenity --entry --title "Nom de profil" --text "Nom de profil (pas d'espace ni caractères spéciaux)")
nomsauvegarde=$(echo "$profilename")
vars=$(zenity --forms \ if [ "$profilename" = "" ];then zenity $W --error --text "Pas de nom de profil";exit;fi
--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)
if [ "$nomsauvegarde" = "" ];then zenity $W --error --text "Pas de nom de sauvegarde";exit;fi if [ "$nomsauvegarde" = "" ];then zenity $W --error --text "Pas de nom de sauvegarde";exit;fi
if [ "$profilename" = "" ];then zenity $W --error --text "Pas de nom de sauvegarde";exit;fi
cat << EOF >> "$dossierprofil""$profilename".conf cat << EOF >> "$dossierprofil""$profilename".conf
nomsauvegarde="$nomsauvegarde" nomsauvegarde="$nomsauvegarde"
borg_repo="$borg_repo" borg_repo="$borg_repo"
@ -97,21 +88,29 @@ borg_compress=""
dryrun="" dryrun=""
EOF EOF
zenity $W --info --text "Le profil $profilename a été créé." zenity $W --info --text "\
Le profil «$profilename» a été créé avec ces paramètres\n\n\
Nom de profil : $profilename\n\
Chemin à sauvegarder : $borg_dir\n\
Chemin du dépôt : $borg_repo\n\
Statut du dépôt : $repo_status"
### Ajouter un dépôt existant ### ### Ajouter un dépôt existant ###
elif [ "$choixmenu" = "ajd" ];then elif [ "$choixmenu" = "ajd" ];then
borg_repo=$(zenity --title "Dossier du dépôt" --file-selection --directory) zenity $W --info --text="Séléctionnez maintenant le dossier qui contient votre dépôt. Il est généralement localisé sur un disque dur externe."
borg_dir=$(zenity --title "Dossier à sauvegarder" --file-selection --directory) TestBorgErr="true"
while [ "$TestBorgErr" = "true" ];do
borg_repo_test=$(zenity --title "Dossier du dépôt" --file-selection --directory)
if [ $? = "1" ];then exit;fi
cd "$borg_repo_test" && TestBorgRepo
if [ "$TestBorgErr" = "false" ];then borg_repo=$borg_repo_test;fi
done
vars=$(zenity --forms \ borg_dir=$(zenity --title "Dossier à sauvegarder" --file-selection --directory)
--text "Laisser les champs vides pour les options par défaut" \ profilename=$(zenity --entry --title "Nom de profil" --text "Nom de profil (pas d'espace ni caractères spéciaux)")
--add-entry "Nom de sauvegarde" \ nomsauvegarde=$(echo "$profilename")
--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 >> "$dossierprofil""$profilename".conf cat << EOF >> "$dossierprofil""$profilename".conf
nomsauvegarde="$nomsauvegarde" nomsauvegarde="$nomsauvegarde"
@ -128,8 +127,23 @@ zenity $W --info --text "Le dépôt à bien été ajouté.\nLancez «Borg Zenity
### Afficher les profils ### ### Afficher les profils ###
elif [ "$choixmenu" = "ap" ];then elif [ "$choixmenu" = "ap" ];then
fichierprofil=$(ls -1 *.conf | 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") fichierprofil=$(ls -1 *.conf | zenity $H $W --window-icon=borg --list --title "Liste des profils" --text "Choisir un profil dans la liste" --hide-header --column "profil")
if [ "$fichierprofil" != "" ];then
zenity $W $H --info --text="<tt>$(cd "$dossierprofil" && cat "$fichierprofil")</tt>" zenity $W $H --info --text="<tt>$(cd "$dossierprofil" && cat "$fichierprofil")</tt>"
fi
### Modifier un profil ###
elif [ "$choixmenu" = "mp" ];then
fichierprofil=$(ls -1 *.conf | zenity $H $W --window-icon=borg --list --title "Liste des profils" --text "Choisir un profil dans la liste" --hide-header --column "profil")
cp "$fichierprofil" "$fichierprofil.tmp"
return=$(zenity $W $H --text-info --editable --title="profil $fichierprofil" --filename "$fichierprofil.tmp")
if [ "$return" = "" ];then
rm "$fichierprofil.tmp"
exit
else
echo "$return" > "$fichierprofil.tmp"
mv "$fichierprofil.tmp" "$fichierprofil"
fi
elif [ "$choixmenu" = "" ];then elif [ "$choixmenu" = "" ];then
exit exit

View File

@ -6,44 +6,17 @@ Pre-requis : Borg-zeniy utilise `borgbackup` et `zenity` pour fonctionner.
Le script devrait les installer automatiquement en détectant votre distribution. Le script devrait les installer automatiquement en détectant votre distribution.
S'il n'y parvient pas vous devrez les installer manuellement. S'il n'y parvient pas vous devrez les installer manuellement.
## Installation (version stable) ## Installation et mise à jour (version stable)
L'installation devrait pouvoir se faire en ligne de commande. Copiez ceci dans votre terminal. L'installation devrait pouvoir se faire en ligne de commande. Copiez ceci dans votre terminal.
``` ```
wget -O borg-zenity.zip https://git.djan-gicquel.fr/djan/borg-zenity/archive/stable.zip && unzip borg-zenity.zip && cd borg-zenity && bash install.sh wget -O borg-zenity.zip https://git.djan-gicquel.fr/djan/borg-zenity/archive/stable.zip && unzip -d ./ borg-zenity.zip && cd borg-zenity && bash install.sh
``` ```
Cette commande va télécharger les fichiers d'installation et exécuter le script d'installation. Cette commande va télécharger les fichiers d'installation et exécuter le script d'installation.
Vous devrez entrer votre mot de passe utilisateur et cet utilisateur devra avoir les droits root. Vous devrez entrer votre mot de passe utilisateur et cet utilisateur devra avoir les droits d'administration.
## Gestionnaire de profils ## Désinstallation
![icône gestionnaire de profils](captures/icone_profils.png) Copier cette ligne dans le terminal.
```
Si vous n'utilisez pas encore `borgbackup` (ce qui normalement est le cas), il faudra tout d'abord créer un profil de sauvegarde. sudo bash /opt/borg-zenity/uninstall.sh
Pour cela utiliser licône "Borg Zenity Profils" dans votre menu principal et sélectionnez «Créer un nouveau profil/dépôt». ```
Sélectionnez le dossier dans lequel sera créé le dépôt. C'est l'emplacement de votre sauvegarde, en général on utilise un disque dur externe.
Puis répondez à la question concernant le chiffrement du dépôt. Les fichiers du dépôt sont initialisés.
Sélectionnez ensuite un dossier à sauvegarder puis choisissez un nom de profil. Celui-ci sera stocké comme fichier donc évitez les espaces et les caractères spéciaux.
## Interface principale
Pour lancer l'interface principale cliquez sur l'icône «Borg Zenity Sauvegarde» dans le menu et sélectionnez le profil voulu.
![icône interface principale](captures/icone_sauvegarde.png)
Le selecteur de profils se lancera. Si vous n'avez qu'un seul profil, il n'y aura qu'une entrée dans cette liste.
![selecteur de profils](captures/selecteurdeprofils.png)
Voici l'interface principale.
![interface_principale](captures/interfaceprincipale.png)
En vocabulaire borg, une archive est une sauvegarde.
Pour créer une sauvegarde cliquez sur «Créer une archive». La première sauvegarde prendra du temps, les suivantes seront plus rapide.
Pour voir le contenu d'une archive déjà sauvegardée cliquez sur «Monter une archive». Un nouveau dossier sera créé en lecture seule dans votre dossier maison. Il contiendra les fichiers de l'archive. Pensez à démonter l'archive dans le menu correspondant avant de quitter Borg Zenity.
Pour quitter Borg Zenity sélectionnez «QUITTER» puis validez ceci afin pouvoir faire quelques tests avant de quitter le logiciel.

View File

@ -24,41 +24,10 @@ elif [ -f /etc/SuSe-release ]; then
elif [ -f /etc/redhat-release ]; then elif [ -f /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc. # Older Red Hat, CentOS, etc.
OS=Redhat OS=Redhat
else
echo "La distribution n'a pas été détecté."
echo "Installez les paquets \"borgbackup\" et \"zenity\" manuellement."
exit
fi fi
echo "OS = $OS" if [ "$OS" = "" ];then
echo "La distribution n'a pas été détecté."
if [[ "$OS" =~ "Fedora" ]];then echo "Installez les paquets \"borgbackup\" et \"zenity\" manuellement."
echo "Fedora detecté" exit
sudo dnf install borgbackup zenity fi
elif [[ "$OS" =~ Mageia ]];then
# non fonctionnel sur Mageia 8, le paquet borgbackup n'existe pas encore
echo "Mageia detecté"
su -c "dnf install borgbackup zenity"
elif [[ "$OS" =~ Debian ]];then
echo "Debian detecté"
su -c apt install -y borgbackup zenity
elif [[ "$OS" =~ Ubuntu ]];then
echo "Ubuntu detecté"
sudo apt install -y borgbackup zenity
elif [[ "$OS" =~ "Linux Mint" ]];then
echo "Linux Mint detecté"
sudo apt install -y borgbackup zenity
elif [[ "$OS" =~ Manjaro ]];then
echo "Manjaro detecté"
sudo pacman -Sy borgbackup zenity
else
echo "La distribution n'a pas été détecté."
echo "Installez les paquets \"borgbackup\" et \"zenity\" manuellement."
exit
fi

View File

@ -6,9 +6,8 @@ sudo rm -vf /usr/share/icons/borgzenity-profils.svg
sudo rm -vf /usr/share/icons/borgzenity-sauvegarde.svg sudo rm -vf /usr/share/icons/borgzenity-sauvegarde.svg
sudo rm -vf /usr/share/applications/borg-zenity-sauvegarde.desktop sudo rm -vf /usr/share/applications/borg-zenity-sauvegarde.desktop
sudo rm -vf /usr/share/applications/borg-zenity-gestprofils.desktop sudo rm -vf /usr/share/applications/borg-zenity-gestprofils.desktop
sudo rm -vf /opt/borg-zenity/borg-gui.sh sudo rm -vrf /opt/borg-zenity/
sudo rm -vf /opt/borg-zenity/profile-manager.sh
echo "--------------------" echo "--------------------"
echo "Désinstallation terminée." echo "Désinstallation terminée."
echo "Vous pouvez supprimmer la configuration manuellement dans ~/.config/borg/" echo "Vous pouvez supprimer la configuration manuellement dans ~/.config/borg/"